Skip to content

Validate circular defaults before coercion - #4460

Open
andimarek wants to merge 8 commits into
masterfrom
codex/simplify-circular-default-validation
Open

andimarek wants to merge 8 commits into
masterfrom
codex/simplify-circular-default-validation

Conversation

@andimarek

@andimarek andimarek commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Programmatic argument defaults can reach circular input-field defaults before schema traversal visits the input type. For example, an argument of type Wrapper { child: Recursive } with default {child: {}} expands Recursive { next: Recursive = {} } until a StackOverflowError occurs.

This PR validates default containers and cycles before running validators that coerce values. Invalid defaults now produce schema validation errors instead of consuming iterators/streams or overflowing the stack.

  • Reject Iterator and BaseStream defaults during schema validation, including values nested in maps, iterables, or arrays. This covers argument, input-field, and directive-argument defaults, including deprecated internal defaults. The setters only store values; they do not traverse or validate them.
  • Run a non-coercing container-validation pass before any default expansion, so an argument cannot consume an invalid input-field default before that field is visited. Schema builders report InvalidSchemaException with InvalidDefaultValue errors. An unchecked FastBuilder defers rejection until explicit validation.
  • Check every resolved input-object type for default cycles before default-value or applied-directive coercion begins. The cycle check uses the schema type map. Literal and programmatic default traversal share the same cycle algorithm, including Iterable and Java arrays.
  • Create fresh cycle-checker and validation-rule instances for every validation run. Remove the argument-specific early check and the coercion guard that depended on a cycle having already been reported.

General runtime iterator/stream coercion remains unchanged. Iterable and array defaults remain supported. Container errors are returned before cycle checking; cycle errors are returned before the remaining validators. Consequently, unrelated errors from later stages are omitted when an earlier stage fails. All discovered errors within the failing stage are collected.

The existing SDL integration tests are retained. Added coverage includes nested argument defaults, list/array wrappers, directive-only input types, multiple independent cycles, repeated validation, and both schema builders with validation enabled. Mocked scalar coercion verifies that default cycles are rejected before coercion. Container tests verify that setters do not traverse values, unsupported sources are not consumed, mutations after setting a default are caught, and valid container defaults work across repeated queries.

Based on the circular-default cleanup in #4450 and merged with master (96443c271).

Validation on Java 25:

  • 237 focused Spock tests passed.
  • ./gradlew test testng check javadoc jacocoTestReport passed: 6,321 Spock cases and 141 TestNG cases passed (7 and 49 skipped, respectively).
  • Per-class coverage gate passed across 994 classes with zero regressions.
  • GitHub CI pending for the final commit.

Port the focused cleanup from the 26.x backport in #4450 to master.
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6508 (+246 🟢) 6452 (+246 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 21 6508 (+246 🟢) 6452 (+246 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 25 6508 (+246 🟢) 6452 (+246 🟢) 0 (±0) 0 (±0) 56 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 19556 (+738 🟢) 19388 (+738 🟢) 0 (±0) 0 (±0) 168 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30503 3048 90.9% +0.1% 🟢
Branches 9060 1476 86.0% +0.3% 🟢
Methods 8129 1185 87.3% +0.1% 🟢

Changed Class Coverage (12 classes)

Class Line Branch Method
g.e.FieldCollector +0.2% 🟢 +0.5% 🟢 ±0.0%
g.s.ShallowTypeRefCollector ±0.0% +0.7% 🟢 ±0.0%
g.s.v.DefaultValueContainersAreValid +100.0% 🟢 +100.0% 🟢 +100.0% 🟢
g.s.v.NoDefaultValueCircularRefs +33.3% 🟢 +45.0% 🟢 +20.0% 🟢
g.s.v.SchemaValidator ±0.0% +100.0% 🟢 ±0.0%
g.u.FpKit +0.1% 🟢 +0.7% 🟢 +0.2% 🟢
g.u.SelectionSetTraversalFrame +100.0% 🟢 +100.0% 🟢 +100.0% 🟢
g.v.LanguageTraversal removed removed removed
g.v.OperationValidationFrame +97.3% 🟢 +90.0% 🟢 +100.0% 🟢
g.v.OperationValidator +0.2% 🟢 +0.1% 🟢 ±0.0%
g.v.OperationValidator
$1
removed removed removed
g.v.Validator +4.3% 🟢 ±0.0% +11.1% 🟢

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-09 22:32:46 UTC

@andimarek andimarek changed the title Simplify circular default value validation Validate circular defaults before coercion Nov 8, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant