-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(gateway): merge selection sets of @requires
fields
#4064
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
fix(gateway): merge selection sets of @requires
fields
#4064
Conversation
…vscode debugger config."" This reverts commit a65536d.
@jakeblaxon: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
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.
Thanks so much for taking the time to work on this @jakeblaxon! I've spoken with the author of the PR you linked, I'd like to go forward with your implementation if you're comfortable with the changes I'm suggesting.
If you're busy or unable to carry this forward for any reason please let me know and I'd be more than happy to wrap this up. Thanks again! 🎉
packages/apollo-gateway/src/__tests__/integration/requires.test.ts
Outdated
Show resolved
Hide resolved
packages/apollo-gateway/src/__tests__/integration/requires.test.ts
Outdated
Show resolved
Hide resolved
Also, please add a changelog entry to the gateway changelog. Note: there's a separate changelog for gateway from the rest of the server monorepo. |
Thanks, @trevor-scheer! I can get these changes in soon. One concern I want to bring up though is that this only combines selection sets for field nodes. If we were to get a fragment node that itself had nested subfields, that fragment node's selection set would still potentially override the corresponding field node's. It currently appears that we expand any fragments into fields before calling I noticed that in the #4017 implementation, since we pass Curious to hear your thoughts. Thanks! |
@jakeblaxon the insight is very much appreciated. Let's go forward with this implementation. If we ever do go down that path, we can revisit Lenny's solution or adapt things as needed. Let me know if you need anything from me! |
… into improve-federation-requires-directive
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.
Two minor changes within this review and this looks good to go! Thanks for the timely turnaround on these updates.
When I land this PR, do you mind if I attribute co-authorship to Lenny as well? I appreciate the effort that went into this from both of you!
FWIW, this is what that would look like in the final commit:
https://help.github.com/en/github/committing-changes-to-your-project/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-github
Co-authored-by: Trevor Scheer <[email protected]>
@trevor-scheer Of course! Please add @lennyburdette as a co-author. Thank you! |
@requires
fields
Thank you both for your time and efforts here, I'll have this released as a patch fix early next week! |
Published in |
…ql/apollo-server#4064) Previously, it was possible for the gateway to build and issue queries for resolving fields that resembled the following: ```graphql { product { id } product { price } } ``` In the above example, the second selection set will take precedence and the first ignored, meaning the query _ought_ to be: ```graphql { product { id price } } ``` This is accomplished in this PR by merging the selection sets recursively. fixes apollographql/apollo-server#3848 Co-authored-by: Lenny Burdette <[email protected]> Apollo-Orig-Commit-AS: apollographql/apollo-server@3cdcd06
This fixes a bug in the Apollo Gateway, where @requires fields are not provided to resolvers for fields nested more than one level deep.
What this is trying to fix
This aims to fix issue #3848: [Federation Gateway] @requires directive sometimes does not provide all required fields
Scenario
When requiring fields nested more than one level deep, they are not getting merged together into one selection set in the query plan. Instead, the query plan will contain duplicate sets like the following:
The required value would be fetched but overwritten by the second selection set in the javascript object. This PR solves this issue by merging the selection sets together, to arbitrary depth, like the following:
Fixes #3848
Closes #4017