-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathIssue739.groovy
More file actions
112 lines (86 loc) · 3.44 KB
/
Issue739.groovy
File metadata and controls
112 lines (86 loc) · 3.44 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package graphql
import graphql.language.SourceLocation
import graphql.schema.GraphQLObjectType
import graphql.schema.idl.RuntimeWiring
import spock.lang.Specification
import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring
class Issue739 extends Specification {
def "Arguments passed via variables are not validated"() {
when:
RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
.type(newTypeWiring("Query")
.dataFetcher("foo",
{ env ->
Map<String, Object> map = new HashMap<>()
map.put("id", "abc")
return map
})
.dataFetcher("bar",
{ env ->
Map<String, Object> map = new HashMap<>()
map.put("id", "def")
return map
})
)
.type(newTypeWiring("Node")
.typeResolver({ env -> (GraphQLObjectType) env.getSchema().getType("Foo") }))
.build()
def graphQL = TestUtil.graphQL("""
schema {
query: Query
}
type Query {
foo: Node
bar(input: BarInput!): Node
}
input BarInput {
baz: String!
boom: Int
}
interface Node {
id: String
}
type Foo implements Node {
id: String
}
""", runtimeWiring).build()
ExecutionInput noVarInput = ExecutionInput.newExecutionInput()
.query('{ bar(input: 123) { id } } ')
.build()
ExecutionResult noVarResult = graphQL
.executeAsync(noVarInput)
.join()
then:
1 == noVarResult.getErrors().size()
when:
def variables = ["input": 123]
ExecutionInput varInput = ExecutionInput.newExecutionInput()
.query('query Bar($input: BarInput!) {bar(input: $input) {id}}')
.variables(variables)
.build()
ExecutionResult varResult = graphQL
.executeAsync(varInput)
.join()
then:
varResult.data == null
varResult.errors.size() == 1
varResult.errors[0].errorType == ErrorType.ValidationError
varResult.errors[0].message == "Variable 'input' has an invalid value: Expected type 'Map' but was 'Integer'. Variables for input objects must be an instance of type 'Map'."
varResult.errors[0].locations == [new SourceLocation(1, 11)]
when:
variables = ["input": ["baz": "hi", "boom": "hi"]]
varInput = ExecutionInput.newExecutionInput()
.query('query Bar($input: BarInput!) {bar(input: $input) {id}}')
.variables(variables)
.build()
varResult = graphQL
.executeAsync(varInput)
.join()
then:
varResult.data == null
varResult.errors.size() == 1
varResult.errors[0].errorType == ErrorType.ValidationError
varResult.errors[0].message == "Variable 'input' has an invalid value: Expected a value that can be converted to type 'Int' but it was a 'String'"
varResult.errors[0].locations == [new SourceLocation(1, 11)]
}
}