Skip to content

feat(cli): allow disabling legacy federation injection for FederationV2 schemas#10788

Merged
eddeee888 merged 3 commits into
dotansimha:masterfrom
robertobadalamenti:feat/disable-legacy-federation-injection
May 27, 2026
Merged

feat(cli): allow disabling legacy federation injection for FederationV2 schemas#10788
eddeee888 merged 3 commits into
dotansimha:masterfrom
robertobadalamenti:feat/disable-legacy-federation-injection

Conversation

@robertobadalamenti

@robertobadalamenti robertobadalamenti commented May 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR introduces the disableFederationDirectiveAndScalarInjection flag to the codegen core.

Currently, when federation: true is set, the generator automatically injects legacy Federation v1 definitions (like scalar _FieldSet and directives @key, @Shareable, etc.). In Apollo Federation v2, these are typically imported via the @link directive, causing "Invalid definition" errors during validation.

This flag allows users to opt-out of the automatic injection while keeping federation support active.

Related #10787

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Screenshots/Sandbox (if appropriate/relevant):

https://github.com/robertobadalamenti/codegen-federationv2-bug

How Has This Been Tested?

I have added unit tests in packages/graphql-codegen-core/tests/codegen.spec.ts to verify that:

  • The default behavior remains unchanged (injection still happens if the flag is not set).
  • When the flag is true, no legacy federation definitions are added to the schema.
  • The flag correctly interacts with existing federation settings.

Test Environment:

  • OS: macOS
  • @graphql-codegen/cli:
  • NodeJS: v24.15.0

Further comments

The solution was implemented at the core level to ensure it works across all plugins that rely on the central codegen logic. I considered automatic detection of Federation v2, but an explicit flag was chosen to avoid breaking changes and provide more predictable control to the user.

@changeset-bot

changeset-bot Bot commented May 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 81e4985

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@eddeee888

Copy link
Copy Markdown
Collaborator

Thank you @robertobadalamenti !
I feel this is a good quick option for now to support federation v2 👍

Side note: It's a bit odd that this is happening in the core codegen package, so I'll have a think how to decouple it later.

@eddeee888 eddeee888 merged commit cbf9544 into dotansimha:master May 27, 2026
18 of 19 checks passed
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.

2 participants