← Back to Pull requests

fix: give every execution its own custom scalar literal values #324

Open
unknown opened this pull request with 364 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 19, 2026 11:04 UTC
Author

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 parseLiteral returns 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:

{
  nextDay(date: "2024-01-01")
}

nextDay(_, { date }) {
  date.setUTCDate(date.getUTCDate() + 1);
  return date;
}

GraphQL-JS returns 2024-01-02 every time, while graphql-jit returns 2024-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, valueFromAST parses it a second time and returns a ScalarLiteral holding 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 calling parseLiteral. Anything else, such as a class instance, is parsed again for every execution; if that fails, the field gets the same Argument "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.

Diff: 364 lines (+273 / -91) across 4 files Reviewer: mcollina Review duration: 1971m
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
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.7% (MEDIUM) · Higher = larger blast radius
42.7%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 22.8% · Safe to merge
22.8%