Skip to content

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

Open
robertobadalamenti wants to merge 1 commit intodotansimha:masterfrom
robertobadalamenti:feat/disable-legacy-federation-injection
Open

feat(cli): allow disabling legacy federation injection for FederationV2 schemas#10788
robertobadalamenti wants to merge 1 commit intodotansimha:masterfrom
robertobadalamenti:feat/disable-legacy-federation-injection

Conversation

@robertobadalamenti
Copy link
Copy Markdown

@robertobadalamenti robertobadalamenti commented May 8, 2026

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
Copy link
Copy Markdown

changeset-bot Bot commented May 8, 2026

⚠️ No Changeset found

Latest commit: 033f45b

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

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.

1 participant