-
Notifications
You must be signed in to change notification settings - Fork 257
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 printSubgraphSchema
method.
#1831
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
👷 Deploy request for apollo-federation-docs pending review.Visit the deploys page to approve it
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
8fc747d
to
235b78f
Compare
This was referenced May 5, 2022
benweatherman
approved these changes
May 6, 2022
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.
🐐
If an input schema had a definition for type `link_Purpose` but not the definition for `@link` itself, then we were generating a confusing error while "importing" the `@link` definition. The situtation triggering this error is a bit unusual (why would you have `link_Purpose` but not the `@link` definition in the first place?), and we could just improve the error message, we're usually lenient about core feature being only halfway-defined in the schema and so it make sense to allow it in this case too if we can. And so this patch ensures that this case work and do not error out anymore.
In federation 1, `printSubgraphSchema` was printing a `GraphQLSchema` with applications for federation directives but without definition for those federation directive. Which meant that you more or less got back what you may have provided as input to `buildSubgraphSchema`. The change of federation 2 broke this somewhat, and `printSubgraphSchema` was outputing a relatively illegical output, where some federation directive definition were skipped, but not others, and where while the `@link` directive was skipped, the `link_Purpose` type that it uses was not skipped, etc... This patch updates the `printSubgraphSchema` to ensure a more logical and consistent output, and more precisely it outputs the schema more or less as inputed by a user (so with application directives, but none of the auto-imported directive definition, or some of the semi-private federation types/fields). This means that, potential formatting and special case aside, `printSubgraphSchema(buildSubgraphSchema(defs))` will give you back `defs`. As as result, this also make it so that the output of `printSubgraphSchema` can always be fed back to `buildSubgraphSchema`. Fixes apollographql#1824
235b78f
to
96cbf21
Compare
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR has 2 main fixes:
buildSubgraphSchema
was failing if a subgraph was defining thelink__Purpose
type but not including the@link
directive definition, and this with a confusing error message (one that didn't make sense for the user and didn't help you understand what to fix). While fixing the error was an option, we're generally lenient toward a user provided parts of the definitions of a core feature but not others, and so it makes sense to simply make it for for@link
itself as well.printSubgraphSchema
in fed2 is currently fairly unhelpful and illogical. It includes some federation directives but not others, skip some federation private parts but include others, etc. Some of it also makesbuildSubgraphSchema
fail on the output of that method. The patch tries to fixprintSubgraphSchema
so it outputs "the schema as the user would usually write it", that is it skip all auto-imported directive definition (and their dependencies) consistently, and additionally skip the auto-added federation semi-private type and fields (_service
and friends).