@@ -18,6 +18,8 @@ import spock.lang.Unroll
1818import java.util.concurrent.CompletableFuture
1919
2020import static graphql.ExperimentalApi.ENABLE_INCREMENTAL_SUPPORT
21+ import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING
22+ import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING
2123import static graphql.execution.instrumentation.dataloader.DataLoaderPerformanceData.combineExecutionResults
2224import static graphql.execution.instrumentation.dataloader.DataLoaderPerformanceData.expectedData
2325import static graphql.execution.instrumentation.dataloader.DataLoaderPerformanceData.expectedExpensiveData
@@ -83,9 +85,7 @@ class DeferWithDataLoaderTest extends Specification {
8385 .dataLoaderRegistry(dataLoaderRegistry)
8486 .graphQLContext([(ENABLE_INCREMENTAL_SUPPORT ): true ])
8587 .build()
86- if (exhaustedStrategy) {
87- executionInput. getGraphQLContext(). put(DataLoaderDispatchingContextKeys . ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , true )
88- }
88+ executionInput. getGraphQLContext(). putAll(contextKey == null ? Collections . emptyMap() : [(contextKey): true ])
8989
9090 IncrementalExecutionResult result = graphQL. execute(executionInput)
9191
@@ -109,7 +109,7 @@ class DeferWithDataLoaderTest extends Specification {
109109 batchCompareDataFetchers. productsForDepartmentsBatchLoaderCounter. get() == 3
110110
111111 where :
112- exhaustedStrategy << [false , true ]
112+ contextKey << [ENABLE_DATA_LOADER_CHAINING , ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , null ]
113113 }
114114
115115 @Unroll
@@ -147,9 +147,7 @@ class DeferWithDataLoaderTest extends Specification {
147147 .dataLoaderRegistry(dataLoaderRegistry)
148148 .graphQLContext([(ENABLE_INCREMENTAL_SUPPORT ): true ])
149149 .build()
150- if (exhaustedStrategy) {
151- executionInput. getGraphQLContext(). put(DataLoaderDispatchingContextKeys . ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , true )
152- }
150+ executionInput. getGraphQLContext(). putAll(contextKey == null ? Collections . emptyMap() : [(contextKey): true ])
153151
154152 IncrementalExecutionResult result = graphQL. execute(executionInput)
155153
@@ -189,7 +187,7 @@ class DeferWithDataLoaderTest extends Specification {
189187 batchCompareDataFetchers. productsForDepartmentsBatchLoaderCounter. get() == 0
190188
191189 where :
192- exhaustedStrategy << [false , true ]
190+ contextKey << [ENABLE_DATA_LOADER_CHAINING , ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , null ]
193191
194192 }
195193
@@ -215,9 +213,7 @@ class DeferWithDataLoaderTest extends Specification {
215213 .dataLoaderRegistry(dataLoaderRegistry)
216214 .graphQLContext([(ENABLE_INCREMENTAL_SUPPORT ): true ])
217215 .build()
218- if (exhaustedStrategy) {
219- executionInput. getGraphQLContext(). put(DataLoaderDispatchingContextKeys . ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , true )
220- }
216+ executionInput. getGraphQLContext(). putAll(contextKey == null ? Collections . emptyMap() : [(contextKey): true ])
221217
222218
223219 ExecutionResult result = graphQL. execute(executionInput)
@@ -249,7 +245,7 @@ class DeferWithDataLoaderTest extends Specification {
249245 batchCompareDataFetchers. productsForDepartmentsBatchLoaderCounter. get() == 9
250246
251247 where :
252- exhaustedStrategy << [false , true ]
248+ contextKey << [ENABLE_DATA_LOADER_CHAINING , ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , null ]
253249
254250 }
255251
@@ -287,9 +283,7 @@ class DeferWithDataLoaderTest extends Specification {
287283 .dataLoaderRegistry(dataLoaderRegistry)
288284 .graphQLContext([(ENABLE_INCREMENTAL_SUPPORT ): true ])
289285 .build()
290- if (exhaustedStrategy) {
291- executionInput. getGraphQLContext(). put(DataLoaderDispatchingContextKeys . ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , true )
292- }
286+ executionInput. getGraphQLContext(). putAll(contextKey == null ? Collections . emptyMap() : [(contextKey): true ])
293287
294288
295289 IncrementalExecutionResult result = graphQL. execute(executionInput)
@@ -321,11 +315,12 @@ class DeferWithDataLoaderTest extends Specification {
321315 batchCompareDataFetchers. productsForDepartmentsBatchLoaderCounter. get() == 0
322316
323317 where :
324- exhaustedStrategy << [false , true ]
318+ contextKey << [ENABLE_DATA_LOADER_CHAINING , ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , null ]
325319
326320 }
327321
328322 @Unroll
323+ @RepeatUntilFailure (maxAttempts = 5 , ignoreRest = false )
329324 def " query with multiple deferred fields" () {
330325 given :
331326 def query = getExpensiveQuery(true )
@@ -351,6 +346,7 @@ class DeferWithDataLoaderTest extends Specification {
351346 .dataLoaderRegistry(dataLoaderRegistry)
352347 .graphQLContext([(ENABLE_INCREMENTAL_SUPPORT ): true ])
353348 .build()
349+ executionInput. getGraphQLContext(). putAll(contextKey == null ? Collections . emptyMap() : [(contextKey): true ])
354350
355351 IncrementalExecutionResult result = graphQL. execute(executionInput)
356352
@@ -378,12 +374,11 @@ class DeferWithDataLoaderTest extends Specification {
378374 combined. errors == null
379375 combined. data == expectedExpensiveData
380376
381- // TODO: Why the load counters are only 1?
382- batchCompareDataFetchers. departmentsForShopsBatchLoaderCounter. get() == 1
377+ batchCompareDataFetchers. departmentsForShopsBatchLoaderCounter. get() == (contextKey != ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING ? 1 : 2 )
383378 batchCompareDataFetchers. productsForDepartmentsBatchLoaderCounter. get() == 1
384379
385380 where :
386- exhaustedStrategy << [false , true ]
381+ contextKey << [ENABLE_DATA_LOADER_CHAINING , ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING , null ]
387382
388383 }
389384
0 commit comments