Skip to content

Commit

Permalink
Merge pull request graphql-java#1961 from graphql-java/remove-deferre…
Browse files Browse the repository at this point in the history
…d-support

remove deferred support
  • Loading branch information
andimarek committed Jun 22, 2020
2 parents 10eeacc + dad2e95 commit 3101f48
Show file tree
Hide file tree
Showing 16 changed files with 6 additions and 1,178 deletions.
43 changes: 1 addition & 42 deletions src/main/java/graphql/execution/AsyncExecutionStrategy.java
@@ -1,9 +1,6 @@
package graphql.execution;

import graphql.ExecutionResult;
import graphql.execution.defer.DeferSupport;
import graphql.execution.defer.DeferredCall;
import graphql.execution.defer.DeferredErrorSupport;
import graphql.execution.instrumentation.DeferredFieldInstrumentationContext;
import graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext;
import graphql.execution.instrumentation.Instrumentation;
Expand All @@ -13,16 +10,12 @@
import graphql.schema.GraphQLObjectType;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static graphql.execution.MergedSelectionSet.newMergedSelectionSet;

/**
* The standard graphql execution strategy that runs fields asynchronously non-blocking.
*/
Expand Down Expand Up @@ -65,14 +58,7 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
.transform(builder -> builder.field(currentField).path(fieldPath).parent(parameters));

resolvedFields.add(fieldName);
CompletableFuture<FieldValueInfo> future;

if (isDeferred(executionContext, newParameters, currentField)) {
executionStrategyCtx.onDeferredField(currentField);
future = resolveFieldWithInfoToNull(executionContext, newParameters);
} else {
future = resolveFieldWithInfo(executionContext, newParameters);
}
CompletableFuture<FieldValueInfo> future = resolveFieldWithInfo(executionContext, newParameters);
futures.add(future);
}
CompletableFuture<ExecutionResult> overallResult = new CompletableFuture<>();
Expand All @@ -99,33 +85,6 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
return overallResult;
}

private boolean isDeferred(ExecutionContext executionContext, ExecutionStrategyParameters parameters, MergedField currentField) {
DeferSupport deferSupport = executionContext.getDeferSupport();
if (deferSupport.checkForDeferDirective(currentField, executionContext.getVariables())) {
DeferredErrorSupport errorSupport = new DeferredErrorSupport();

// with a deferred field we are really resetting where we execute from, that is from this current field onwards
Map<String, MergedField> fields = new LinkedHashMap<>();
fields.put(currentField.getName(), currentField);

ExecutionStrategyParameters callParameters = parameters.transform(builder ->
{
MergedSelectionSet mergedSelectionSet = newMergedSelectionSet().subFields(fields).build();
builder.deferredErrorSupport(errorSupport)
.field(currentField)
.fields(mergedSelectionSet)
.parent(null) // this is a break in the parent -> child chain - its a new start effectively
.listSize(0)
.currentListIndex(0);
}
);

DeferredCall call = new DeferredCall(parameters.getPath(), deferredExecutionResult(executionContext, callParameters), errorSupport);
deferSupport.enqueue(call);
return true;
}
return false;
}

@SuppressWarnings("FutureReturnValueIgnored")
private Supplier<CompletableFuture<ExecutionResult>> deferredExecutionResult(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
Expand Down
24 changes: 1 addition & 23 deletions src/main/java/graphql/execution/Execution.java
@@ -1,14 +1,11 @@
package graphql.execution;


import graphql.DeferredExecutionResult;
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.GraphQL;
import graphql.GraphQLError;
import graphql.Internal;
import graphql.execution.defer.DeferSupport;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.InstrumentationContext;
import graphql.execution.instrumentation.InstrumentationState;
Expand All @@ -22,7 +19,6 @@
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.util.LogKit;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;

import java.util.Collections;
Expand Down Expand Up @@ -183,27 +179,9 @@ private CompletableFuture<ExecutionResult> executeOperation(ExecutionContext exe

result = result.whenComplete(executeOperationCtx::onCompleted);

return deferSupport(executionContext, result);
return result;
}

/*
* Adds the deferred publisher if its needed at the end of the query. This is also a good time for the deferred code to start running
*/
private CompletableFuture<ExecutionResult> deferSupport(ExecutionContext executionContext, CompletableFuture<ExecutionResult> result) {
return result.thenApply(er -> {
DeferSupport deferSupport = executionContext.getDeferSupport();
if (deferSupport.isDeferDetected()) {
// we start the rest of the query now to maximize throughput. We have the initial important results
// and now we can start the rest of the calls as early as possible (even before some one subscribes)
Publisher<DeferredExecutionResult> publisher = deferSupport.startDeferredCalls();
return ExecutionResultImpl.newExecutionResult().from(er)
.addExtension(GraphQL.DEFERRED_RESULTS, publisher)
.build();
}
return er;
});

}

private GraphQLObjectType getOperationRootType(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition) {
OperationDefinition.Operation operation = operationDefinition.getOperation();
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/graphql/execution/ExecutionContext.java
Expand Up @@ -3,10 +3,8 @@

import graphql.ExecutionInput;
import graphql.GraphQLError;
import graphql.Internal;
import graphql.PublicApi;
import graphql.cachecontrol.CacheControl;
import graphql.execution.defer.DeferSupport;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.language.Document;
Expand Down Expand Up @@ -47,7 +45,6 @@ public class ExecutionContext {
private final DataLoaderRegistry dataLoaderRegistry;
private final CacheControl cacheControl;
private final Locale locale;
private final DeferSupport deferSupport = new DeferSupport();
private final ValueUnboxer valueUnboxer;
private final ExecutionInput executionInput;

Expand Down Expand Up @@ -198,10 +195,6 @@ public ExecutionStrategy getSubscriptionStrategy() {
return subscriptionStrategy;
}

public DeferSupport getDeferSupport() {
return deferSupport;
}

/**
* This helps you transform the current ExecutionContext object into another one by starting a builder with all
* the current values and allows you to transform it how you want.
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Expand Up @@ -345,7 +345,6 @@ private void handleFetchingException(ExecutionContext executionContext,
DataFetcherExceptionHandlerResult handlerResult = dataFetcherExceptionHandler.onException(handlerParameters);
handlerResult.getErrors().forEach(executionContext::addError);

parameters.deferredErrorSupport().onFetchingException(parameters, e);
}

/**
Expand Down Expand Up @@ -461,7 +460,6 @@ private void handleUnresolvedTypeProblem(ExecutionContext context, ExecutionStra
logNotSafe.warn(error.getMessage(), e);
context.addError(error);

parameters.deferredErrorSupport().onError(error);
}

private CompletableFuture<ExecutionResult> completeValueForNull(ExecutionStrategyParameters parameters) {
Expand Down Expand Up @@ -669,7 +667,6 @@ private Object handleCoercionProblem(ExecutionContext context, ExecutionStrategy
logNotSafe.warn(error.getMessage(), e);
context.addError(error);

parameters.deferredErrorSupport().onError(error);

return null;
}
Expand Down Expand Up @@ -708,7 +705,6 @@ private void handleTypeMismatchProblem(ExecutionContext context, ExecutionStrate
logNotSafe.warn("{} got {}", error.getMessage(), result.getClass());
context.addError(error);

parameters.deferredErrorSupport().onError(error);
}


Expand Down
18 changes: 2 additions & 16 deletions src/main/java/graphql/execution/ExecutionStrategyParameters.java
Expand Up @@ -2,7 +2,6 @@

import graphql.Assert;
import graphql.PublicApi;
import graphql.execution.defer.DeferredErrorSupport;

import java.util.Map;
import java.util.function.Consumer;
Expand All @@ -25,7 +24,6 @@ public class ExecutionStrategyParameters {
private final int listSize;
private final int currentListIndex;
private final ExecutionStrategyParameters parent;
private final DeferredErrorSupport deferredErrorSupport;

private ExecutionStrategyParameters(ExecutionStepInfo executionStepInfo,
Object source,
Expand All @@ -37,8 +35,7 @@ private ExecutionStrategyParameters(ExecutionStepInfo executionStepInfo,
MergedField currentField,
int listSize,
int currentListIndex,
ExecutionStrategyParameters parent,
DeferredErrorSupport deferredErrorSupport) {
ExecutionStrategyParameters parent) {

this.executionStepInfo = assertNotNull(executionStepInfo, () -> "executionStepInfo is null");
this.localContext = localContext;
Expand All @@ -51,7 +48,6 @@ private ExecutionStrategyParameters(ExecutionStepInfo executionStepInfo,
this.listSize = listSize;
this.currentListIndex = currentListIndex;
this.parent = parent;
this.deferredErrorSupport = deferredErrorSupport;
}

public ExecutionStepInfo getExecutionStepInfo() {
Expand Down Expand Up @@ -94,10 +90,6 @@ public ExecutionStrategyParameters getParent() {
return parent;
}

public DeferredErrorSupport deferredErrorSupport() {
return deferredErrorSupport;
}

/**
* This returns the current field in its query representations.
*
Expand Down Expand Up @@ -139,7 +131,6 @@ public static class Builder {
int listSize;
int currentListIndex;
ExecutionStrategyParameters parent;
DeferredErrorSupport deferredErrorSupport = new DeferredErrorSupport();

/**
* @see ExecutionStrategyParameters#newParameters()
Expand All @@ -158,7 +149,6 @@ private Builder(ExecutionStrategyParameters oldParameters) {
this.arguments = oldParameters.arguments;
this.nonNullableFieldValidator = oldParameters.nonNullableFieldValidator;
this.currentField = oldParameters.currentField;
this.deferredErrorSupport = oldParameters.deferredErrorSupport;
this.path = oldParameters.path;
this.parent = oldParameters.parent;
this.listSize = oldParameters.listSize;
Expand Down Expand Up @@ -225,13 +215,9 @@ public Builder parent(ExecutionStrategyParameters parent) {
return this;
}

public Builder deferredErrorSupport(DeferredErrorSupport deferredErrorSupport) {
this.deferredErrorSupport = deferredErrorSupport;
return this;
}

public ExecutionStrategyParameters build() {
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, arguments, nonNullableFieldValidator, path, currentField, listSize, currentListIndex, parent, deferredErrorSupport);
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, arguments, nonNullableFieldValidator, path, currentField, listSize, currentListIndex, parent);
}
}
}
82 changes: 0 additions & 82 deletions src/main/java/graphql/execution/defer/DeferSupport.java

This file was deleted.

43 changes: 0 additions & 43 deletions src/main/java/graphql/execution/defer/DeferredCall.java

This file was deleted.

0 comments on commit 3101f48

Please sign in to comment.