-
Notifications
You must be signed in to change notification settings - Fork 2k
Correctly expand possible types for interfaces #3529
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
Conversation
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.
This looks great! 👍🏽
For future work, it strikes me that the solution to this general problem—given a point in a query, what fields / fragments are valid?—might well be useful in other contexts (like a language server, for example), so it might be worth pulling out at some point. Either way, this is great for the gateway, so LGTM.
@@ -93,69 +93,69 @@ describe('buildQueryPlan', () => { | |||
const queryPlan = buildQueryPlan(buildOperationContext(schema, query)); | |||
|
|||
expect(queryPlan).toMatchInlineSnapshot(` | |||
QueryPlan { |
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.
aw man this indentation change is a bummer.
(tests are not a bummer, tests are great, i'm just sad abt that jest bug)
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.
Good news is the bug is behind us and our poorly indented tests will resolve themselves over time 😄
@@ -422,14 +426,14 @@ function splitFields( | |||
GraphQLObjectType | |||
>(); | |||
|
|||
for (const runtimeParentType of context.getPossibleTypes(parentType)) { | |||
for (const runtimeParentType of scope.possibleTypes) { |
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.
ahhh, so nice. ♨️😄
…server#3529) * Fix indentation of query plan snapshots in test * Add failing tests from apollographql/apollo-server#3257 * Introduce Scope to capture nested type conditions * Clarify that `completeField` is only called for object types * Adjust fields when expanding possible types Co-authored-by: Martijn Walraven <[email protected]> Co-authored-by: Vitramir <[email protected]> Apollo-Orig-Commit-AS: apollographql/apollo-server@43d3ac1
This PR is in response to the following contributions made by @vitramir, thank you for bringing this to our attention and proposing a solution 🎉
Closes #3253
Closes #3257
Thank you to everyone following along for your patience while we've discussed the problem and a solution we'd like to go forward with. @martijnwalraven has prepared this branch for us as a proposal, and it's one we'd like to go forward with.
This PR introduces the concept of a
Scope
. AScope
(which belongs to aField
) captures information about the parent's type and the possible types of theField
. This addition to the data model of aField
allows the query planner to make correct decisions about exploding interfaces into only possible types.