Skip to content

Commit ac6fbf9

Browse files
committed
ExecutionStrategyParameters now has a direct transform without a Builder
1 parent 73984b9 commit ac6fbf9

5 files changed

Lines changed: 45 additions & 27 deletions

File tree

‎src/main/java/graphql/execution/AsyncSerialExecutionStrategy.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
5252
CompletableFuture<List<Object>> resultsFuture = Async.eachSequentially(fieldNames, (fieldName, prevResults) -> {
5353
MergedField currentField = fields.getSubField(fieldName);
5454
ResultPath fieldPath = parameters.getPath().segment(mkNameForPath(currentField));
55-
ExecutionStrategyParameters newParameters = parameters
56-
.transform(builder -> builder.field(currentField).path(fieldPath));
55+
ExecutionStrategyParameters newParameters = parameters.transform(currentField, fieldPath);
5756

58-
Object resolveSerialField = resolveSerialField(executionContext, dataLoaderDispatcherStrategy, newParameters);
59-
return resolveSerialField;
57+
return resolveSerialField(executionContext, dataLoaderDispatcherStrategy, newParameters);
6058
});
6159

6260
CompletableFuture<ExecutionResult> overallResult = new CompletableFuture<>();

‎src/main/java/graphql/execution/ExecutionStrategy.java‎

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ DeferredExecutionSupport createDeferredExecutionSupport(ExecutionContext executi
329329
MergedField currentField = fields.getSubField(fieldName);
330330

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

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

628627
NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, executionStepInfo);
629628

630-
ExecutionStrategyParameters newParameters = parameters.transform(builder ->
631-
builder.executionStepInfo(executionStepInfo)
632-
.source(fetchedValue.getFetchedValue())
633-
.localContext(fetchedValue.getLocalContext())
634-
.nonNullFieldValidator(nonNullableFieldValidator)
635-
);
629+
ExecutionStrategyParameters newParameters = parameters.transform(executionStepInfo,
630+
nonNullableFieldValidator,
631+
fetchedValue.getLocalContext(),
632+
fetchedValue.getFetchedValue());
636633

637634
FieldValueInfo fieldValueInfo = completeValue(executionContext, newParameters);
638635

@@ -790,13 +787,10 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,
790787

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

793-
ExecutionStrategyParameters newParameters = parameters.transform(builder ->
794-
builder.executionStepInfo(stepInfoForListElement)
795-
.nonNullFieldValidator(nonNullableFieldValidator)
796-
.localContext(value.getLocalContext())
797-
.path(indexedPath)
798-
.source(value.getFetchedValue())
799-
);
790+
ExecutionStrategyParameters newParameters = parameters.transform(stepInfoForListElement,
791+
nonNullableFieldValidator, indexedPath,
792+
value.getLocalContext(), value.getFetchedValue());
793+
800794
fieldValueInfos.add(completeValue(executionContext, newParameters));
801795
index++;
802796
}
@@ -936,12 +930,10 @@ protected Object completeValueForObject(ExecutionContext executionContext, Execu
936930
ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull(resolvedObjectType);
937931
NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, newExecutionStepInfo);
938932

939-
ExecutionStrategyParameters newParameters = parameters.transform(builder ->
940-
builder.executionStepInfo(newExecutionStepInfo)
941-
.fields(subFields)
942-
.nonNullFieldValidator(nonNullableFieldValidator)
943-
.source(result)
944-
);
933+
ExecutionStrategyParameters newParameters = parameters.transform(newExecutionStepInfo,
934+
nonNullableFieldValidator,
935+
subFields,
936+
result);
945937

946938
// Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy.
947939
return executionContext.getQueryStrategy().executeObject(executionContext, newParameters);

‎src/main/java/graphql/execution/ExecutionStrategyParameters.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package graphql.execution;
22

3+
import graphql.Internal;
34
import graphql.PublicApi;
45
import graphql.execution.incremental.DeferredCallContext;
56
import org.jspecify.annotations.Nullable;
@@ -115,6 +116,31 @@ public MergedField getField() {
115116
return currentField;
116117
}
117118

119+
@Internal
120+
ExecutionStrategyParameters transform(MergedField currentField, ResultPath path) {
121+
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, parent, deferredCallContext);
122+
}
123+
124+
@Internal
125+
ExecutionStrategyParameters transform(ExecutionStepInfo executionStepInfo, NonNullableFieldValidator nonNullableFieldValidator, MergedSelectionSet fields, Object source) {
126+
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, parent, deferredCallContext);
127+
}
128+
129+
@Internal
130+
ExecutionStrategyParameters transform(ExecutionStepInfo executionStepInfo, NonNullableFieldValidator nonNullableFieldValidator, ResultPath path, Object localContext, Object source) {
131+
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, parent, deferredCallContext);
132+
}
133+
134+
@Internal
135+
ExecutionStrategyParameters transform(ExecutionStepInfo executionStepInfo, NonNullableFieldValidator nonNullableFieldValidator, Object localContext, Object source) {
136+
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, parent, deferredCallContext);
137+
}
138+
139+
@Internal
140+
ExecutionStrategyParameters transform(MergedField currentField, ResultPath path, ExecutionStrategyParameters parent) {
141+
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, parent, deferredCallContext);
142+
}
143+
118144
public ExecutionStrategyParameters transform(Consumer<Builder> builderConsumer) {
119145
Builder builder = newParameters(this);
120146
builderConsumer.accept(builder);

‎src/main/java/graphql/execution/SubscriptionExecutionStrategy.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private ExecutionStrategyParameters firstFieldOfSubscriptionSelection(ExecutionS
184184
MergedField firstField = fields.getSubField(fields.getKeys().get(0));
185185

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

190190
private ExecutionStepInfo createSubscribedFieldStepInfo(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {

‎src/main/java/graphql/execution/incremental/DeferredExecutionSupport.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import graphql.execution.FieldValueInfo;
1212
import graphql.execution.MergedField;
1313
import graphql.execution.MergedSelectionSet;
14+
import graphql.execution.ResultPath;
1415
import graphql.execution.instrumentation.Instrumentation;
1516
import graphql.incremental.IncrementalPayload;
1617
import graphql.util.FpKit;
@@ -139,10 +140,11 @@ private Supplier<CompletableFuture<DeferredFragmentCall.FieldWithExecutionResult
139140
ExecutionStrategyParameters callParameters = parameters.transform(builder ->
140141
{
141142
MergedSelectionSet mergedSelectionSet = MergedSelectionSet.newMergedSelectionSet().subFields(fields).build();
143+
ResultPath path = parameters.getPath().segment(currentField.getResultKey());
142144
builder.deferredCallContext(deferredCallContext)
143145
.field(currentField)
144146
.fields(mergedSelectionSet)
145-
.path(parameters.getPath().segment(currentField.getResultKey()))
147+
.path(path)
146148
.parent(null); // this is a break in the parent -> child chain - it's a new start effectively
147149
}
148150
);

0 commit comments

Comments
 (0)