Skip to content
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 3 commits into from
May 9, 2022

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented May 5, 2022

This PR has 2 main fixes:

  1. buildSubgraphSchema was failing if a subgraph was defining the link__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.
  2. the output of 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 makes buildSubgraphSchema fail on the output of that method. The patch tries to fix printSubgraphSchema 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).

@netlify
Copy link

netlify bot commented May 5, 2022

👷 Deploy request for apollo-federation-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 96cbf21

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 5, 2022

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.

Copy link
Contributor

@benweatherman benweatherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐐

Sylvain Lebresne added 3 commits May 9, 2022 11:44
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
@pcmanus pcmanus force-pushed the 1824-print-schema-fixes branch from 235b78f to 96cbf21 Compare May 9, 2022 09:47
@pcmanus pcmanus merged commit 6480e5c into apollographql:main May 9, 2022
@benweatherman benweatherman mentioned this pull request May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants