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
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
CompletableFuture<List<Object>> resultsFuture = Async.eachSequentially(fieldNames, (fieldName, prevResults) -> {
MergedField currentField = fields.getSubField(fieldName);
ResultPath fieldPath = parameters.getPath().segment(mkNameForPath(currentField));
ExecutionStrategyParameters newParameters = parameters
.transform(builder -> builder.field(currentField).path(fieldPath));
ExecutionStrategyParameters newParameters = parameters.transform(currentField, fieldPath);

Object resolveSerialField = resolveSerialField(executionContext, dataLoaderDispatcherStrategy, newParameters);
return resolveSerialField;
return resolveSerialField(executionContext, dataLoaderDispatcherStrategy, newParameters);
});

CompletableFuture<ExecutionResult> overallResult = new CompletableFuture<>();
Expand Down
34 changes: 13 additions & 21 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ DeferredExecutionSupport createDeferredExecutionSupport(ExecutionContext executi
MergedField currentField = fields.getSubField(fieldName);

ResultPath fieldPath = parameters.getPath().segment(mkNameForPath(currentField));
ExecutionStrategyParameters newParameters = parameters
.transform(builder -> builder.field(currentField).path(fieldPath).parent(parameters));
ExecutionStrategyParameters newParameters = parameters.transform(currentField, fieldPath, parameters);

if (!deferredExecutionSupport.isDeferredField(currentField)) {
Object fieldValueInfo = resolveFieldWithInfo(executionContext, newParameters);
Expand Down Expand Up @@ -627,12 +626,10 @@ private FieldValueInfo completeField(GraphQLFieldDefinition fieldDef, ExecutionC

NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, executionStepInfo);

ExecutionStrategyParameters newParameters = parameters.transform(builder ->
builder.executionStepInfo(executionStepInfo)
.source(fetchedValue.getFetchedValue())
.localContext(fetchedValue.getLocalContext())
.nonNullFieldValidator(nonNullableFieldValidator)
);
ExecutionStrategyParameters newParameters = parameters.transform(executionStepInfo,
nonNullableFieldValidator,
fetchedValue.getLocalContext(),
fetchedValue.getFetchedValue());

FieldValueInfo fieldValueInfo = completeValue(executionContext, newParameters);
ctxCompleteField.onDispatched();
Expand Down Expand Up @@ -793,13 +790,10 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,

FetchedValue value = unboxPossibleDataFetcherResult(executionContext, parameters, item);

ExecutionStrategyParameters newParameters = parameters.transform(builder ->
builder.executionStepInfo(stepInfoForListElement)
.nonNullFieldValidator(nonNullableFieldValidator)
.localContext(value.getLocalContext())
.path(indexedPath)
.source(value.getFetchedValue())
);
ExecutionStrategyParameters newParameters = parameters.transform(stepInfoForListElement,
nonNullableFieldValidator, indexedPath,
value.getLocalContext(), value.getFetchedValue());

fieldValueInfos.add(completeValue(executionContext, newParameters));
index++;
}
Expand Down Expand Up @@ -939,12 +933,10 @@ protected Object completeValueForObject(ExecutionContext executionContext, Execu
ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull(resolvedObjectType);
NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, newExecutionStepInfo);

ExecutionStrategyParameters newParameters = parameters.transform(builder ->
builder.executionStepInfo(newExecutionStepInfo)
.fields(subFields)
.nonNullFieldValidator(nonNullableFieldValidator)
.source(result)
);
ExecutionStrategyParameters newParameters = parameters.transform(newExecutionStepInfo,
nonNullableFieldValidator,
subFields,
result);

// Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy.
return executionContext.getQueryStrategy().executeObject(executionContext, newParameters);
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/graphql/execution/ExecutionStrategyParameters.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.execution;

import graphql.Internal;
import graphql.PublicApi;
import graphql.execution.incremental.DeferredCallContext;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -115,6 +116,84 @@ public MergedField getField() {
return currentField;
}

@Internal
ExecutionStrategyParameters transform(MergedField currentField,
ResultPath path) {
return new ExecutionStrategyParameters(executionStepInfo,
source,
localContext,
fields,
nonNullableFieldValidator,
path,
currentField,
parent,
deferredCallContext);
}

@Internal
ExecutionStrategyParameters transform(ExecutionStepInfo executionStepInfo,
NonNullableFieldValidator nonNullableFieldValidator,
MergedSelectionSet fields,
Object source) {
return new ExecutionStrategyParameters(executionStepInfo,
source,
localContext,
fields,
nonNullableFieldValidator,
path,
currentField,
parent,
deferredCallContext);
}

@Internal
ExecutionStrategyParameters transform(ExecutionStepInfo executionStepInfo,
NonNullableFieldValidator nonNullableFieldValidator,
ResultPath path,
Object localContext,
Object source) {
return new ExecutionStrategyParameters(executionStepInfo,
source,
localContext,
fields,
nonNullableFieldValidator,
path,
currentField,
parent,
deferredCallContext);
}

@Internal
ExecutionStrategyParameters transform(ExecutionStepInfo executionStepInfo,
NonNullableFieldValidator nonNullableFieldValidator,
Object localContext,
Object source) {
return new ExecutionStrategyParameters(executionStepInfo,
source,
localContext,
fields,
nonNullableFieldValidator,
path,
currentField,
parent,
deferredCallContext);
}

@Internal
ExecutionStrategyParameters transform(MergedField currentField,
ResultPath path,
ExecutionStrategyParameters parent) {
return new ExecutionStrategyParameters(executionStepInfo,
source,
localContext,
fields,
nonNullableFieldValidator,
path,
currentField,
parent,
deferredCallContext);
}

public ExecutionStrategyParameters transform(Consumer<Builder> builderConsumer) {
Builder builder = newParameters(this);
builderConsumer.accept(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private ExecutionStrategyParameters firstFieldOfSubscriptionSelection(ExecutionS
MergedField firstField = fields.getSubField(fields.getKeys().get(0));

ResultPath fieldPath = parameters.getPath().segment(mkNameForPath(firstField.getSingleField()));
return parameters.transform(builder -> builder.field(firstField).path(fieldPath));
return parameters.transform(firstField,fieldPath);
}

private ExecutionStepInfo createSubscribedFieldStepInfo(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import graphql.execution.FieldValueInfo;
import graphql.execution.MergedField;
import graphql.execution.MergedSelectionSet;
import graphql.execution.ResultPath;
import graphql.execution.instrumentation.Instrumentation;
import graphql.incremental.IncrementalPayload;
import graphql.util.FpKit;
Expand Down Expand Up @@ -139,10 +140,11 @@ private Supplier<CompletableFuture<DeferredFragmentCall.FieldWithExecutionResult
ExecutionStrategyParameters callParameters = parameters.transform(builder ->
{
MergedSelectionSet mergedSelectionSet = MergedSelectionSet.newMergedSelectionSet().subFields(fields).build();
ResultPath path = parameters.getPath().segment(currentField.getResultKey());
builder.deferredCallContext(deferredCallContext)
.field(currentField)
.fields(mergedSelectionSet)
.path(parameters.getPath().segment(currentField.getResultKey()))
.path(path)
.parent(null); // this is a break in the parent -> child chain - it's a new start effectively
}
);
Expand Down
Loading