GQLGW-5297-optimise-incremental-part-execution-for-defer-requests by llin2 · Pull Request #4174 · graphql-java/graphql-java · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/graphql/GraphQLUnusualConfiguration.java
10 changes: 10 additions & 0 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import graphql.execution.directives.QueryDirectives;
import graphql.execution.directives.QueryDirectivesImpl;
import graphql.execution.incremental.DeferredExecutionSupport;
import graphql.execution.incremental.IncrementalExecutionContextKeys;
import graphql.execution.instrumentation.ExecuteObjectInstrumentationContext;
import graphql.execution.instrumentation.FieldFetchingInstrumentationContext;
import graphql.execution.instrumentation.Instrumentation;
Expand Down Expand Up @@ -325,7 +326,16 @@ DeferredExecutionSupport createDeferredExecutionSupport(ExecutionContext executi
Object fieldValueInfo = resolveFieldWithInfo(executionContext, newParameters);
futures.addObject(fieldValueInfo);
}

}

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

executionContext.getIncrementalCallState().startDrainingNow();
}

return futures;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ public Publisher<DelayedIncrementalPartialResult> startDeferredCalls() {
return publisher.get();
}

public void startDrainingNow() {
drainIncrementalCalls();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package graphql.execution.incremental;


import graphql.Internal;
import org.jspecify.annotations.NullMarked;

/**
* GraphQLContext keys for controlling incremental execution behavior.
*/
@Internal
@NullMarked
public final class IncrementalExecutionContextKeys {
private IncrementalExecutionContextKeys() {
}

/**
* Enables eager start of @defer processing so defered work runs before the initial result is computed.
* Defaults to false.
* <p>
* Expects a boolean value.
*/
public static final String ENABLE_EAGER_DEFER_START = "__GJ_enable_eager_defer_start";

}


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.

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;
        }

Loading