1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Functional\Relay\Mutation; |
4
|
|
|
|
5
|
|
|
use Overblog\GraphQLBundle\Tests\Functional\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class MutationTest. |
9
|
|
|
* |
10
|
|
|
* @see https://github.com/graphql/graphql-relay-js/blob/master/src/mutation/__tests__/mutation.js |
11
|
|
|
*/ |
12
|
|
|
class MutationTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
protected function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
static::bootKernel(['test_case' => 'mutation']); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testRequiresAnArgument() |
22
|
|
|
{ |
23
|
|
|
$query = <<<'EOF' |
24
|
|
|
mutation M { |
25
|
|
|
simpleMutation { |
26
|
|
|
result |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
EOF; |
30
|
|
|
$result = $this->executeGraphQLRequest($query); |
31
|
|
|
|
32
|
|
|
$this->assertCount(1, $result['errors']); |
33
|
|
|
$this->assertEquals( |
34
|
|
|
'Field "simpleMutation" argument "input" of type "simpleMutationInput!" is required but not provided.', |
35
|
|
|
$result['errors'][0]['message'] |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testReturnTheSameClientMutationId() |
40
|
|
|
{ |
41
|
|
|
$query = <<<'EOF' |
42
|
|
|
mutation M { |
43
|
|
|
simpleMutation(input: {clientMutationId: "abc"}) { |
44
|
|
|
result |
45
|
|
|
clientMutationId |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
EOF; |
49
|
|
|
|
50
|
|
|
$expectedData = [ |
51
|
|
|
'simpleMutation' => [ |
52
|
|
|
'result' => 1, |
53
|
|
|
'clientMutationId' => 'abc', |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
$this->assertGraphQL($query, $expectedData); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testSupportsThunksAsInputAndOutputFields() |
61
|
|
|
{ |
62
|
|
|
$query = <<<'EOF' |
63
|
|
|
mutation M { |
64
|
|
|
simpleMutationWithThunkFields(input: {inputData: 1234, clientMutationId: "abc"}) { |
65
|
|
|
result |
66
|
|
|
clientMutationId |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
EOF; |
70
|
|
|
$expectedData = [ |
71
|
|
|
'simpleMutationWithThunkFields' => [ |
72
|
|
|
'result' => 1234, |
73
|
|
|
'clientMutationId' => 'abc', |
74
|
|
|
], |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
$this->assertGraphQL($query, $expectedData); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testSupportsPromiseMutations() |
81
|
|
|
{ |
82
|
|
|
$query = <<<'EOF' |
83
|
|
|
mutation M { |
84
|
|
|
simplePromiseMutation(input: {clientMutationId: "abc"}) { |
85
|
|
|
result |
86
|
|
|
clientMutationId |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
EOF; |
90
|
|
|
$expectedData = [ |
91
|
|
|
'simplePromiseMutation' => [ |
92
|
|
|
'result' => 1, |
93
|
|
|
'clientMutationId' => 'abc', |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
$this->assertGraphQL($query, $expectedData); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testContainsCorrectInput() |
101
|
|
|
{ |
102
|
|
|
$query = <<<'EOF' |
103
|
|
|
{ |
104
|
|
|
__type(name: "simpleMutationInput") { |
105
|
|
|
name |
106
|
|
|
kind |
107
|
|
|
inputFields { |
108
|
|
|
name |
109
|
|
|
type { |
110
|
|
|
name |
111
|
|
|
kind |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
EOF; |
117
|
|
|
$expectedData = [ |
118
|
|
|
'__type' => [ |
119
|
|
|
'name' => 'simpleMutationInput', |
120
|
|
|
'kind' => 'INPUT_OBJECT', |
121
|
|
|
'inputFields' => [ |
122
|
|
|
[ |
123
|
|
|
'name' => 'clientMutationId', |
124
|
|
|
'type' => [ |
125
|
|
|
'name' => 'String', |
126
|
|
|
'kind' => 'SCALAR', |
127
|
|
|
], |
128
|
|
|
], |
129
|
|
|
], |
130
|
|
|
], |
131
|
|
|
]; |
132
|
|
|
|
133
|
|
|
$this->assertGraphQL($query, $expectedData); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testContainsCorrectPayload() |
137
|
|
|
{ |
138
|
|
|
$query = <<<'EOF' |
139
|
|
|
{ |
140
|
|
|
__type(name: "simpleMutationPayload") { |
141
|
|
|
name |
142
|
|
|
kind |
143
|
|
|
fields { |
144
|
|
|
name |
145
|
|
|
type { |
146
|
|
|
name |
147
|
|
|
kind |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
EOF; |
153
|
|
|
|
154
|
|
|
$expectedData = [ |
155
|
|
|
'__type' => [ |
156
|
|
|
'name' => 'simpleMutationPayload', |
157
|
|
|
'kind' => 'OBJECT', |
158
|
|
|
'fields' => [ |
159
|
|
|
[ |
160
|
|
|
'name' => 'result', |
161
|
|
|
'type' => [ |
162
|
|
|
'name' => 'Int', |
163
|
|
|
'kind' => 'SCALAR', |
164
|
|
|
], |
165
|
|
|
], |
166
|
|
|
[ |
167
|
|
|
'name' => 'clientMutationId', |
168
|
|
|
'type' => [ |
169
|
|
|
'name' => 'String', |
170
|
|
|
'kind' => 'SCALAR', |
171
|
|
|
], |
172
|
|
|
], |
173
|
|
|
], |
174
|
|
|
], |
175
|
|
|
]; |
176
|
|
|
|
177
|
|
|
$this->assertGraphQL($query, $expectedData); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testContainsCorrectField() |
181
|
|
|
{ |
182
|
|
|
$query = <<<'EOF' |
183
|
|
|
{ |
184
|
|
|
__schema { |
185
|
|
|
mutationType { |
186
|
|
|
fields { |
187
|
|
|
name |
188
|
|
|
args { |
189
|
|
|
name |
190
|
|
|
type { |
191
|
|
|
name |
192
|
|
|
kind |
193
|
|
|
ofType { |
194
|
|
|
name |
195
|
|
|
kind |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
type { |
200
|
|
|
name |
201
|
|
|
kind |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
EOF; |
208
|
|
|
|
209
|
|
|
$expectedData = [ |
210
|
|
|
'__schema' => [ |
211
|
|
|
'mutationType' => [ |
212
|
|
|
'fields' => [ |
213
|
|
|
[ |
214
|
|
|
'name' => 'simpleMutation', |
215
|
|
|
'args' => [ |
216
|
|
|
[ |
217
|
|
|
'name' => 'input', |
218
|
|
|
'type' => [ |
219
|
|
|
'name' => null, |
220
|
|
|
'kind' => 'NON_NULL', |
221
|
|
|
'ofType' => [ |
222
|
|
|
'name' => 'simpleMutationInput', |
223
|
|
|
'kind' => 'INPUT_OBJECT', |
224
|
|
|
], |
225
|
|
|
], |
226
|
|
|
], |
227
|
|
|
], |
228
|
|
|
'type' => [ |
229
|
|
|
'name' => 'simpleMutationPayload', |
230
|
|
|
'kind' => 'OBJECT', |
231
|
|
|
], |
232
|
|
|
], |
233
|
|
|
[ |
234
|
|
|
'name' => 'simpleMutationWithThunkFields', |
235
|
|
|
'args' => [ |
236
|
|
|
[ |
237
|
|
|
'name' => 'input', |
238
|
|
|
'type' => [ |
239
|
|
|
'name' => null, |
240
|
|
|
'kind' => 'NON_NULL', |
241
|
|
|
'ofType' => [ |
242
|
|
|
'name' => 'simpleMutationWithThunkFieldsInput', |
243
|
|
|
'kind' => 'INPUT_OBJECT', |
244
|
|
|
], |
245
|
|
|
], |
246
|
|
|
], |
247
|
|
|
], |
248
|
|
|
'type' => [ |
249
|
|
|
'name' => 'simpleMutationWithThunkFieldsPayload', |
250
|
|
|
'kind' => 'OBJECT', |
251
|
|
|
], |
252
|
|
|
], |
253
|
|
|
[ |
254
|
|
|
'name' => 'simplePromiseMutation', |
255
|
|
|
'args' => [ |
256
|
|
|
[ |
257
|
|
|
'name' => 'input', |
258
|
|
|
'type' => [ |
259
|
|
|
'name' => null, |
260
|
|
|
'kind' => 'NON_NULL', |
261
|
|
|
'ofType' => [ |
262
|
|
|
'name' => 'simplePromiseMutationInput', |
263
|
|
|
'kind' => 'INPUT_OBJECT', |
264
|
|
|
], |
265
|
|
|
], |
266
|
|
|
], |
267
|
|
|
], |
268
|
|
|
'type' => [ |
269
|
|
|
'name' => 'simplePromiseMutationPayload', |
270
|
|
|
'kind' => 'OBJECT', |
271
|
|
|
], |
272
|
|
|
], |
273
|
|
|
], |
274
|
|
|
], |
275
|
|
|
], |
276
|
|
|
]; |
277
|
|
|
|
278
|
|
|
$this->assertGraphQL($query, $expectedData); |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|