-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adhere to specification for schema extension #2433
base: series/2.x
Are you sure you want to change the base?
Adhere to specification for schema extension #2433
Conversation
@ghostdogpr hoping for some feedback here. Somebody more knowledgeable about the GQL specification noted that there are actually 2 conditions that we should check before considering the schema an extended schema:
We can implement those rules, but developers may rely on the fact that caliban produces a non-extended schema for case (2) above. In either case, this change may be breaking. I'm going to update the logic here to reflect the above checks, you can see my first attempt by looking at the commit history if you'd like |
Pinging our expert in subgraphs @paulpdaniels to confirm |
@@ -327,7 +327,8 @@ object DocumentRenderer extends Renderer[Document] { | |||
definition match { | |||
case SchemaDefinition(directives, query, mutation, subscription, description) => | |||
val hasTypes = query.nonEmpty || mutation.nonEmpty || subscription.nonEmpty | |||
val isExtension = directives.nonEmpty && !hasTypes | |||
val isExtension = | |||
(!hasTypes && directives.nonEmpty) || query.isEmpty && (mutation.nonEmpty || subscription.nonEmpty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your comment, shouldn't this be:
(!hasTypes && directives.nonEmpty) || query.isEmpty && (mutation.nonEmpty || subscription.nonEmpty) | |
(!hasTypes && directives.nonEmpty) || (query.isEmpty && (mutation.nonEmpty || subscription.nonEmpty)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops, I thought I had done it and the formatter stripped it, but I must have made a mistake. Fixed
I'm not sure I fully understand the reasoning behind (2) 🤔. Can you provide an example of a valid schema extension (in |
Is checking for a present |
yes - this would be essentially any subgraph that has (1) only a mutation, (2) only a subscription, or (3) a mutation + subscription but no query. E.g: "Directive which holds a freeform tag applied to an element."
directive @tag("The name of the tag to apply."
name: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
extend schema @link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key", "@requires", "@provides", "@external", "@shareable", "@tag", "@inaccessible", "@override", "@extends", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresScopes", "@policy"]) {
mutation: Mutations
}
type Mutations {
mutateFoo(fooId: String!): String @tag(name: "fooTag")
}
|
Wanted to circle back here to see if anyone can take a look at this change? |
@kyri-petrou @paulpdaniels you guys can take another look? |
Technically speaking I don't have any issues with this. My question above is, are we treating rendered vs interpreted schemas different? and are we ok with that? For instance if we called |
We have a validation rule |
I guess I'm OK with this change. I would have preferred if we were able to determine whether this is a schema extension a bit more explicitly (rather than basing it on the absence of the query field in the schema), but if this is the best that we can do then that's fine with me. |
Looking into the GraphQL specification, I believe that schemas for federated graphs are being rendered in a slightly incorrect way. The specification states
What is important is that the final federated GraphQL schema obeys ☝️. However, subgraphs need not implement the full schema specification. Subgraphs which do not meet this criteria should use the
extend
keywordI believe that this change more closely adheres to the correct specification.