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

feat(gateway): New federation composition format #4405

Merged
merged 12 commits into from
Jul 28, 2020

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Jul 21, 2020

Design / ref: apollographql/federation#61

Note: this PR is intended to be reviewed by commit. The steps taken to first update the
existing fork and then continue with the new implementation should be fairly clear.

The format of composition as it stands is not a portable one. In its current form,
the result of composition is an executable GraphQLSchema object whose types and fields
are annotated via the extensions field.

This is problematic for the future of composition at Apollo - as we move query planning to
Rust, moving away from this JS native object and towards a portable format (SDL) is ideal,
and also allows us to:

  • parse and consume this format more easily with tooling
  • create / consume this format in any language which can already parse valid GraphQL
  • standardize the format for other implementors

I imagine there's some overlap in my bullets but the points still hold for us.

All of that being said, this PR creates an additional output to composition - the printed
SDL of the new composition format. We're calling this CSDL C(omposed)SDL to distinguish
that this SDL ought to include all of the annotations / metadata necessary about the
composed graph in order to perform query planning and execution.

I included updating our existing fork of graphql-js printSchema as part of the work
since it fit nicely into my iterative transition while building the new printer. As a
side effect, this PR also resolves an outstanding issue related to printing block descriptions
which include double quote characters. This issue made such a schema unparseable. cc @watson
Fixes #4400
Fixes #4339
Fixes #3864

@trevor-scheer trevor-scheer force-pushed the trevor/print-federated-schema branch from fa4f22f to 3ac7406 Compare July 21, 2020 21:48
trevor-scheer added a commit that referenced this pull request Jul 22, 2020
This work is separated out from #4405, and is important to
unblock progress on the new composition format.

This upgrade could've happened at any time. Now that composition
is being updated to a fork of the latest graphql schema printer,
v15 is now a requirement.

This comes with a few test updates, mostly around the sorting
of AST nodes (i.e. in the query plan).
trevor-scheer added a commit that referenced this pull request Jul 22, 2020
This work is separated out from #4405, and is important to
unblock progress on the new composition format.

This upgrade could've happened at any time. Now that composition
is being updated to a fork of the latest graphql schema printer,
v15 is now a requirement.

This comes with a few test updates, mostly around the sorting
of AST nodes (i.e. in the query plan).
@trevor-scheer trevor-scheer force-pushed the trevor/print-federated-schema branch from 2be570a to 37aca46 Compare July 22, 2020 15:53
@trevor-scheer trevor-scheer force-pushed the trevor/print-federated-schema branch 6 times, most recently from 0e1c6d1 to c085470 Compare July 24, 2020 03:50
This commit introduces a fresh copy of graphql-js schema printer.
Copying it here as the first commit gives us a good diffing point
for review.
@trevor-scheer trevor-scheer force-pushed the trevor/print-federated-schema branch from c085470 to d998e06 Compare July 24, 2020 03:53
@@ -1,87 +1,119 @@
/*
Copy link
Member Author

@trevor-scheer trevor-scheer Jul 24, 2020

Choose a reason for hiding this comment

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

Reviewer: this entire file change is a copy/paste of newPrintFederatedSchema.ts from previous commits. Nothing from this file change is new code - this is the drop-in update for the schema printer.

@trevor-scheer trevor-scheer force-pushed the trevor/print-federated-schema branch 3 times, most recently from 61a2c39 to 71f5b58 Compare July 24, 2020 05:06
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

😍 Wow, what an incredible PR! This is super exciting, and very well organized / easy to review. The annotations explaining the federated adjustments are super useful for posterity, too.

(Glad we've brought in updated, upstream printer bits too!)

Two bits:

  • I believe that newPrintFederatedSchema.ts is equal to printComposedSdl.ts by the end of this. I don't see newPrintFederatedSchema.ts being require'd / import'd anywhere; is there meant to be one final commit that removes newPrintFederatedSchema.ts?
  • I had one naming thought I mentioned in Directives for SDL representation of composed schema federation#61 (comment) that might be worth tweaking (easy, rename) that I'd be curious in getting your thoughts on.

Copy over the now validated `newPrintFederatedSchema.ts` contents
into the former `printFederatedSchema.ts` as an "under-the-hood"
swap.
This forks from the newly updated schema printer. However, the goal
of this printer is to print the FINAL composition, rather than the
schema for a single federated service.

By peeking at the existing annotations in the `extensions` on the
composed `GraphQLSchema`, the composition printer can gather
important metadata like type and field ownership which is then
annotated in the final SDL.
@trevor-scheer trevor-scheer force-pushed the trevor/print-federated-schema branch from 71f5b58 to 0784ff7 Compare July 24, 2020 17:30
@trevor-scheer
Copy link
Member Author

@abernix good catch! That file is now removed in bd69058

@trevor-scheer trevor-scheer added ⛲️ feature New addition or enhancement to existing solutions 👩‍🚀 federation labels Jul 27, 2020
@trevor-scheer trevor-scheer self-assigned this Jul 27, 2020
@trevor-scheer trevor-scheer merged commit 1c58ea3 into main Jul 28, 2020
@trevor-scheer trevor-scheer deleted the trevor/print-federated-schema branch July 28, 2020 18:35
abernix pushed a commit to apollographql/federation that referenced this pull request Sep 4, 2020
…o-server#4405)

The output of composition as it stands is not a portable one. In its current
form, the output of composition is an executable GraphQLSchema object whose
types and fields are annotated via the extensions field.

This is problematic for the future of composition at Apollo - as we move query
planning to Rust, moving away from this JS native object and towards a portable
format (SDL) is ideal, and also allows us to:

* parse and consume this format more easily with tooling
* create / consume this format in any language which can parse valid GraphQL
* standardize the format for other implementors

All of that being said, this commit creates an additional output to
composition - the printed SDL of the new composition format. We're calling this
CSDL C(omposed)SDL to distinguish that this SDL ought to include all of the
annotations / metadata necessary about the composed graph in order to perform
query planning and execution.
Apollo-Orig-Commit-AS: apollographql/apollo-server@1c58ea3
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⛲️ feature New addition or enhancement to existing solutions
Projects
None yet
2 participants