Skip to content

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

Open
sahuadarsh0 wants to merge 1 commit into
graphql-java:masterfrom
sahuadarsh0:fix/4567-nested-defer-order
Open

sahuadarsh0 wants to merge 1 commit into
graphql-java:masterfrom
sahuadarsh0:fix/4567-nested-defer-order

Conversation

@sahuadarsh0

Copy link
Copy Markdown

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)

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.

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

1 participant