Skip to content

Support constant arguments in field selection maps and @key - #9974

Merged
glen-84 merged 13 commits into
mainfrom
gai/selectionsetmap-constant-arg-composition
Jun 23, 2026
Merged

glen-84 merged 13 commits into
mainfrom
gai/selectionsetmap-constant-arg-composition

Conversation

@glen-84

@glen-84 glen-84 commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds composition-layer support for constant arguments on selected fields in field selection maps (@is, @require, @lookup) and relaxes @key to permit them, per the composite-schemas spec.

  • Validates that supplied arguments are constant literals matching the field's argument definitions (argument exists, value coerces to the type, required arguments supplied), surfacing errors under IS_INVALID_FIELDS / REQUIRE_INVALID_FIELDS and the renamed KEY_INVALID_ARGUMENTS (was KEY_FIELDS_HAS_ARGUMENTS).
  • Carries constant arguments through the field-selection-map → selection-set rewrite so they reach the composed @fusion__requires / @fusion__lookup. @provides continues to disallow arguments.
  • Updates the Fusion v16 documentation.

Test plan

  • dotnet test src/HotChocolate/Fusion/test/Fusion.Utilities.Tests — 238 pass
  • dotnet test src/HotChocolate/Fusion/test/Fusion.Composition.Tests — 525 pass
  • New unit and rule tests cover constant-argument validation across @is, @require, and @key, the value-node converter, the rewriter carry-through, and a composition snapshot showing constant arguments in @fusion__requires.

Copilot AI review requested due to automatic review settings June 23, 2026 14:09
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Jun 23, 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.

Pull request overview

Adds composition-layer support for constant arguments on fields referenced by field selection maps (@is, @require, @lookup) and relaxes @key to allow constant arguments, including validation and composition carry-through into generated selection sets.

Changes:

  • Introduces constant-argument validation (argument existence, type compatibility, duplicate detection, and required-argument checks) and applies it to field selection maps and @key.
  • Preserves constant arguments during field-selection-map → selection-set rewriting so they reach composed directives like @fusion__requires / @fusion__lookup.
  • Updates Fusion v16 documentation and expands test coverage for constant-argument behavior and the new KEY_INVALID_ARGUMENTS error.

Reviewed changes

Copilot reviewed 25 out of 27 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
website/src/docs/fusion/v16/entities-and-lookups.md Documents constant arguments in @key(fields: ...).
website/src/docs/fusion/v16/directives-reference.md Documents constant arguments for @key, @is, @require; reiterates @provides argument prohibition.
website/src/docs/fusion/v16/data-requirements-and-mapping.md Adds a section explaining constant arguments in selection maps with an example.
website/src/docs/fusion/v16/composition.md Updates composition error table to replace KEY_FIELDS_HAS_ARGUMENTS with KEY_INVALID_ARGUMENTS.
src/HotChocolate/Fusion/test/Fusion.Utilities.Tests/Validators/FieldSelectionMapValidatorTests.cs Adds valid/invalid cases for constant arguments in field selection maps.
src/HotChocolate/Fusion/test/Fusion.Utilities.Tests/Validators/ConstantArgumentValidatorTests.cs New unit tests for constant-argument validation rules.
src/HotChocolate/Fusion/test/Fusion.Utilities.Tests/Rewriters/ValueSelectionToSelectionSetRewriterTests.cs Adds rewrite tests ensuring arguments are preserved in generated selection sets.
src/HotChocolate/Fusion/test/Fusion.Utilities.Tests/Converters/FieldSelectionMapValueNodeConverterTests.cs New unit tests for converting Fusion value nodes to HotChocolate language value nodes.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaValidationRules/KeyInvalidArgumentsRuleTests.cs New rule tests for KEY_INVALID_ARGUMENTS (unknown arg, incompatible value, missing required, variables).
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaValidationRules/KeyFieldsHasArgumentsRuleTests.cs Removes tests for the old KEY_FIELDS_HAS_ARGUMENTS rule.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/SourceSchemaMerger.OutputField.Tests.cs Adds snapshot test showing constant arguments preserved in composed @fusion__requires.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/PostMergeValidationRules/RequireInvalidFieldsRuleTests.cs Adds post-merge validation coverage for constant args in @require selection maps.
src/HotChocolate/Fusion/test/Fusion.Composition.Tests/PostMergeValidationRules/IsInvalidFieldsRuleTests.cs Adds post-merge validation coverage for constant args in @is selection maps.
src/HotChocolate/Fusion/src/Fusion.Utilities/Validators/FieldSelectionMapValidator.cs Hooks constant-argument validation into selection-map validation.
src/HotChocolate/Fusion/src/Fusion.Utilities/Validators/ConstantArgumentValidator.cs New validator implementing constant-argument semantic checks.
src/HotChocolate/Fusion/src/Fusion.Utilities/Rewriters/ValueSelectionToSelectionSetRewriter.cs Preserves arguments when rewriting selections into FieldNodes.
src/HotChocolate/Fusion/src/Fusion.Utilities/Properties/FusionUtilitiesResources.resx Adds localized messages for constant-argument validation errors.
src/HotChocolate/Fusion/src/Fusion.Utilities/Properties/FusionUtilitiesResources.Designer.cs Adds resource accessors for new validator messages.
src/HotChocolate/Fusion/src/Fusion.Utilities/Converters/FieldSelectionMapValueNodeConverter.cs New converter from Fusion language value nodes to HotChocolate language value nodes.
src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaValidationRules/KeyInvalidArgumentsRule.cs New composition rule validating constant arguments in @key(fields: ...).
src/HotChocolate/Fusion/src/Fusion.Composition/SourceSchemaValidationRules/KeyFieldsHasArgumentsRule.cs Removes old rule that rejected any argument usage in @key fields.
src/HotChocolate/Fusion/src/Fusion.Composition/SchemaComposer.cs Swaps rule registration to use KeyInvalidArgumentsRule.
src/HotChocolate/Fusion/src/Fusion.Composition/Properties/CompositionResources.resx Adds log template for KEY_INVALID_ARGUMENTS and removes old template.
src/HotChocolate/Fusion/src/Fusion.Composition/Properties/CompositionResources.Designer.cs Updates resource accessors to match resx changes.
src/HotChocolate/Fusion/src/Fusion.Composition/Logging/LogEntryHelper.cs Adds KeyInvalidArguments(...) log entry builder.
src/HotChocolate/Fusion/src/Fusion.Composition/Logging/LogEntryCodes.cs Adds KEY_INVALID_ARGUMENTS code constant and removes KEY_FIELDS_HAS_ARGUMENTS.
dictionary.txt Adds unsupplied to dictionary.
Files not reviewed (2)
  • src/HotChocolate/Fusion/src/Fusion.Composition/Properties/CompositionResources.Designer.cs: Generated file
  • src/HotChocolate/Fusion/src/Fusion.Utilities/Properties/FusionUtilitiesResources.Designer.cs: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +71 to +83
foreach (var argumentDefinition in field.Arguments.AsEnumerable())
{
if (argumentDefinition.Type.IsNonNullType()
&& argumentDefinition.DefaultValue is null
&& !provided.Contains(argumentDefinition.Name))
{
errors.Add(
string.Format(
ConstantArgumentValidator_MissingRequiredArgument,
argumentDefinition.Name,
fieldCoordinate));
}
}
Comment on lines +201 to +209
foreach (var inputField in inputObjectType.Fields.AsEnumerable())
{
if (inputField.Type.IsNonNullType()
&& inputField.DefaultValue is null
&& !provided.Contains(inputField.Name))
{
return false;
}
}
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the gai/selectionsetmap-... branch remains at 49%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main 5862763 gai/selectionsetmap-... 9e9eb15 +/-
/home/runner/wo...eiveEndpoint.cs 77% 69% -8%
/home/runner/wo...gerMessage.g.cs 10% 6% -4%
/home/runner/wo...PromiseCache.cs 81% 78% -3%
/home/runner/wo...MapValidator.cs 95% 93% -2%
/home/runner/wo...nManagerBase.cs 83% 82% -1%
/home/runner/wo...tocolHandler.cs 86% 85% -1%
/home/runner/wo...onCollection.cs 31% 62% +31%
/home/runner/wo...entValidator.cs 0% 80% +80%
/home/runner/wo...rgumentsRule.cs 0% 89% +89%
/home/runner/wo...odeConverter.cs 0% 95% +95%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

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