Repository navigation
fix(graphql): link the federation 2 spec in the auto schema file - #4189
Merged
Merged
Conversation
With `autoSchemaFile: { federation: 2 }`, the written SDL file kept the
federation directives but not the `extend schema @link(...)` that the
served subgraph schema gets, so tools such as `rover` read it as a
federation 1 subgraph and rejected federation 2 directives.
Decorate the printed file with the same federation 2 `@link` as the
served type definitions. Federation 1 and non-federated schemas are
unchanged.
Closes #2765
This file contains hidden or 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
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.
PR Checklist
PR Type
What is the current behavior?
With a code-first federation subgraph and
autoSchemaFile: { path, federation: 2 }, the generated file contains the federation directive usages (@key,@shareable,@external, ...) but noextend schema @link(url: "https://specs.apollo.dev/federation/v2.x", import: [...]). The schema actually served (_service { sdl }) does have the@link: it is added to the in-memory type definitions after the file has been written. As a result,rover subgraph check/rover supergraph composetreat the file as a federation 1 subgraph and fail on federation 2 directives, e.g.Unknown directive "@shareable". ... note that this schema is a federation 1 schema. To be a federation 2 schema, it needs to @link to the federation specification v2.Issue Number: #2765
What is the new behavior?
GraphQLFederationFactorydecorates the file printer with the sameTypeDefsFederation2Decorator(and the sameautoSchemaFile.federationconfig:importUrl,directives) that is applied to the served type definitions, so the written file links the federation 2 spec and can be composed as-is. Federation 1 and non-federated schemas are untouched.A new e2e spec (
federation2-auto-schema-file.spec.ts) asserts that the written file parses, links the federation 2 spec, imports every federation directive it uses, and composes with another federation 2 subgraph viaLocalComposefrom@apollo/gateway. The@linkassertion fails on master.The original error in #2765 ("Type User must define one or more fields") no longer reproduces with current
@apollo/subgraph; the remaining gap was the missing@link. Generating a subgraph's SDL without bootstrapping the app (GraphQLSchemaFactory+printSubgraphSchema) is covered by a docs PR.Closes #2765
Does this PR introduce a breaking change?
The file emitted for
federation: 2now starts withextend schema @link(...). It already carried federation directive usages without their definitions, so it now matches the SDL the subgraph serves.