Skip to content

Commit 610a527

Browse files
committed
add test to show that BatchedExecutionStrategy doesn't work
across different paths
1 parent 873bada commit 610a527

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

src/test/groovy/graphql/execution/batched/BatchedExecutionStrategyTest.groovy

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import graphql.ExceptionWhileDataFetching
88
import graphql.ExecutionResult
99
import graphql.GraphQL
1010
import graphql.Scalars
11+
import graphql.TestUtil
1112
import graphql.execution.AsyncExecutionStrategy
12-
import graphql.execution.NonNullableFieldWasNullError
1313
import graphql.execution.instrumentation.TestingInstrumentation
1414
import graphql.schema.DataFetcher
1515
import graphql.schema.GraphQLObjectType
1616
import graphql.schema.GraphQLSchema
17+
import graphql.schema.idl.RuntimeWiring
1718
import spock.lang.Specification
1819

1920
import java.util.concurrent.atomic.AtomicInteger
@@ -474,4 +475,69 @@ class BatchedExecutionStrategyTest extends Specification {
474475
result.getErrors()[0] instanceof ExceptionWhileDataFetching
475476
}
476477

478+
def "multi level batching with two different path"() {
479+
given:
480+
def foo1s = [[id: 'id1'], [id: 'id2']] as List
481+
def foo1DF = { env -> foo1s } as DataFetcher
482+
def foo2s = [[id: 'id3'], [id: 'id4']] as List
483+
def foo2DF = { env -> foo2s } as DataFetcher
484+
485+
486+
def subFooDF = { env ->
487+
def result = [[[batchThat: 'batchThat1-2'], [batchThat: 'batchThat1-2']], [[batchThat: 'batchThat2-1'], [batchThat: 'batchThat2-2']]]
488+
result
489+
} as BatchedDataFetcher
490+
491+
def expectedBatchThatCount = 0
492+
def batchThatDF = { env ->
493+
expectedBatchThatCount++
494+
env.getSource()
495+
} as BatchedDataFetcher
496+
497+
def runtimeWiring = RuntimeWiring.newRuntimeWiring()
498+
.type("Query",
499+
{ builder ->
500+
builder
501+
.dataFetcher("foo1", foo1DF)
502+
.dataFetcher("foo2", foo2DF)
503+
})
504+
.type("Foo",
505+
{ builder ->
506+
builder
507+
.dataFetcher("subFoo", subFooDF)
508+
})
509+
.type("SubFoo",
510+
{ builder ->
511+
builder
512+
.dataFetcher("batchThat", batchThatDF)
513+
})
514+
.build()
515+
def schema = TestUtil.schema("""
516+
type Query {
517+
foo1: [Foo]
518+
foo2: [Foo]
519+
}
520+
type Foo{
521+
id: ID
522+
subFoo: [SubFoo]
523+
}
524+
type SubFoo{
525+
batchThat: String
526+
}
527+
""", runtimeWiring)
528+
529+
def query = """
530+
{foo1 {id subFoo{batchThat}} foo2 {id subFoo{batchThat}} }
531+
"""
532+
533+
when:
534+
GraphQL.newGraphQL(schema).queryExecutionStrategy(new BatchedExecutionStrategy())
535+
.build().execute(query)
536+
537+
then:
538+
expectedBatchThatCount == 2
539+
540+
541+
}
542+
477543
}

0 commit comments

Comments
 (0)