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

chore(federation): Update schema printers #996

Merged
merged 4 commits into from Sep 3, 2021

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Sep 1, 2021

Update our subgraph and supergraph schema printers to match the printSchema function from graphql-js as closely as possible. This introduces printing capabilities for the @specifiedBy directive as well as @deprecated on input values.

This PR depends on #1000 which resolves a few problems I turned up after addressing @martijnwalraven's sorting concern.

  • The supergraph printer was doing some composition-level operations on the schema (adding directives and types). I pushed this behavior more appropriately up to composition where it belongs.
  • This change resulted in supergraphs being sorted correctly (lexicographicSortSchema was being called, but the printer was modifying the schema after that sort).
  • This change was also reflected in the subgraph printer tests which was odd. I found that the printFederatedSchema test was testing printing a composed graph rather than a subgraph, so I fixed the test.
  • Alias and deprecate printFederatedSchema (which was exported as printSchema) to printSubgraphSchema to prevent naming confusion.

Fixes #994
Fixes #635

Post-merge edit: In addition, this PR now prints interfaces implementing interfaces (as a byproduct of updating our printer forks). Previously it used to ignore them.

@trevor-scheer
Copy link
Member Author

Needs changelog entry

Copy link
Contributor

@martijnwalraven martijnwalraven left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this! I don't have any real feedback on these changes in particular. Some changes seem unrelated to the @specifiedBy/@deprecated additions, but I'm assuming that's because you're brought the code up to date with graphql-js v16.

We've talked about this before, but it's a shame we have to fork printSchema (and do it twice!). This is probably a good topic for discussion with @IvanGoncharov, but it would be great to investigate additions to graphql-js that could avoid the need for forking altogether.

federation-js/src/service/printFederatedSchema.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@martijnwalraven martijnwalraven left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Comment on lines +521 to +522
// Apollo addition: support both specifiedByUrl and specifiedByURL - these
// happen across v15 and v16.
Copy link
Member Author

Choose a reason for hiding this comment

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

@IvanGoncharov do you intend to preserve this breaking change in v16?
graphql/graphql-js#3156

Base automatically changed from trevor/fix-printer-responsibilities to main September 3, 2021 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants