Skip to content

Deliver parent @defer payloads before nested child @defer payloads - #4568

Merged
bbakerman merged 2 commits into
graphql-java:masterfrom
sahuadarsh0:fix/4567-nested-defer-order
Nov 25, 2026
Merged

bbakerman merged 2 commits into
graphql-java:masterfrom
sahuadarsh0:fix/4567-nested-defer-order

Conversation

@sahuadarsh0

Copy link
Copy Markdown
Contributor

Fixes #4567

Root Cause

In ExecutionStrategy.getAsyncFieldValueInfo, nested @defer calls discovered while resolving a field inside an outer deferred fragment were enqueued into IncrementalCallState without tracking their parent fragment. When the nested @defer completed faster than a sibling field of its parent @defer, IncrementalCallState emitted the child payload before the parent payload (with both enableEarlyIncrementalFieldExecution enabled and disabled).

Changes

  • Expose AlternativeCallContext on DeferredFragmentCall.
  • Pass parameters.getAlternativeCallContext() when enqueuing deferred calls in ExecutionStrategy.getAsyncFieldValueInfo.
  • Track active parent contexts and parent-child call relationships in IncrementalCallState under publisherLock. If a child call completes while its parent has not yet been emitted, buffer its payload and flush ready descendants in parent-before-child order as soon as the parent is offered to the publisher (preserving exact hasNext calculation and keeping unrelated sibling defers unblocked).

Testing

  • Added integration tests in DeferExecutionSupportIntegrationTest covering 2-level and 3-level nested @defer ordering with faster inner resolvers under both ENABLE_EAGER_DEFER_START = false and true.
  • Added unit tests in IncrementalCallStateDeferTest verifying parent-before-child ordering, unblocked sibling delivery, and unregistered parent contexts (e.g., subscriptions).
  • Verified locally on Java 25 with:
    • ./gradlew test --tests "graphql.execution.incremental.*" --tests "graphql.execution.instrumentation.dataloader.DeferWithDataLoaderTest" (127 tests passed)
    • ./gradlew test --tests "graphql.execution.incremental.*" --tests "graphql.execution.AsyncExecutionStrategyTest" --tests "graphql.execution.SubscriptionExecutionStrategyTest" (80 tests passed)

@bbakerman bbakerman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6386 (+8 🟢) 6331 (+8 🟢) 0 (±0) 0 (±0) 55 (±0)
Java 21 6386 (+8 🟢) 6331 (+8 🟢) 0 (±0) 0 (±0) 55 (±0)
Java 25 6386 (+8 🟢) 6331 (+8 🟢) 0 (±0) 0 (±0) 55 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 19190 (+24 🟢) 19025 (+24 🟢) 0 (±0) 0 (±0) 165 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 26839 2695 90.9% ±0.0%
Branches 7703 1170 86.8% ±0.0%
Methods 7430 1090 87.2% ±0.0%

Changed Class Coverage (1 class)

Class Line Branch Method
g.e.i.DeferredFragmentCall +0.1% 🟢 ±0.0% +1.8% 🟢

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-25 09:31:22 UTC

@bbakerman
bbakerman merged commit c3ac876 into graphql-java:master Nov 25, 2026
9 checks passed
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.

Nested @defer fragment is delivered before the fragment that contains it

2 participants