-
Notifications
You must be signed in to change notification settings - Fork 254
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
Additional SourceSpecDefinition
validations
#2914
Additional SourceSpecDefinition
validations
#2914
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
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. |
if (result.sourceAPI || result.sourceType || result.sourceField) { | ||
// Since this subgraph uses at least one of the @source{API,Type,Field} | ||
// directives, it must also use v2.7 or later of federation. | ||
if (!federationVersion || federationVersion.lt(this.minimumFederationVersion)) { |
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.
I don't think this error is necessary. I think it's fine to just not validate rather than throw an error. Not sure that this could ever happen.
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.
Without this enforcement, there's a cryptic error later on because @join__directive
isn't added to the supergraph schema unless federation v2.7+ is in use.
Specifically, joinDirective
ends up undefined here:
federation/composition-js/src/merging/merge.ts
Lines 2747 to 2750 in 6ae4294
const joinDirective = this.joinSpec.directiveDirective(this.merged); | |
Object.keys(joinsByDirectiveName).forEach(directiveName => { | |
joinsByDirectiveName[directiveName].forEach(join => { | |
dest.applyDirective(joinDirective, { |
when it wasn't added to the schema here:
federation/internals-js/src/specs/joinSpec.ts
Lines 137 to 143 in 6ae4294
if (this.version.gte(new FeatureVersion(0, 4))) { | |
const joinDirective = this.addDirective(schema, 'directive').addLocations( | |
DirectiveLocation.SCHEMA, | |
DirectiveLocation.OBJECT, | |
DirectiveLocation.INTERFACE, | |
DirectiveLocation.FIELD_DEFINITION, | |
); |
I agree with @lennyburdette that not using federation v2.7 is an easy mistake to make, and this error should make the problem easier to diagnose.
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.
All directives have an issue where if you don't specify the right version composition will say that it doesn't understand the directive. Not sure why this is a special case.
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.
because the source directives are imported from their own link instead of from the federation link. it's a little weird, but i'm ok with leaning into it because enforcing a minimum version of 2.7 should minimize the number of unhappy paths:
@link federation < 2.7 |
@link federation >= 2.7 |
|
---|---|---|
composition < 2.7 | using source is silently ignored (🦶🏻 🔫 , but can't fix) | composition fails due to link being ahead of composition |
composition >= 2.7 | this scenario which we're disallowing | happy path |
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.
Ok, I got it. Can you make an issue to solve this for the general case? Might be a good starter project for our new hire.
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.
main
has been updated, so you want to merge there rather than next
(which is in theory 2.8 now).
✅ Deploy Preview for apollo-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`493f5acd16ad92adf99c963659cd40dc5eac1219`](493f5ac)]: - @apollo/[email protected] - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`493f5acd16ad92adf99c963659cd40dc5eac1219`](493f5ac)]: - @apollo/[email protected] - @apollo/[email protected] - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Additional `SourceSpecDefinition` validations and bug fixes ([#2914](#2914)) ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`493f5acd16ad92adf99c963659cd40dc5eac1219`](493f5ac)]: - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`493f5acd16ad92adf99c963659cd40dc5eac1219`](493f5ac)]: - @apollo/[email protected] - @apollo/[email protected] ## @apollo/[email protected] ### Patch Changes - Updated dependencies \[[`493f5acd16ad92adf99c963659cd40dc5eac1219`](493f5ac)]: - @apollo/[email protected] ## [email protected] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
… directive (#2929) # Overview The recent addition of `SourceSpecDefinition` surfaced a case where a subgraph with a `@link` to federation < 2.7 and a `@link` to the source spec (which requires federation >= 2.7) results in an unexpected error during composition. Validation for this case was introduced in #2914, raising a composition error when the versions are mismatched. Since the existing behavior will implicitly upgrade to a later minor version of federation when two subgraphs are mismatched, it makes sense to do the same with feature requirements. # Example Subgraph A has a `@link` to fed version 2.5 Subgraph B has a `@link` to fed version 2.7 Subgraph C has a `@link` to fed version 2.5 and a separate `@link` to the source spec Previous behavior: 1. Composing Subgraph A and Subgraph B silently upgrades to fed version 2.7 2. Composing Subgraph A and Subgraph C results in a composition error New behavior: 1. Composing Subgraph A and Subgraph B silently upgrades to fed version 2.7 2. Composing Subgraph A and Subgraph C upgrades to fed version 2.7 and raises a hint explaining why --------- Co-authored-by: Chris Lenfest <[email protected]>
Follow-up to PR #2910.