Repository navigation
Validate fragment arguments and scope fragment variables - #10272
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends HotChocolate’s document validation to support the experimental “fragment variable definitions + fragment spread arguments” syntax by (1) validating fragment-spread arguments against the target fragment’s declared variables and (2) introducing fragment-local variable scoping/shadowing so fragment variables do not interfere with operation variables outside the fragment.
Changes:
- Add fragment-spread argument validation (unknown arg, duplicate arg, missing required arg / explicit null for required) and reuse existing error messages with a
fragmentextension. - Implement fragment variable scoping + shadowing behavior and update variable/value visitors so fragment-spread arguments are typed from the target fragment’s variable definitions.
- Add/adjust validation tests and snapshots to cover fragment-argument parsing/validation and updated
specifiedBylinks.
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/test/Validation.Tests/VariablesAreInputTypesRuleTests.cs | Adds coverage for fragment-declared variable being an output type. |
| src/HotChocolate/Core/test/Validation.Tests/ValuesOfCorrectTypeRuleTests.cs | Adds coverage for wrong-typed literal passed to fragment spread argument. |
| src/HotChocolate/Core/test/Validation.Tests/RequiredArgumentRuleTests.cs | Adds coverage for missing required fragment variable at spread site. |
| src/HotChocolate/Core/test/Validation.Tests/DocumentValidatorVisitorTestBase.cs | Adds parser-option overloads + shared parser options enabling fragment arguments in tests. |
| src/HotChocolate/Core/test/Validation.Tests/ArgumentUniquenessRuleTests.cs | Adds coverage for duplicate fragment spread arguments. |
| src/HotChocolate/Core/test/Validation.Tests/ArgumentNamesRuleTests.cs | Adds coverage for unknown fragment spread argument names. |
| src/HotChocolate/Core/test/Validation.Tests/AllVariableUsagesAreAllowedRuleTests.cs | Adds coverage for shadowing restore + nullable-to-nonnull fragment argument variable passing. |
| src/HotChocolate/Core/test/Validation.Tests/AllVariablesUsedRuleTests.cs | Adds coverage for fragment-only declaration, unused fragment variables, and operation var used only inside shadowing fragment. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/VariablesAreInputTypesRuleTests.Validate_Should_Report_When_AFragmentDeclaresAnOutputTypeVariable.snap | New snapshot for fragment variable input-type validation + fragment-unused-variable reporting. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ValuesOfCorrectTypeRuleTests.Validate_Should_Report_When_AFragmentArgumentValueHasTheWrongType.snap | New snapshot for wrong-typed fragment argument value. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/RequiredArgumentRuleTests.Validate_Should_Report_When_ASpreadOmitsARequiredFragmentVariable.snap | New snapshot for missing required fragment argument. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/RequiredArgumentRuleTests.MissingOneNonNullableArgument.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/RequiredArgumentRuleTests.IncorrectValueAndMissingArgument.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/DocumentValidatorTests.InvalidFieldArgName.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentUniquenessRuleTests.Validate_Should_Report_When_ASpreadPassesTheSameArgumentTwice.snap | New snapshot for duplicate fragment arguments error including fragment extension. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.Validate_Should_Report_When_ASpreadPassesAnArgumentTheFragmentDoesNotDeclare.snap | New snapshot for unknown fragment argument error including fragment extension. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.UnknownArgsDeeply.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.UnknownArgsAmongstKnowArgs.snap | Updates specifiedBy link for ArgumentDoesNotExist (two occurrences). |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.MisspelledFieldArgsAreReported.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.MisspelledDirectiveArgsAreReported.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.InvalidFieldArgNameInReusedFragment.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.InvalidFieldArgName.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.InvalidDirectiveArgName.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/ArgumentNamesRuleTests.DirectiveWithWrongArgsIsInvalid.snap | Updates specifiedBy link for ArgumentDoesNotExist. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/AllVariableUsagesAreAllowedRuleTests.Validate_Should_Report_When_ANullableVariableIsPassedToANonNullFragmentArgument.snap | New snapshot for variable-usage compatibility when passing op var to required fragment arg. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/AllVariablesUsedRuleTests.Validate_Should_Report_When_AnOperationVariableIsOnlyUsedInsideAShadowingFragment.snap | New snapshot for operation variable reported unused due to fragment shadowing. |
| src/HotChocolate/Core/test/Validation.Tests/snapshots/AllVariablesUsedRuleTests.Validate_Should_Report_When_AFragmentDeclaresAVariableItDoesNotUse.snap | New snapshot for fragment-specific unused-variable reporting. |
| src/HotChocolate/Core/src/Validation/TypeDocumentValidatorVisitor.cs | Adds fragment-variable scope enter/leave and prevents fragment vars registering as op vars. |
| src/HotChocolate/Core/src/Validation/Rules/VariableVisitor.cs | Implements fragment variable frames, fragment-unused-variable reporting, and fragment-spread argument typing/default handling. |
| src/HotChocolate/Core/src/Validation/Rules/ValueVisitor.cs | Types fragment-spread arguments based on target fragment variable definitions. |
| src/HotChocolate/Core/src/Validation/Rules/ArgumentVisitor.cs | Adds fragment-spread argument validation (unknown/duplicate/missing required/null required). |
| src/HotChocolate/Core/src/Validation/Properties/Resources.resx | Adds resource string for fragment-unused-variable error message. |
| src/HotChocolate/Core/src/Validation/Properties/Resources.Designer.cs | Adds strongly-typed accessor for new fragment-unused-variable resource. |
| src/HotChocolate/Core/src/Validation/FragmentArguments.cs | New helper for resolving fragment spread arguments to fragment variable definitions/types. |
| src/HotChocolate/Core/src/Validation/ErrorHelper.cs | Adds fragment-unused-variable error + extends argument error helpers to include optional fragment extension and correct specifiedBy for unknown args. |
| src/HotChocolate/Core/src/Validation/DocumentValidatorContext.cs | Adds fragment-variable scoping/shadowing state and APIs, resets/clears the new state. |
Files not reviewed (1)
- src/HotChocolate/Core/src/Validation/Properties/Resources.Designer.cs: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage95.5% of changed lines covered (254/266)
Uncovered changed lines (JSON){
"sha": "9173ae2d3766a4da22e97f4a1af7fbef37d5dd96",
"files": [
{ "path": "src/HotChocolate/Core/src/Validation/Rules/ArgumentVisitor.cs", "ranges": [[159, 165]] },
{ "path": "src/HotChocolate/Core/src/Validation/FragmentArguments.cs", "ranges": [[30, 31]] },
{ "path": "src/HotChocolate/Core/src/Validation/Rules/ValueVisitor.cs", "ranges": [[162, 162]] },
{ "path": "src/HotChocolate/Core/src/Validation/DocumentValidatorContext.cs", "ranges": [[216, 216]] },
{ "path": "src/HotChocolate/Core/src/Validation/Rules/VariableVisitor.cs", "ranges": [[281, 281]] }
]
}Project coverage: 56.0% (261477/466652 lines) |
This was referenced Aug 29, 2026
Merged
This was referenced Sep 21, 2026
Closed
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
Merged
This was referenced Oct 19, 2026
This was referenced Oct 26, 2026
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.
Summary
nullare each reported. The existing argument messages are reused with afragmentextension, so no new wording was needed for them.Also corrected here:
ArgumentDoesNotExistlinked tosec-Required-Arguments, which is the section asserting that a required argument was supplied. An argument the target does not declare belongs tosec-Argument-Names, as the fragment-arguments RFC states explicitly: "Every argument provided to a named fragment spread must be defined in the set of possible variables of that named fragment." The fix applies to fields and directives too, which moves thespecifiedBylink in 12 existing snapshots.Two rules are deliberately held back, because both depend on how the rewrite pass substitutes arguments: the
FieldsInSetCanMergeextension for same-name spreads carrying different argument sets, and the rejection of a defaulted fragment variable fed a possibly-unprovided operation variable.All of this is reachable only with the experimental parser option, which no server configuration exposes, so the rules are exercised through
DocumentValidatordirectly.Test plan
dotnet test src/HotChocolate/Core/test/Validation.Testspasses 2540 tests across net8.0, net9.0, net10.0, and net11.0.ExpectErrors, which pins each error's message, locations, path, and extensions, including the newfragmentextension.ParserOptionsoverloads so fragment-argument documents parse through the existingExpectValid/ExpectErrorshelpers instead of hand-rolled parse calls.src/All.slnxbuilds with 0 errors.Execution.Testswas clean apart fromSubscriptionEventTimeoutTests, a load-sensitive timing flake that passes in isolation.