Skip to content

Support variable batching - #4520

Open
andimarek wants to merge 5 commits into
masterfrom
codex/variable-batching
Open

andimarek wants to merge 5 commits into
masterfrom
codex/variable-batching

Conversation

@andimarek

@andimarek andimarek commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Adds variable batching to the existing ExecutionInput: execute the same selected operation once per variable map. This is execution-layer support for the variable batching proposal; it adds no HTTP or request batching behavior.

ExecutionInput input = ExecutionInput.newExecutionInput()
    .query("query($id: ID!) { product(id: $id) { name } }")
    .variables(List.of(Map.of("id", "a"), Map.of("id", "b")))
    .dataLoaderRegistry(registry)
    .build();
VariableBatchExecutionResult batch = (VariableBatchExecutionResult) graphQL.execute(input);
CompletableFuture<List<ExecutionResult>> results = batch.getResultsAsync();
  • variables(Map) becomes a singleton list. Empty lists execute once with empty variables; singletons retain ordinary execution. Larger lists execute once per complete map, including duplicates. getVariables() and getRawVariables() assert that there is at most one map; use getVariablesList() for batches.
  • A plain loop calls executeAsync for every entry, without waiting for earlier futures. There are no batch size/concurrency limits, scheduling, or backpressure. getResults() exposes the futures in input order; getResultsAsync() collects all results in that order. No threads are created by batching.
  • Entries share the supplied DataLoader registry and caches, including mutations, with ordinary automatic/manual dispatch behavior. Dispatch is not coordinated across entries. Mutation root fields remain serial within each entry; entries have no ordering guarantee. Writers must clear/prime affected cache entries.
  • Coercion, errors, instrumentation state, execution IDs, and context copies are separate per entry. Cancelling the input requests cancellation of every entry. Existing incremental results and their publishers pass through unchanged.
  • The default configuration parses and validates once. Custom instrumentation and preparsed providers retain their per-entry behavior, including persisted queries and document/variable transformations.
  • Multi-map subscriptions fail with IllegalArgumentException as soon as the selected operation is known, before coercion or resolvers. Literal, cached, persisted, and rewritten documents are covered. Empty/singleton lists still support subscriptions.

The new APIs are experimental. Serialize each individual ExecutionResult; the batch has no single GraphQL response map.

Validation: 158 focused tests pass across VariableBatchExecutionTest, ExecutionInputTest, GraphQLTest, and ParseAndValidateTest, including all 44 batching cases and the empty/singleton/multi-map accessor checks. Javadoc passes. The JMH benchmark compares batching with repeated executions sharing a registry.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 11 6108 (+51 🟢) 6052 (+51 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 17 6108 (+51 🟢) 6051 (+51 🟢) 0 (±0) 0 (±0) 57 (±0)
Java 21 6108 (+51 🟢) 6051 (+51 🟢) 0 (±0) 0 (±0) 57 (±0)
Java 25 6108 (+51 🟢) 6051 (+51 🟢) 0 (±0) 0 (±0) 57 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 24464 (+204 🟢) 24237 (+204 🟢) 0 (±0) 0 (±0) 227 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30301 3077 90.8% ±0.0%
Branches 8895 1507 85.5% +0.1% 🟢
Methods 8098 1185 87.2% +0.1% 🟢

Changed Class Coverage (6 classes)

Class Line Branch Method
g.e.Execution ±0.0% +2.9% 🟢 ±0.0%
g.e.i.p.InstrumentationExecutionParameters +6.3% 🟢 ±0.0% +12.5% 🟢
g.ExecutionInput ±0.0% +3.8% 🟢 ±0.0%
g.GraphQL +0.4% 🟢 +2.5% 🟢 +0.3% 🟢
g.GraphQL
$Builder
+10.5% 🟢 ±0.0% +16.7% 🟢
g.VariableBatchExecutionResultImpl +100.0% 🟢 ±0.0% +100.0% 🟢

Full HTML report: build artifact jacoco-html-report

Updated: 2026-10-31 23:35:10 UTC

@andimarek andimarek changed the title Support variable batching with shared DataLoaders Support variable batching Oct 31, 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