Skip to content

Fix Fusion composition crash on repeated @key in Apollo Federation schemas - #10269

Merged
michaelstaib merged 1 commit into
mainfrom
mst/fusion-repeated-key-lookup
Aug 19, 2026
Merged

michaelstaib merged 1 commit into
mainfrom
mst/fusion-repeated-key-lookup

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

Fixes #10221

Copilot AI lite review requested due to automatic review settings August 19, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @key directives (including those differing only by whitespace/field order) when generating Fusion lookup fields, preventing duplicate fusion__lookup_* collisions.
  • Introduce FieldSelection normalization logic and reuse it in composition validation to compare structurally equivalent key selections.
  • Switch Utf8GraphQLParser.Syntax fragment parsing to use ParserOptions.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);
@michaelstaib
michaelstaib merged commit 7a9b4e2 into main Aug 19, 2026
148 checks passed
@michaelstaib
michaelstaib deleted the mst/fusion-repeated-key-lookup branch August 19, 2026 19:41
@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

81.1% of changed lines covered (189/233)

File Covered Changed Patch %
…/Language/src/Language.Utf8/Utf8GraphQLParser.Syntax.cs 7 12 58.3% 🔴
…/HotChocolate/Fusion/src/Fusion.Composition/FieldSelection.cs 165 204 80.9% 🟡
…/Fusion.Composition/ApolloFederation/GenerateLookupFields.cs 16 16 100.0% 🟢
…/PreMergeValidationRules/InterfaceObjectKeyMismatchRule.cs 1 1 100.0% 🟢
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fusion composition crashes with an unhandled ArgumentException on a lawful Apollo supergraph pattern (duplicate generated lookup name)

2 participants