Skip to content

Apply explicit null variable defaults when variables are omitted - #10424

Merged
glen-84 merged 1 commit into
mainfrom
gai/explicit-null-variable-defaults
Sep 24, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/explicit-null-variable-defaults

Conversation

@glen-84

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

Copy link
Copy Markdown
Member

Summary

  • Variable coercion in Core and Fusion now applies an explicit null variable default ($value: Int = null) when the request omits the variable, as Coercing Variable Values requires. Both helpers skipped a null default, so the variable was treated as not provided and an argument default such as field(arg: Int = 5) resolved to 5 instead of null. This regressed in Adds ResultDocument to HotChocolate Core #8931 and affects every release since 16.0.0.
  • The Fusion gateway now sends the coerced null to the subgraph as an explicit variable value, so the result no longer depends on how the subgraph handles the forwarded = null default.
  • Non-null variables are unaffected: validation already rejects a null default on them ($a: Int! = null).

Test plan

  • Core: a VariableCoercionHelper unit test for an omitted variable with a null default, and an ArgumentCoercionTests execution test where echo(value: Int = 5) returns null.
  • Fusion: a VariableCoercionHelper unit test, and a gateway test whose snapshot shows the subgraph receiving "value": null and the response returning null.
  • All four tests fail without the fix and pass with it on net10.0.
  • The neighbouring coercion test classes (Core VariableCoercionHelperTests, ArgumentCoercionTests, VariableCoercionIntegrationTests, and CodeFirstTests; Fusion VariableCoercionHelperTests and VariableCoercionTests) pass, as do the existing tests that use null variable defaults (IdAttributeTests and SlicingArgumentsTests).

Closes #10423

Copilot AI lite review requested due to automatic review settings September 24, 2026 07:56

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

The reviewed changes include regression coverage and no unresolved blocking issues.

Review effort: Lite
Findings: None

What changed in this PR

Updates Core and Fusion variable coercion to preserve explicit null defaults for omitted nullable variables and forward them correctly.

Changes:

  • Applies explicit null variable defaults.
  • Adds Core, Fusion, and gateway regression tests.
  • Verifies Fusion forwards coerced null values.
File Description
src/​HotChocolate/​Fusion/​test/​Fusion.Execution.Tests/​Execution/​VariableCoercionHelperTests.cs Tests Fusion null-default coercion.
src/​HotChocolate/​Fusion/​test/​Fusion.AspNetCore.Tests/​VariableCoercionTests.cs Tests gateway forwarding and execution.
src/​HotChocolate/​Fusion/​test/​Fusion.AspNetCore.Tests/​__snapshots__/​VariableCoercionTests.Omitted_Variable_With_Null_Default_Overrides_Argument_Default.yaml Captures expected forwarded null behavior.
src/​HotChocolate/​Fusion/​src/​Fusion.Execution/​Execution/​VariableCoercionHelper.cs Applies explicit defaults in Fusion.
src/​HotChocolate/​Core/​test/​Execution.Tests/​Processing/​VariableCoercionHelperTests.cs Tests Core null-default coercion.
src/​HotChocolate/​Core/​test/​Execution.Tests/​Integration/​Spec/​ArgumentCoercionTests.cs Verifies null overrides argument defaults.
src/​HotChocolate/​Core/​src/​Types/​Execution/​Processing/​VariableCoercionHelper.cs Applies explicit defaults in Core.

💡 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 (23/23)

File Covered Changed Patch %
…/src/Types/Execution/Processing/VariableCoercionHelper.cs 8 8 100.0% 🟢
…/src/Fusion.Execution/Execution/VariableCoercionHelper.cs 15 15 100.0% 🟢

Project coverage: 58.8% (299817/509758 lines)

@glen-84
glen-84 merged commit d7c99f7 into main Sep 24, 2026
158 checks passed
@glen-84
glen-84 deleted the gai/explicit-null-variable-defaults branch September 24, 2026 08:08
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.

Explicit null variable defaults are ignored when variables are omitted

2 participants