| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,12 +8,13 @@ import graphql.ExceptionWhileDataFetching | |||
| 8 | 8 | import graphql.ExecutionResult | |
| 9 | 9 | import graphql.GraphQL | |
| 10 | 10 | import graphql.Scalars | |
| 11 | + import graphql.TestUtil | ||
| 11 | 12 | import graphql.execution.AsyncExecutionStrategy | |
| 12 | - import graphql.execution.NonNullableFieldWasNullError | ||
| 13 | 13 | import graphql.execution.instrumentation.TestingInstrumentation | |
| 14 | 14 | import graphql.schema.DataFetcher | |
| 15 | 15 | import graphql.schema.GraphQLObjectType | |
| 16 | 16 | import graphql.schema.GraphQLSchema | |
| 17 | + import graphql.schema.idl.RuntimeWiring | ||
| 17 | 18 | import spock.lang.Specification | |
| 18 | 19 | ||
| 19 | 20 | import java.util.concurrent.atomic.AtomicInteger | |
@@ -474,4 +475,69 @@ class BatchedExecutionStrategyTest extends Specification { | |||
| 474 | 475 | result.getErrors()[0] instanceof ExceptionWhileDataFetching | |
| 475 | 476 | } | |
| 476 | 477 | ||
| 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 | + | ||
| 477 | 543 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments