sqrl icon indicating copy to clipboard operation
sqrl copied to clipboard

Inherited table functions not exposed in GraphQL schema

Open velo opened this issue 5 months ago • 0 comments

When a derived table (e.g., TopicPackages) selects all (SELECT *) from a base table (e.g., TopicPackagesA) that defines additional functions (e.g., .latest), the GraphQL schema validator does not expose those functions—unless the GraphQL return type is explicitly renamed to match the base table (TopicPackagesA).

Example here: https://github.com/DataSQRL/sqrl/pull/1422/files

This leads to validation errors like:

[FATAL] Unknown field at location latest. Possible scalars are [...]

Even though the SQL logic works and compiles fine without a GraphQL schema, the functions are silently missing from the schema output.

Reproduction Steps:

This SQL compiles but fails GraphQL validation:

TopicPackagesA := SELECT pkgName, topicName FROM SubmissionTopics;

TopicPackagesA.latest := SELECT * FROM Submission s WHERE this.pkgName = s.name LIMIT 1;

TopicPackages(topicName STRING NOT NULL) :=
  SELECT * FROM TopicPackagesA WHERE topicName = :topicName;

GraphQL schema:

type Query {
  TopicPackages(topicName: String!): [TopicPackages!]
}

type TopicPackages {
  pkgName: String!
  topicName: String!
  latest: Submission
}

Workaround:

Changing the return type of the query to match the table name (TopicPackagesA) causes it to work as expected:

type Query {
  TopicPackages(topicName: String!): [TopicPackagesA!]
}

Expected Behavior:

Even when the return type is named differently (e.g., TopicPackages), the schema should still expose inherited functions (e.g., .latest) from the base table.

Possible Root Cause:

The DAG planner may not propagate base table functions correctly unless the table name and GraphQL type name align. Either the base table inference is broken, or GraphQL schema generation does not traverse the base table chain to include inherited functions.

Related Debugging Work:

  • Confirmed ServerPhysicalPlan.functions does not include base table functions
  • Base table is correctly inferred in DAG
  • PR with reproduction: https://github.com/DataSQRL/sqrl/pull/1422

Environment:

  • DataSQRL: main branch
  • CLI compiles successfully without graphql
  • Breaks during GraphQL schema validation

velo avatar Jul 25 '25 17:07 velo