Skip to content

Conversation

@llin2
Copy link
Contributor

@llin2 llin2 commented Nov 16, 2025

This is to optimise defer execution for incremental results to begin processing as soon as the first incremental call is detected rather than on completion of the initial result.

initialResult.incrementalItemPublisher.subscribe(sub)

then:
Awaitility.await().untilTrue(sub.isDone())
Copy link
Member

Choose a reason for hiding this comment

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

Needs an assert on the contents of the Publisher

&& deferredExecutionSupport.deferredFieldsCount() > 0
&& executionContext.getGraphQLContext().getBoolean(IncrementalExecutionContextKeys.ENABLE_EAGER_DEFER_START, false)) {

executionContext.getIncrementalCallState().startDeferredCalls();
Copy link
Member

Choose a reason for hiding this comment

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

This call here is only need as a side effect to create the memoizing supplier (of the Publisher)

I think we should invent a new method that does that and hides the side effect

executionContext.getIncrementalCallState().startEarlyDraining();

Copy link
Member

Choose a reason for hiding this comment

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

Hang on you have that - startDrainingNow() and it calls publisher.get()

I dont think executionContext.getIncrementalCallState().startDeferredCalls(); is needed


}


Copy link
Member

Choose a reason for hiding this comment

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

We need to create a new entry in the unusual config - lets put it in

graphql.GraphQLUnusualConfiguration.IncrementalSupportConfig

        /**
         * This controls whether @defer field execution starts as early as possible.
         */
        @ExperimentalApi
        public IncrementalSupportConfig enableEarlyFieldExecution(boolean enable) {
            contextConfig.put(YOUR_KEY_HERE, enable);
            return this;
        }

}

public void startDrainingNow() {
startDeferredCalls();
Copy link
Member

Choose a reason for hiding this comment

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

no need to call start Deferred calls as it just creates the publisher

@andimarek andimarek merged commit aa0b31e into graphql-java:master Nov 30, 2025
4 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.

3 participants