/
mutation.feature
348 lines (334 loc) · 12.8 KB
/
mutation.feature
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
Feature: GraphQL mutation support
@createSchema
Scenario: Introspect types
When I send the following GraphQL request:
"""
{
__type(name: "Mutation") {
fields {
name
description
type {
name
kind
}
args {
name
type {
name
kind
}
}
}
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.__type.fields[0].name" should contain "delete"
And the JSON node "data.__type.fields[0].description" should match '/^Deletes a [A-z0-9]+\.$/'
And the JSON node "data.__type.fields[0].type.name" should match "/^delete[A-z0-9]+Payload$/"
And the JSON node "data.__type.fields[0].type.kind" should be equal to "OBJECT"
And the JSON node "data.__type.fields[0].args[0].name" should be equal to "input"
And the JSON node "data.__type.fields[0].args[0].type.name" should match "/^delete[A-z0-9]+Input$/"
And the JSON node "data.__type.fields[0].args[0].type.kind" should be equal to "INPUT_OBJECT"
Scenario: Create an item
When I send the following GraphQL request:
"""
mutation {
createFoo(input: {name: "A new one", bar: "new", clientMutationId: "myId"}) {
id
name
bar
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createFoo.id" should be equal to "/foos/1"
And the JSON node "data.createFoo.name" should be equal to "A new one"
And the JSON node "data.createFoo.bar" should be equal to "new"
And the JSON node "data.createFoo.clientMutationId" should be equal to "myId"
Scenario: Create an item with a subresource
Given there are 1 dummy objects with relatedDummy
When I send the following GraphQL request:
"""
mutation {
createDummy(input: {_id: 1, name: "A dummy", foo: [], relatedDummy: "/related_dummies/1", clientMutationId: "myId"}) {
id
name
foo
relatedDummy {
name
}
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createDummy.id" should be equal to "/dummies/2"
And the JSON node "data.createDummy.name" should be equal to "A dummy"
And the JSON node "data.createDummy.foo" should have 0 elements
And the JSON node "data.createDummy.relatedDummy.name" should be equal to "RelatedDummy #1"
And the JSON node "data.createDummy.clientMutationId" should be equal to "myId"
Scenario: Create an item with an iterable field
When I send the following GraphQL request:
"""
mutation {
createDummy(input: {_id: 2, name: "A dummy", foo: [], jsonData: {bar:{baz:3,qux:[7.6,false,null]}}, arrayData: ["bar", "baz"], clientMutationId: "myId"}) {
id
name
foo
jsonData
arrayData
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createDummy.id" should be equal to "/dummies/3"
And the JSON node "data.createDummy.name" should be equal to "A dummy"
And the JSON node "data.createDummy.foo" should have 0 elements
And the JSON node "data.createDummy.jsonData.bar.baz" should be equal to the number 3
And the JSON node "data.createDummy.jsonData.bar.qux[0]" should be equal to the number 7.6
And the JSON node "data.createDummy.jsonData.bar.qux[1]" should be false
And the JSON node "data.createDummy.jsonData.bar.qux[2]" should be null
And the JSON node "data.createDummy.arrayData[1]" should be equal to baz
And the JSON node "data.createDummy.clientMutationId" should be equal to "myId"
Scenario: Delete an item through a mutation
When I send the following GraphQL request:
"""
mutation {
deleteFoo(input: {id: "/foos/1", clientMutationId: "anotherId"}) {
id
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.deleteFoo.id" should be equal to "/foos/1"
And the JSON node "data.deleteFoo.clientMutationId" should be equal to "anotherId"
Scenario: Trigger an error trying to delete item of different resource
When I send the following GraphQL request:
"""
mutation {
deleteFoo(input: {id: "/dummies/1", clientMutationId: "myId"}) {
id
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "errors[0].message" should be equal to 'Item "/dummies/1" did not match expected type "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Foo".'
Scenario: Delete an item with composite identifiers through a mutation
Given there are Composite identifier objects
When I send the following GraphQL request:
"""
mutation {
deleteCompositeRelation(input: {id: "/composite_relations/compositeItem=1;compositeLabel=1", clientMutationId: "myId"}) {
id
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.deleteCompositeRelation.id" should be equal to "/composite_relations/compositeItem=1;compositeLabel=1"
And the JSON node "data.deleteCompositeRelation.clientMutationId" should be equal to "myId"
@createSchema
Scenario: Modify an item through a mutation
Given there are 1 dummy objects having each 2 relatedDummies
When I send the following GraphQL request:
"""
mutation {
updateDummy(input: {id: "/dummies/1", description: "Modified description.", dummyDate: "2018-06-05", clientMutationId: "myId"}) {
id
name
description
dummyDate
relatedDummies {
edges {
node {
name
}
}
}
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.updateDummy.id" should be equal to "/dummies/1"
And the JSON node "data.updateDummy.name" should be equal to "Dummy #1"
And the JSON node "data.updateDummy.description" should be equal to "Modified description."
And the JSON node "data.updateDummy.dummyDate" should be equal to "2018-06-05T00:00:00+00:00"
And the JSON node "data.updateDummy.relatedDummies.edges[0].node.name" should be equal to "RelatedDummy11"
And the JSON node "data.updateDummy.clientMutationId" should be equal to "myId"
Scenario: Modify an item with composite identifiers through a mutation
Given there are Composite identifier objects
When I send the following GraphQL request:
"""
mutation {
updateCompositeRelation(input: {id: "/composite_relations/compositeItem=1;compositeLabel=2", value: "Modified value.", clientMutationId: "myId"}) {
id
value
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.updateCompositeRelation.id" should be equal to "/composite_relations/compositeItem=1;compositeLabel=2"
And the JSON node "data.updateCompositeRelation.value" should be equal to "Modified value."
And the JSON node "data.updateCompositeRelation.clientMutationId" should be equal to "myId"
Scenario: Create an item with a custom UUID
When I send the following GraphQL request:
"""
mutation {
createWritableId(input: {_id: "c6b722fe-0331-48c4-a214-f81f9f1ca082", name: "Foo", clientMutationId: "m"}) {
id
_id
name
clientMutationId
}
}
"""
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createWritableId.id" should be equal to "/writable_ids/c6b722fe-0331-48c4-a214-f81f9f1ca082"
And the JSON node "data.createWritableId._id" should be equal to "c6b722fe-0331-48c4-a214-f81f9f1ca082"
And the JSON node "data.createWritableId.name" should be equal to "Foo"
And the JSON node "data.createWritableId.clientMutationId" should be equal to "m"
Scenario: Update an item with a custom UUID
When I send the following GraphQL request:
"""
mutation {
updateWritableId(input: {id: "/writable_ids/c6b722fe-0331-48c4-a214-f81f9f1ca082", _id: "f8a708b2-310f-416c-9aef-b1b5719dfa47", name: "Foo", clientMutationId: "m"}) {
id
_id
name
clientMutationId
}
}
"""
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.updateWritableId.id" should be equal to "/writable_ids/f8a708b2-310f-416c-9aef-b1b5719dfa47"
And the JSON node "data.updateWritableId._id" should be equal to "f8a708b2-310f-416c-9aef-b1b5719dfa47"
And the JSON node "data.updateWritableId.name" should be equal to "Foo"
And the JSON node "data.updateWritableId.clientMutationId" should be equal to "m"
Scenario: Use serialization groups
Given there are 1 dummy group objects
When I send the following GraphQL request:
"""
mutation {
createDummyGroup(input: {bar: "Bar", baz: "Baz", clientMutationId: "myId"}) {
id
bar
baz
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.createDummyGroup.id" should be equal to "/dummy_groups/2"
And the JSON node "data.createDummyGroup.bar" should be equal to "Bar"
And the JSON node "data.createDummyGroup.baz" should be null
And the JSON node "data.createDummyGroup.clientMutationId" should be equal to "myId"
Scenario: Trigger a validation error
When I send the following GraphQL request:
"""
mutation {
createDummy(input: {_id: 12, name: "", foo: [], clientMutationId: "myId"}) {
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "errors[0].message" should be equal to "name: This value should not be blank."
Scenario: Create an item using custom inputClass & disabled outputClass
Given there are 2 dummyDtoNoOutput objects
When I send the following GraphQL request:
"""
mutation {
createDummyDtoNoOutput(input: {foo: "A new one", bar: 3, clientMutationId: "myId"}) {
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON should be equal to:
"""
{
"data": {
"createDummyDtoNoOutput": {
"clientMutationId": "myId"
}
}
}
"""
Scenario: Cannot create an item using disabled inputClass
Given there are 2 dummyDtoNoInput objects
When I send the following GraphQL request:
"""
mutation {
createDummyDtoNoInput(input: {foo: "A new one", bar: 3, clientMutationId: "myId"}) {
clientMutationId
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON should be equal to:
"""
{
"errors": [
{
"message": "Field \"foo\" is not defined by type createDummyDtoNoInputInput.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 2,
"column": 33
}
]
},
{
"message": "Field \"bar\" is not defined by type createDummyDtoNoInputInput.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 2,
"column": 51
}
]
}
]
}
"""