Skip to content

Commit 3fc8444

Browse files
Small adjustments after pairing with Andi
1 parent d63702a commit 3fc8444

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/main/java/graphql/execution/instrumentation/dataloader/PerLevelDataLoaderDispatchStrategyWithDeferAlwaysDispatch.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public class PerLevelDataLoaderDispatchStrategyWithDeferAlwaysDispatch implement
3131
private final ExecutionContext executionContext;
3232

3333
/**
34-
* This flag is used to determine if we are in a deferred context or not.
34+
* This flag is used to determine if we have started the deferred execution.
3535
* The value of this flag is set to true as soon as we identified that a deferred field is being executed, and then
3636
* the flag stays on that state for the remainder of the execution.
3737
*/
38-
private final AtomicBoolean enteredDeferredContext = new AtomicBoolean(false);
38+
private final AtomicBoolean startedDeferredExecution = new AtomicBoolean(false);
3939

4040

4141
private static class CallStack {
@@ -115,12 +115,12 @@ public PerLevelDataLoaderDispatchStrategyWithDeferAlwaysDispatch(ExecutionContex
115115

116116
@Override
117117
public void executeDeferredOnFieldValueInfo(FieldValueInfo fieldValueInfo, ExecutionStrategyParameters executionStrategyParameters) {
118-
this.enteredDeferredContext.set(true);
118+
this.startedDeferredExecution.set(true);
119119
}
120120

121121
@Override
122122
public void executionStrategy(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
123-
if (this.enteredDeferredContext.get()) {
123+
if (this.startedDeferredExecution.get()) {
124124
return;
125125
}
126126
int curLevel = parameters.getExecutionStepInfo().getPath().getLevel() + 1;
@@ -129,7 +129,7 @@ public void executionStrategy(ExecutionContext executionContext, ExecutionStrate
129129

130130
@Override
131131
public void executeObject(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
132-
if (this.enteredDeferredContext.get()) {
132+
if (this.startedDeferredExecution.get()) {
133133
return;
134134
}
135135
int curLevel = parameters.getExecutionStepInfo().getPath().getLevel() + 1;
@@ -138,7 +138,7 @@ public void executeObject(ExecutionContext executionContext, ExecutionStrategyPa
138138

139139
@Override
140140
public void executionStrategyOnFieldValuesInfo(List<FieldValueInfo> fieldValueInfoList, ExecutionStrategyParameters parameters) {
141-
if (this.enteredDeferredContext.get()) {
141+
if (this.startedDeferredExecution.get()) {
142142
this.dispatch();
143143
}
144144
int curLevel = parameters.getPath().getLevel() + 1;
@@ -155,7 +155,7 @@ public void executionStrategyOnFieldValuesException(Throwable t, ExecutionStrate
155155

156156
@Override
157157
public void executeObjectOnFieldValuesInfo(List<FieldValueInfo> fieldValueInfoList, ExecutionStrategyParameters parameters) {
158-
if (this.enteredDeferredContext.get()) {
158+
if (this.startedDeferredExecution.get()) {
159159
this.dispatch();
160160
}
161161
int curLevel = parameters.getPath().getLevel() + 1;
@@ -179,8 +179,8 @@ public void fieldFetched(ExecutionContext executionContext,
179179

180180
final boolean dispatchNeeded;
181181

182-
if (parameters.getField().isDeferred() || this.enteredDeferredContext.get()) {
183-
this.enteredDeferredContext.compareAndSet(false, true);
182+
if (parameters.getField().isDeferred() || this.startedDeferredExecution.get()) {
183+
this.startedDeferredExecution.set(true);
184184
dispatchNeeded = true;
185185
} else {
186186
int level = parameters.getPath().getLevel();

src/test/groovy/graphql/execution/instrumentation/dataloader/DataLoaderPerformanceData.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,14 @@ class DataLoaderPerformanceData {
249249
.collect { it.toSpecification() }
250250
}
251251

252-
252+
/**
253+
* Combines the initial result with the incremental results into a single result that has the same shape as a
254+
* "normal" execution result.
255+
*
256+
* @param initialResult the data from the initial execution
257+
* @param incrementalResults the data from the incremental executions
258+
* @return a single result that combines the initial and incremental results
259+
*/
253260
static Map<String, Object> combineExecutionResults(Map<String, Object> initialResult, List<Map<String, Object>> incrementalResults) {
254261
Map<String, Object> combinedResult = deepClone(initialResult, Map.class)
255262

@@ -275,6 +282,7 @@ class DataLoaderPerformanceData {
275282
}
276283
}
277284

285+
// Remove the "hasNext" to make the result look like a normal execution result
278286
combinedResult.remove("hasNext")
279287

280288
combinedResult

src/test/groovy/graphql/execution/instrumentation/dataloader/DeferWithDataLoaderTest.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ class DeferWithDataLoaderTest extends Specification {
190190

191191
ExecutionResult result = graphQL.execute(executionInput)
192192

193-
println "dept for shops dl: " + batchCompareDataFetchers.departmentsForShopsBatchLoaderCounter.get()
194-
println "prod for depts dl: " + batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get()
195-
196193
then:
197194
result.toSpecification() == expectedInitialData
198195

0 commit comments

Comments
 (0)