fix: give every execution its own custom scalar literal values #324
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 364 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.353
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #324"
general
weight: 0.35
mcollina
Since #302, a custom scalar literal is parsed once, when the query is compiled, and the parsed value is shared by every execution of the compiled query. When
parseLiteralreturns an object, a resolver that mutates its argument changes it for every later execution, including the executions of other requests that send the same query:GraphQL-JS returns
2024-01-02every time, while graphql-jit returns2024-01-02,2024-01-03,2024-01-04. The same happens with a JSON scalar whose resolver adds a field to its argument. graphql-jit 0.8 rebuilt plain objects, arrays and dates for every execution, so this is also a change for users upgrading from 0.8. GraphQL-JS.md documents it, but resolvers written for GraphQL-JS can reasonably mutate their arguments, and the effect crosses requests.This PR gives every execution its own value again, like GraphQL-JS, and avoids parsing at run time where it can. When a literal parses to an object,
valueFromASTparses it a second time and returns aScalarLiteralholding both results. Objects that parsing returned both times are shared, as GraphQL-JS shares them too. Dates, arrays and plain objects that it created anew are emitted as source that rebuilds them, as 0.8 did, so each execution gets a copy without callingparseLiteral. Anything else, such as a class instance, is parsed again for every execution; if that fails, the field gets the sameArgument "x" of type "T" has invalid value ...error as at compile time and its resolver is skipped. Default literals of variable definitions work the same way, with a variable error if coercing them again fails. Literals that parse to strings, numbers or booleans are still inlined and parsed once, and defaults from the schema are still shared. The new tests check that resolvers receive as many distinct values as with GraphQL-JS for each kind of literal and default, which values are copied, shared or parsed again, and the errors.Copying a Date for each of the 100 items costs throughput in the two benchmarks that use custom scalar literals, compared with sharing one Date (ops/sec,
BENCHMARK_FILTER='^argument' yarn benchmark skip-json, Node 24):| Benchmark | GraphQL-JS | main | this PR |
| --- | --- | --- | --- |
| argumentBuiltInLiterals | 23,099 | 108,466 | 105,790 |
| argumentCustomScalarLiteral | 26,141 | 115,994 | 93,721 |
| argumentCustomScalarInInput | 10,754 | 85,861 | 56,344 |
| argumentVariableInput | 29,683 | 84,519 | 80,610 |
This is the cost graphql-jit 0.8 had: running the same two queries with graphql 17, 0.8.10 and this PR are within 3% of each other (146k vs 143k and 97k vs 96k ops/sec). If sharing should stay available for schemas whose resolvers never mutate their arguments, I can add a compiler option to opt into it.