feat(cli): allow disabling legacy federation injection for FederationV2 schemas#10788
Open
robertobadalamenti wants to merge 1 commit intodotansimha:masterfrom
Open
Conversation
|
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.
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
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:
Test Environment:
@graphql-codegen/cli: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.