Skip to content

stop re-walking variable values in validateOneOfInputTypes - #4564

Open
nab-iha3 wants to merge 1 commit into
graphql-java:masterfrom
nab-iha3:oneof-variable-rewalk
Open

nab-iha3 wants to merge 1 commit into
graphql-java:masterfrom
nab-iha3:oneof-variable-rewalk

Conversation

@nab-iha3

Copy link
Copy Markdown
Contributor

input Filter { and: [Filter!] or: [Filter!] not: Filter eq: String }, Query.f(filter: Filter): Int, $f = {and: [{eq: "x"} x 100,000]} (~1.1 MB of variables), JDK 25:

query ($f: Filter) { a0: f(filter: $f) a1: f(filter: $f) ... }

aliases      before      after
      1       16 ms      13 ms
   1000     1615 ms      17 ms

{ items { f(filter: $f) } } over 10,000 items:  21.6 s before, 0.33 s after

getArgumentValues calls validateOneOfInputTypes for every argument of every field invocation, and for a variable reference it walks the whole coerced variable value: every input object field and, since #4494 (mine), every list element. variable values are already coerced and checked once per request in coerceVariableValues, so each field that references the variable repeats the full walk. the cost is variable size times field invocations, which makes it a request amplification any client that can send variables can trigger, and the schema does not need a @oneOf type, only a list or input object argument. coercion itself also ran the recursive walk at every nested input object, so a value nested 120 deep was walked once per ancestor (50,000 leaves: 122 ms before, 11 ms after).

validateOneOfInputTypes now returns for variable references, coerceVariableValues checks variable default values the way it already checked supplied ones, and external values are checked once after coercion instead of at every level. one visible change: an invalid default like query ($v: [OneOf] = [{a: null}]) is now rejected during variable coercion, the same as a supplied [{"a": null}], instead of as a field error. the getArgumentValues rows that fed hand-built invalid CoercedVariables (a state coercion no longer lets through) moved to a coerceVariableValues test with the same values and exceptions. the new default value test and the @Timeout(10) end to end test fail before the change.

@github-actions

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6370 (+1 🟢) 6315 (+1 🟢) 0 (±0) 0 (±0) 55 (±0)
Java 21 6370 (+1 🟢) 6315 (+1 🟢) 0 (±0) 0 (±0) 55 (±0)
Java 25 6370 (+1 🟢) 6315 (+1 🟢) 0 (±0) 0 (±0) 55 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 19142 (+3 🟢) 18977 (+3 🟢) 0 (±0) 0 (±0) 165 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 26788 2698 90.8% ±0.0%
Branches 7683 1170 86.8% ±0.0%
Methods 7415 1091 87.2% ±0.0%

Changed Class Coverage (2 classes)

Class Line Branch Method
g.e.ValuesResolverConversion +0.1% 🟢 ±0.0% +0.4% 🟢
g.e.ValuesResolverOneOfValidation +0.3% 🟢 +0.3% 🟢 ±0.0%

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-15 16:13:15 UTC

@xuorig

xuorig commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

I think this is similar / dup of #4542

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.

2 participants