Skip to content

Add opt-in covariant field merging to selection set validation - #10413

Merged
glen-84 merged 1 commit into
mainfrom
gai/covariant-field-merging-opt-in
Sep 21, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/covariant-field-merging-opt-in

Conversation

@glen-84

@glen-84 glen-84 commented Sep 21, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds SchemaOptions.EnableCovariantFieldMerging, default false. When enabled, the field selection merging rule ignores Non-Null wrappers at every level when comparing response shapes, so title: String on an interface and title: String! on an implementing type merge under one response name. List-ness and the named type must still match, and the default behavior is unchanged.
  • The option flows into ValidationOptions the same way EnableEmptySelectionSets does and can be overridden per validator through ConfigureValidation. The relaxation follows graphql-spec PR 883, proposed for issue 804. Fusion gateway and StrawberryShake support are tracked separately.
  • Documents the option in the server options reference.

Test plan

  • Rule-level tests with the option enabled: sibling implementations, an interface fragment beside a concrete selection, union members, list nullability, nested sub-selections, and the list-versus-scalar and differing-named-type cases that must still conflict.
  • Validator-level and end-to-end tests confirm the option reaches the rule through AddDefaultRules and ModifyOptions.
  • SchemaOptions copy snapshot updated. The Validation test project and the Core solution build pass with EnforceCodeStyleInBuild.

Copilot AI lite review requested due to automatic review settings September 21, 2026 09:59
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Sep 21, 2026

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.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified, and the requested behavior is comprehensively tested.

Review effort: Lite
Findings: None

What changed in this PR

Adds opt-in covariant field merging, allowing fields differing only by nullability to merge during GraphQL validation while preserving existing defaults.

Changes:

  • Adds and propagates EnableCovariantFieldMerging.
  • Updates merging logic, tests, snapshots, and benchmarks.
  • Documents the new schema option.
File Summary
website/​content/​docs/​hotchocolate/​server/​options.md Documents the option.
src/​HotChocolate/​Core/​test/​Validation.Tests/​FieldSelectionMergingRuleTests.cs Tests merging behavior.
src/​HotChocolate/​Core/​test/​Validation.Tests/​DocumentValidatorTests.cs Tests validator configuration.
src/​HotChocolate/​Core/​test/​Types.Tests/​SchemaOptionsTests.cs Tests option copying.
src/​HotChocolate/​Core/​test/​Types.Tests/​__snapshots__/​SchemaOptionsTests.FromOptions_Should_CopyEveryOption_When_OptionsAreConfigured.snap Updates the options snapshot.
src/​HotChocolate/​Core/​test/​Execution.Tests/​DependencyInjection/​RequestExecutorBuilderExtensions_SchemaOptionsTests.cs Tests end-to-end propagation.
src/​HotChocolate/​Core/​src/​Validation/​Rules/​OverlappingFieldsCanBeMergedRule.cs Implements configurable covariant merging.
src/​HotChocolate/​Core/​src/​Validation/​Options/​ValidationOptions.cs Adds validation configuration.
src/​HotChocolate/​Core/​src/​Validation/​Extensions/​ValidationBuilderExtensions.cs Passes the option to the rule.
src/​HotChocolate/​Core/​src/​Types/​SchemaOptions.cs Adds and copies schema configuration.
src/​HotChocolate/​Core/​src/​Types/​IReadOnlySchemaOptions.cs Exposes the read-only option.
src/​HotChocolate/​Core/​src/​Types/​Execution/​RequestExecutorManager.cs Propagates schema settings.
src/​HotChocolate/​Core/​benchmarks/​Validation.Benchmarks/​OverlappingFieldsMergedBenchmark.cs Updates benchmark construction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (32/32)

File Covered Changed Patch %
…/Core/src/Types/Execution/RequestExecutorManager.cs 5 5 100.0% 🟢
src/HotChocolate/Core/src/Types/SchemaOptions.cs 2 2 100.0% 🟢
…/src/Validation/Extensions/ValidationBuilderExtensions.cs 3 3 100.0% 🟢
…/Core/src/Validation/Options/ValidationOptions.cs 1 1 100.0% 🟢
…/src/Validation/Rules/OverlappingFieldsCanBeMergedRule.cs 21 21 100.0% 🟢

Project coverage: 58.2% (291020/500394 lines)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants