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

Additional SourceSpecDefinition validations #2914

Merged
merged 13 commits into from
Jan 24, 2024

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jan 23, 2024

Follow-up to PR #2910.

@benjamn benjamn self-assigned this Jan 23, 2024

This comment was marked as resolved.

Copy link

codesandbox-ci bot commented Jan 23, 2024

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.

@benjamn benjamn marked this pull request as ready for review January 23, 2024 18:27
@benjamn benjamn requested review from a team as code owners January 23, 2024 18:27
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)) {
Copy link
Contributor

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.

Copy link
Member Author

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:

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:
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.

Copy link
Contributor

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.

Copy link
Contributor

@lennyburdette lennyburdette Jan 23, 2024

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

Copy link
Contributor

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.

Copy link
Contributor

@clenfest clenfest left a 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).

@benjamn benjamn changed the base branch from next to main January 23, 2024 19:49
Copy link

netlify bot commented Jan 24, 2024

Deploy Preview for apollo-federation-docs ready!

Name Link
🔨 Latest commit 066783f
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/65b13c1badc8ff0009cc36b1
😎 Deploy Preview https://deploy-preview-2914--apollo-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@benjamn benjamn enabled auto-merge (squash) January 24, 2024 16:34
@benjamn benjamn merged commit 493f5ac into main Jan 24, 2024
17 checks passed
@benjamn benjamn deleted the benjamn/additional-SourceSpecDefinition-validations branch January 24, 2024 16:39
clenfest pushed a commit that referenced this pull request Jan 24, 2024
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>
tninesling added a commit that referenced this pull request Feb 5, 2024
… 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]>
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.

4 participants