Repository navigation
Expand file tree
/
Copy pathDataLoaderCompanyProductMutationTest.groovy
More file actions
97 lines (75 loc) · 3.74 KB
/
Copy pathDataLoaderCompanyProductMutationTest.groovy
File metadata and controls
97 lines (75 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package graphql.execution.instrumentation.dataloader
import graphql.ExecutionInput
import graphql.ExecutionResult
import graphql.TestUtil
import graphql.execution.AsyncExecutionStrategy
import graphql.execution.AsyncSerialExecutionStrategy
import org.dataloader.DataLoaderRegistry
import spock.lang.Specification
import spock.lang.Unroll
import java.util.concurrent.TimeUnit
import static graphql.schema.idl.RuntimeWiring.newRuntimeWiring
import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring
class DataLoaderCompanyProductMutationTest extends Specification {
@Unroll
def "bug #1099 test mutation completes as expected and does not hang - running #note"() {
DataLoaderCompanyProductBackend backend = new DataLoaderCompanyProductBackend(3, 5)
def spec = '''
type Project {
id : ID!
name : String!
}
type Company {
id : ID!
name : String!
projects : [Project!]
}
type Query {
companies : [Company!]
}
type Mutation {
addCompany : Company
}
'''
def wiring = newRuntimeWiring()
.type(
newTypeWiring("Company").dataFetcher("projects", {
environment ->
DataLoaderCompanyProductBackend.Company source = environment.getSource()
return environment.getDataLoader("projects-dl").load(source.getId())
}))
.type(
newTypeWiring("Query").dataFetcher("companies", {
environment -> backend.getCompanies()
}))
.type(
newTypeWiring("Mutation").dataFetcher("addCompany", {
environment -> backend.addCompany()
}))
.build()
def registry = new DataLoaderRegistry()
registry.register("projects-dl", backend.getProjectsLoader())
def graphQL = TestUtil.graphQL(spec, wiring)
.queryExecutionStrategy(queryES)
.mutationExecutionStrategy(mutationES)
.build()
ExecutionInput executionInput = ExecutionInput.newExecutionInput()
.query(query)
.dataLoaderRegistry(registry)
.build()
when:
ExecutionResult result = graphQL.executeAsync(executionInput).get(5, TimeUnit.SECONDS)
then:
result != null
result.errors.isEmpty()
result.data != null
where:
note | query | queryES | mutationES
"mutation - spec compliant" | "mutation { addCompany { name projects { name }}}" | new AsyncExecutionStrategy() | new AsyncSerialExecutionStrategy()
"mutation - all serial" | "mutation { addCompany { name projects { name }}}" | new AsyncSerialExecutionStrategy() | new AsyncSerialExecutionStrategy()
"mutation - non spec compliant" | "mutation { addCompany { name projects { name }}}" | new AsyncExecutionStrategy() | new AsyncExecutionStrategy()
"query - spec compliant" | "query {companies { name projects { name }}}" | new AsyncExecutionStrategy() | new AsyncSerialExecutionStrategy()
"query - all serial" | "query {companies { name projects { name }}}" | new AsyncSerialExecutionStrategy() | new AsyncSerialExecutionStrategy()
"query - non spec compliant" | "query {companies { name projects { name }}}" | new AsyncExecutionStrategy() | new AsyncExecutionStrategy()
}
}