Repository navigation
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
8c40697 to
21a2a8c
Compare
8c13477 to
220e8d4
Compare
Notes from meeting:We should support syntax grammar for key motivation is that "a schema minus all deprecated elements is always valid" which today could be not true! For a bunch of reasons but in this case: this cannot create a valid non-deprecated schema! that's our aim. Another example: a mutation payload (relay style) that wants to be defined up front as Specifically important because the LLM-focused subschema generation still has some issues we're working out, and it's unclear that providing |
|
Looks like we'll need the same for input objects? |
|
I am not sure this is the right place to comment, but together with the issue about interfaces without fields and interfaces without objects implementing them I am wondering if we should distinguish between valid schemas vs valid and executable schemas. For example an interface without an implementation is not something I find sensible for a real schema that should be executed but for schema during design it is ok. |
@andimarek My preference here would be a lint warning. The spec is already a bit vague on SDL validation (see #1233 (comment)) so we're not really equipped to have executable vs non-executable validation yet. |
|
A data point from the AI WG. I’m writing the Schema Search RFC (graphql/ai-wg#187). It describes a service returning a valid subset of its schema as SDL in response to a natural language query. That subset is exactly the kind of partial schema this PR covers, so I wanted to share how the current rule affects it. Since object types need at least one field today, our slicer has to drop any type that has no matching fields. That also removes every field that returns that type, so the model never learns that
We also hit this case when searches match only mutations, like "create an issue." The slice needs |
+1 from the schema-search side, with one caveat that I think is worth stating, because input objects behave differently from output types here. A slice guarantees that any operation that validates against the slice will also validate against the full schema. An empty |
|
Ahead of today's WG, here is a short summary of the open syntax question, so we can settle it in the meeting. Question: how do we write an object type, interface, or input object with no fields?
Suggestion: C. It needs no grammar change, and we can still add Asks for today:
GraphQL.js: graphql/graphql-js#4934 implements all three behind |
|
We agreed on option A, so I've merged the unions and interfaces into this PR and expanded our "odd duck" of unions to use the least-bad alternative syntax: |
* Interfaces with no fields * Allow a union to be empty
354b794 to
68e2b00
Compare
|
I've also added the requirement that Mutation must have at least one field (like Subscription). Query is allowed to be empty because a) Query is required, b) Query is how you do introspection, c) if you want a "mutation only" schema then you don't want to add any Query fields. This addresses |
| A union type may also be defined for an empty set of member types: | ||
|
|
||
| ```graphql example | ||
| union EmptyUnion = {} |
There was a problem hiding this comment.
@benjie Did we settle on this syntax? I remember a few other options were discussed yesterday, like using a keyword.
There was a problem hiding this comment.
Not officially, no, that would need WG consensus. If there are others you'd like us to consider, do propose them!
I think {} is a solid option though. {} is already used as an ASCII-only way of representing the empty set (rather than non-ASCII options like ∅) which is what we're representing here. We're also kind of representing an object with no properties, so it kind of makes sense there too. I think it's fairly straightforward, obvious, and we're making breaking changes to the SDL anyway so seems as good a time as any to introduce it.
One option is to just use union EmptyUnion to represent empty unions and allow it to be the "odd duck". But I think this is a cheap solution that enables some level of consistency.
Related:
Since 2015 we've always required an object type to define at least 1 field. As we continue to explore GraphQL's position in the new AI-world, we realise that we need schema subsets that represents part of a larger interface, in these cases it's sometimes useful to leave in type references without including full definitions of those types:
Here the AI can see a basic schema it can write queries against, but it can also ask to expand the parts of the schema that are relevant to its interests - e.g. books or articles or publishers - without wasting context on things it doesn't care about.
We can make a schema like this valid by including at least one field on each of these types, but it's hard for a tool to know which field(s) to include, and not including fields makes it much more obvious to the LLM that the schema is partial. Making this partial schema itself valid would be helpful for tooling.
This need can also be expanded to interfaces and unions:
AI aside:
type MyMutationPayload { success: Boolean! }is used as a workaround, but it's messy.Related: