Repository navigation
Fix Fusion composition crash on repeated @key in Apollo Federation schemas - #10269
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Fusion composition crashing when an Apollo Federation schema repeats the same @key(fields: ...) on both a type and an extend type block (issue #10221). It does so by normalizing key field selections to detect duplicates and by deduplicating generated lookup fields instead of throwing an unhandled ArgumentException.
Changes:
- Deduplicate repeated
@keydirectives (including those differing only by whitespace/field order) when generating Fusion lookup fields, preventing duplicatefusion__lookup_*collisions. - Introduce
FieldSelectionnormalization logic and reuse it in composition validation to compare structurally equivalent key selections. - Switch
Utf8GraphQLParser.Syntaxfragment parsing to useParserOptions.Trusted(no request limits) and add/extend tests + snapshots covering the new behaviors.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Language/test/Language.Tests/Parser/GraphQLParserSyntaxTests.cs | Adds a test ensuring Utf8GraphQLParser.Syntax.ParseSelectionSet is not constrained by default request limits. |
| src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Syntax.cs | Uses ParserOptions.Trusted for Syntax fragment parsing and documents the intent (trusted input). |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/PreMergeValidationRules/InterfaceObjectKeyMismatchRuleTests.cs | Adds coverage for key equivalence when order/whitespace differ. |
| src/HotChocolate/Fusion/test/Fusion.Composition.Tests/FieldSelectionTests.cs | New test suite for field selection normalization behavior. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/RepeatedKeyLookupTests.cs | Repro-style test ensuring composition succeeds for repeated type+extension @key. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/FederationSchemaTransformerTests.cs | Adds transformer tests ensuring single lookup generation for repeated/normalized keys, and correctness around resolvable. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/FederationKeyValidationTests.cs | Adds coverage that invalid @key(fields: ...) syntax produces a diagnostic instead of crashing. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/RepeatedKeyLookupTests.Compose_Should_Succeed_When_SameKeyIsRepeatedOnTypeAndExtension.graphql | Snapshot for composed schema output in repeated-key scenario. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_Should_KeepBothKeys_When_SameFieldsDifferOnlyInResolvable.md | Snapshot validating key retention rules when resolvable differs. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_Should_GenerateSingleLookup_When_SameKeyIsRepeatedOnTypeAndExtension.md | Snapshot validating single lookup generation for repeated type+extension key. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_Should_GenerateSingleLookup_When_ListSegmentKeyIsRepeated.md | Snapshot validating dedupe behavior for repeated list-segment keys. |
| src/HotChocolate/Fusion/test/Fusion.Composition.ApolloFederation.Tests/snapshots/FederationSchemaTransformerTests.Transform_Should_GenerateSingleLookup_When_KeysDifferOnlyInWhitespaceOrFieldOrder.md | Snapshot validating dedupe behavior for equivalent keys with differing formatting/order. |
| src/HotChocolate/Fusion/src/Fusion.Composition/PreMergeValidationRules/InterfaceObjectKeyMismatchRule.cs | Switches key comparison to FieldSelection.Normalize. |
| src/HotChocolate/Fusion/src/Fusion.Composition/FieldSelection.cs | Introduces normalization/merging/sorting logic for selection sets used as @key(fields: ...). |
| src/HotChocolate/Fusion/src/Fusion.Composition/ApolloFederation/GenerateLookupFields.cs | Adds duplicate-key identity tracking and reuses parsed selection sets to prevent duplicate lookup generation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| .OrderBy(p => p, StringComparer.Ordinal); | ||
|
|
||
| return string.Join(" ", parts); | ||
| return FieldSelection.Normalize(fields.Value); |
Contributor
Patch coverage81.1% of changed lines covered (189/233)
Uncovered changed lines (JSON){
"sha": "dd2f101186d3f2796a4388378cadf1120e83f5d7",
"files": [
{ "path": "src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Syntax.cs", "ranges": [[34, 34], [55, 55], [76, 76], [118, 118], [211, 211]] },
{ "path": "src/HotChocolate/Fusion/src/Fusion.Composition/FieldSelection.cs", "ranges": [[102, 104], [133, 134], [136, 143], [213, 214], [218, 219], [233, 235], [240, 242], [263, 264], [268, 269], [286, 288], [305, 306], [310, 311], [315, 316], [340, 340], [349, 350]] }
]
}Project coverage: 54.5% (243533/446855 lines) |
This was referenced Aug 29, 2026
Merged
This was referenced Sep 8, 2026
Closed
Closed
This was referenced Sep 15, 2026
Closed
[nuget][SUI_Matcher]- Bump the sui-package-updates group with 20 updates
DFE-Digital/SUI_Matcher#405
Closed
Closed
This was referenced Sep 22, 2026
Closed
Closed
[nuget][SUI_Matcher]- Bump the sui-package-updates group with 20 updates
DFE-Digital/SUI_Matcher#410
Merged
This was referenced Oct 5, 2026
Open
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.
Fixes #10221