-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
GraphQLTypeUtilTest.groovy
208 lines (152 loc) · 5.06 KB
/
GraphQLTypeUtilTest.groovy
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package graphql.schema
import spock.lang.Specification
import static graphql.Scalars.GraphQLString
import static graphql.schema.GraphQLList.list
import static graphql.schema.GraphQLNonNull.nonNull
import static graphql.schema.GraphQLObjectType.newObject
import static graphql.schema.GraphQLTypeReference.*
class GraphQLTypeUtilTest extends Specification {
def heroType = newObject().name("Hero").build()
def inputType = GraphQLInputObjectType.newInputObject().name("Input").build()
def enumType = GraphQLEnumType.newEnum().name("enumType").value("X").build()
def "test it builds its wrapped types"() {
given:
def nonnull_heroType = nonNull(heroType)
def list_nonnull_heroType = list(nonnull_heroType)
def nonnull_list_nonnull_heroType = nonNull(list_nonnull_heroType)
when:
def heroTypeStr = GraphQLTypeUtil.simplePrint(heroType)
def nonnull_heroType_str = GraphQLTypeUtil.simplePrint(nonnull_heroType)
def list_nonnull_heroType_str = GraphQLTypeUtil.simplePrint(list_nonnull_heroType)
def nonnull_list_nonnull_heroType_str = GraphQLTypeUtil.simplePrint(nonnull_list_nonnull_heroType)
then:
heroTypeStr == "Hero"
nonnull_heroType_str == "Hero!"
list_nonnull_heroType_str == "[Hero!]"
nonnull_list_nonnull_heroType_str == "[Hero!]!"
}
def "isList tests"() {
expect:
GraphQLTypeUtil.isList(list(GraphQLString))
!GraphQLTypeUtil.isList(nonNull(GraphQLString))
!GraphQLTypeUtil.isList(GraphQLString)
!GraphQLTypeUtil.isList(nonNull(list(GraphQLString)))
}
def "isNonNull tests"() {
expect:
GraphQLTypeUtil.isNonNull(nonNull(GraphQLString))
!GraphQLTypeUtil.isNonNull(list(GraphQLString))
!GraphQLTypeUtil.isNonNull(GraphQLString)
!GraphQLTypeUtil.isNonNull(list(nonNull(GraphQLString)))
}
def "isWrapperType tests"() {
expect:
GraphQLTypeUtil.isWrapped(nonNull(GraphQLString))
GraphQLTypeUtil.isWrapped(list(GraphQLString))
!GraphQLTypeUtil.isWrapped(GraphQLString)
}
def "isNotWrapped tests"() {
expect:
!GraphQLTypeUtil.isNotWrapped(nonNull(GraphQLString))
!GraphQLTypeUtil.isNotWrapped(list(GraphQLString))
GraphQLTypeUtil.isNotWrapped(GraphQLString)
}
def "isScalar tests"() {
expect:
GraphQLTypeUtil.isScalar(GraphQLString)
!GraphQLTypeUtil.isScalar(list(GraphQLString))
}
def "isEnum tests"() {
expect:
GraphQLTypeUtil.isEnum(enumType)
!GraphQLTypeUtil.isEnum(GraphQLString)
!GraphQLTypeUtil.isEnum(list(GraphQLString))
}
def "unwrap tests"() {
when:
def type = list(nonNull(GraphQLString))
then:
GraphQLTypeUtil.isList(type)
when:
type = GraphQLTypeUtil.unwrapOne(type)
then:
GraphQLTypeUtil.isNonNull(type)
when:
type = GraphQLTypeUtil.unwrapOne(type)
then:
!GraphQLTypeUtil.isWrapped(type)
type == GraphQLString
when:
GraphQLScalarType scalar = GraphQLTypeUtil.unwrapOneAs(nonNull(GraphQLString))
then:
scalar == GraphQLString
}
def "unwrapAll tests"() {
when:
def type = list(nonNull(list(nonNull(GraphQLString))))
then:
GraphQLTypeUtil.simplePrint(type) == "[[String!]!]"
when:
type = GraphQLTypeUtil.unwrapAll(type)
then:
type == GraphQLString
when:
type = GraphQLTypeUtil.unwrapAll(type)
then:
type == GraphQLString
}
def "unwrapAllAs tests"() {
def type = list(nonNull(list(nonNull(GraphQLString))))
def typeRef = list(nonNull(list(nonNull(typeRef("A")))))
when:
type = GraphQLTypeUtil.unwrapAllAs(type)
then:
type == GraphQLString
when:
type = GraphQLTypeUtil.unwrapAllAs(type)
then:
type == GraphQLString
when:
typeRef = GraphQLTypeUtil.unwrapAllAs(typeRef)
then:
typeRef instanceof GraphQLTypeReference
(typeRef as GraphQLTypeReference).name == "A"
when:
typeRef = GraphQLTypeUtil.unwrapAllAs(typeRef)
then:
typeRef instanceof GraphQLTypeReference
(typeRef as GraphQLTypeReference).name == "A"
}
def "isLeaf tests"() {
when:
def type = GraphQLString
then:
GraphQLTypeUtil.isLeaf(type)
when:
type = enumType
then:
GraphQLTypeUtil.isLeaf(type)
when:
type = heroType
then:
!GraphQLTypeUtil.isLeaf(type)
}
def "isInput tests"() {
when:
def type = GraphQLString
then:
GraphQLTypeUtil.isInput(type)
when:
type = inputType
then:
GraphQLTypeUtil.isInput(type)
when:
type = enumType
then:
GraphQLTypeUtil.isInput(type)
when:
type = heroType
then:
!GraphQLTypeUtil.isInput(type)
}
}