Skip to content

Add fragment arguments support to the GraphQL syntax layer - #10270

Merged
glen-84 merged 2 commits into
mainfrom
gai/fragment-arguments-syntax-layer
Aug 20, 2026
Merged

glen-84 merged 2 commits into
mainfrom
gai/fragment-arguments-syntax-layer

Conversation

@glen-84

@glen-84 glen-84 commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Parses fragment spread arguments (...F(size: 10)) into a new FragmentSpreadNode.Arguments, gated behind the experimental allowFragmentArguments parser option. It is off by default, so existing documents are unaffected.
  • Carries arguments through the rest of the syntax layer: equality and hashing, the query serializer, the visitation map, and SyntaxRewriter, which would otherwise silently drop them when rebuilding a spread. FragmentDefinitionNode now also walks its own VariableDefinitions, mirroring OperationDefinitionNode.
  • Keeps the three-parameter FragmentSpreadNode constructor as an [Obsolete] overload that delegates with an empty argument list, so this is non-breaking on the 16.x line. Enabling allowFragmentArguments implies allowFragmentVariables in both Utf8GraphQLParser and Utf8GraphQLOperationParser, so one options object means the same thing in both.

This is the syntax layer only. Validation rules and the rewrite pass that substitutes arguments into inlined selection sets are follow-ups; no server configuration can reach either execution engine with a fragment-argument document yet, because neither request-parser options type exposes the flag.

Test plan

  • dotnet test src/HotChocolate/Language/HotChocolate.Language.slnx passes 4224 tests across net8.0, net9.0, net10.0, and net11.0.
  • New parser tests cover spreads with arguments being accepted with the flag on and rejected with it off, and Utf8GraphQLOperationParser honouring the same option as Utf8GraphQLParser.
  • Round-trip printing tests assert a spread re-prints with its arguments before its directives.
  • Visitor, rewriter, and node tests pin that arguments are visited, rewritten, and preserved across every With* call; each was mutation-checked, so removing the production code makes them fail.
  • Six AST snapshots each gain one "Arguments": [] line. The introspection query builder's printed-GraphQL snapshots are unchanged, confirming its call-site update is behaviour-neutral.

Copilot AI lite review requested due to automatic review settings August 20, 2026 07:52

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 adds experimental support in the HotChocolate GraphQL syntax layer for fragment spread arguments (e.g. ...F(size: 10)), gated behind a new parser option so existing documents remain unaffected by default. It threads the new FragmentSpreadNode.Arguments through parsing, printing/serialization, visitor/rewriter behavior, and syntax equality/hashing, with corresponding test and snapshot updates.

Changes:

  • Add FragmentSpreadNode.Arguments and update serializer, visitor map, and rewriter to preserve/visit/print arguments.
  • Introduce experimental parser option allowFragmentArguments (also implying fragment variables) and update UTF-8 parsers accordingly.
  • Add/extend unit tests and snapshots to cover parsing, formatting, visiting, rewriting, and round-trip printing of fragment spread arguments.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionQueryBuilder.cs Updates fragment spread construction to pass an empty arguments list explicitly.
src/HotChocolate/Language/test/Language.Web.Tests/snapshots/Utf8GraphQLRequestParserTests.Utf8GraphQLRequestParser_Parse.snap Snapshot updated to include Arguments: [] on fragment spreads.
src/HotChocolate/Language/test/Language.Web.Tests/snapshots/Utf8GraphQLRequestParserTests.Parse_Kitchen_Sink_Query_With_Cache.snap Snapshot updated to include Arguments: [] on fragment spreads.
src/HotChocolate/Language/test/Language.Web.Tests/snapshots/Utf8GraphQLRequestParserTests.Parse_Kitchen_Sink_Query_No_Cache.snap Snapshot updated to include Arguments: [] on fragment spreads.
src/HotChocolate/Language/test/Language.Web.Tests/snapshots/Utf8GraphQLRequestParserTests.Parse_Kitchen_Sink_Query_AllProps_No_Cache.snap Snapshot updated to include Arguments: [] on fragment spreads.
src/HotChocolate/Language/test/Language.Web.Tests/snapshots/Utf8GraphQLRequestParserTests.Parse_Id_As_Name.snap Snapshot updated to include Arguments: [] on fragment spreads.
src/HotChocolate/Language/test/Language.Tests/Visitors/SyntaxVisitorTests.cs Adds visitor tests for fragment spread arguments and fragment definition variable definitions.
src/HotChocolate/Language/test/Language.Tests/Visitors/SyntaxRewriterTests.cs Adds rewriter tests to ensure fragment spread arguments are preserved/rewritten.
src/HotChocolate/Language/test/Language.Tests/Utilities/SyntaxPrinterTests.cs Adds round-trip printing tests for fragment spreads with arguments (and directives).
src/HotChocolate/Language/test/Language.Tests/Parser/Utf8SyntaxFormatterTests.cs Ensures formatting emits fragment variable definitions when fragment arguments are allowed.
src/HotChocolate/Language/test/Language.Tests/Parser/QueryParserTests.cs Adds parser tests for spread arguments and fragment variable definitions under the new flag.
src/HotChocolate/Language/test/Language.Tests/Parser/snapshots/KitchenSinkParserTests.ParseFacebookKitchenSinkQuery.snap Snapshot updated to include Arguments: [] on fragment spreads.
src/HotChocolate/Language/test/Language.SyntaxTree.Tests/FragmentSpreadNodeTests.cs Extends syntax-node tests for equality/hashing and With* preservation of arguments.
src/HotChocolate/Language/test/Language.SyntaxTree.Tests/FragmentDefinitionNodeTests.cs Verifies node enumeration order includes fragment variable definitions.
src/HotChocolate/Language/src/Language.Visitors/SyntaxVisitor~1.VisitationMap.cs Adds visitation of fragment spread arguments (gated by VisitArguments) and fragment variable defs.
src/HotChocolate/Language/src/Language.Visitors/SyntaxRewriter~1.cs Ensures rewriter preserves/rewrites FragmentSpreadNode.Arguments.
src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.Fragments.cs Extends fragment spread parsing grammar to optionally parse arguments when enabled.
src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.cs Adds _allowFragmentArgs and makes it imply _allowFragmentVars.
src/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLOperationParser.cs Makes allowFragmentArguments imply fragment variables in the operation parser options.
src/HotChocolate/Language/src/Language.Utf8/ParserOptionsExperimental.cs Adds AllowFragmentArguments and updates documentation for experimental flags.
src/HotChocolate/Language/src/Language.Utf8/ParserOptions.cs Adds public API surface for allowFragmentArguments via ParserOptions.
src/HotChocolate/Language/src/Language.SyntaxTree/Utilities/SyntaxSerializer.QuerySyntax.cs Prints fragment spread arguments before directives when present.
src/HotChocolate/Language/src/Language.SyntaxTree/SyntaxEqualityComparer.cs Includes fragment spread arguments in syntax equality and hashing.
src/HotChocolate/Language/src/Language.SyntaxTree/FragmentSpreadNode.cs Introduces Arguments on FragmentSpreadNode, updates constructors and With* methods.
src/HotChocolate/Language/src/Language.SyntaxTree/FragmentDefinitionNode.cs Enumerates fragment variable definitions in GetNodes() (mirrors operations).

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

Comment thread src/HotChocolate/Language/src/Language.Utf8/ParserOptions.cs
@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

95.6% of changed lines covered (87/91)

File Covered Changed Patch %
…/src/Language.Visitors/SyntaxVisitor~1.VisitationMap.cs 11 15 73.3% 🔴
…/Language/src/Language.SyntaxTree/FragmentDefinitionNode.cs 4 4 100.0% 🟢
…/Language/src/Language.SyntaxTree/FragmentSpreadNode.cs 15 15 100.0% 🟢
…/Language/src/Language.SyntaxTree/SyntaxEqualityComparer.cs 6 6 100.0% 🟢
…/Utilities/SyntaxSerializer.QuerySyntax.cs 4 4 100.0% 🟢
src/HotChocolate/Language/src/Language.Utf8/ParserOptions.cs 19 19 100.0% 🟢
…/Language/src/Language.Utf8/ParserOptionsExperimental.cs 5 5 100.0% 🟢
…/Language/src/Language.Utf8/Utf8GraphQLOperationParser.cs 2 2 100.0% 🟢
…/Language/src/Language.Utf8/Utf8GraphQLParser.Fragments.cs 4 4 100.0% 🟢
…/HotChocolate/Language/src/Language.Utf8/Utf8GraphQLParser.cs 6 6 100.0% 🟢
…/Language/src/Language.Visitors/SyntaxRewriter~1.cs 3 3 100.0% 🟢
…/src/Utilities.Introspection/IntrospectionQueryBuilder.cs 8 8 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "74ae23b03186a7f245825f024e52af0adbc72f89",
  "files": [
    { "path": "src/HotChocolate/Language/src/Language.Visitors/SyntaxVisitor~1.VisitationMap.cs", "ranges": [[298, 299], [361, 362]] }
  ]
}

Project coverage: 54.5% (243659/447012 lines)

@glen-84
glen-84 merged commit 1d11199 into main Aug 20, 2026
149 checks passed
@glen-84
glen-84 deleted the gai/fragment-arguments-syntax-layer branch August 20, 2026 08:59
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.

2 participants