@@ -25,6 +25,9 @@ |
||
25 | 25 | { |
26 | 26 | } |
27 | 27 | |
28 | + /** |
|
29 | + * @param \Youshido\GraphQL\Type\Object\ObjectType $object |
|
30 | + */ |
|
28 | 31 | public function resolveType($object) |
29 | 32 | { |
30 | 33 | return $this->getConfig()->resolveType($object); |
@@ -50,6 +50,9 @@ |
||
50 | 50 | return $value; |
51 | 51 | } |
52 | 52 | |
53 | + /** |
|
54 | + * @param null|Scalar\StringType $value |
|
55 | + */ |
|
53 | 56 | public function isValidValue($value) |
54 | 57 | { |
55 | 58 | return $value !== null; |
@@ -57,7 +57,7 @@ |
||
57 | 57 | * @param Field $objField |
58 | 58 | * @param AbstractInterfaceType $interface |
59 | 59 | * |
60 | - * @return bool |
|
60 | + * @return boolean|null |
|
61 | 61 | * |
62 | 62 | * @throws ConfigurationException |
63 | 63 | */ |
@@ -16,13 +16,16 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | /** |
19 | - * @return AbstractObjectType |
|
19 | + * @return IntType |
|
20 | 20 | */ |
21 | 21 | public function getType() |
22 | 22 | { |
23 | 23 | return new IntType(); |
24 | 24 | } |
25 | 25 | |
26 | + /** |
|
27 | + * @param string $value |
|
28 | + */ |
|
26 | 29 | public function resolve($value, array $args, ResolveInfo $info) |
27 | 30 | { |
28 | 31 | return $value; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | /** |
19 | - * @return AbstractInputObjectType |
|
19 | + * @return IntType |
|
20 | 20 | */ |
21 | 21 | public function getType() |
22 | 22 | { |
@@ -9,7 +9,6 @@ |
||
9 | 9 | |
10 | 10 | |
11 | 11 | use Youshido\GraphQL\Field\Field; |
12 | -use Youshido\GraphQL\Field\FieldFactory; |
|
13 | 12 | use Youshido\GraphQL\Type\Object\AbstractObjectType; |
14 | 13 | use Youshido\GraphQL\Type\Scalar\IdType; |
15 | 14 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | 'args' => [ |
37 | 37 | 'episode' => ['type' => new EpisodeEnum()] |
38 | 38 | ], |
39 | - 'resolve' => function ($root, $args) { |
|
39 | + 'resolve' => function($root, $args) { |
|
40 | 40 | return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null); |
41 | 41 | }, |
42 | 42 | ]) |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | 'args' => [ |
47 | 47 | 'id' => new IdType() |
48 | 48 | ], |
49 | - 'resolve' => function ($value = null, $args = []) { |
|
49 | + 'resolve' => function($value = null, $args = []) { |
|
50 | 50 | $humans = StarWarsData::humans(); |
51 | 51 | |
52 | 52 | return isset($humans[$args['id']]) ? $humans[$args['id']] : null; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | 'args' => [ |
59 | 59 | 'id' => new IdType() |
60 | 60 | ], |
61 | - 'resolve' => function ($value = null, $args = []) { |
|
61 | + 'resolve' => function($value = null, $args = []) { |
|
62 | 62 | $droids = StarWarsData::droids(); |
63 | 63 | |
64 | 64 | return isset($droids[$args['id']]) ? $droids[$args['id']] : null; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | public function testSchemaOperations() |
98 | 98 | { |
99 | - $schema = new Schema([ |
|
99 | + $schema = new Schema([ |
|
100 | 100 | 'query' => new ObjectType([ |
101 | 101 | 'name' => 'RootQuery', |
102 | 102 | 'fields' => [ |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'args' => [ |
110 | 110 | 'shorten' => new BooleanType() |
111 | 111 | ], |
112 | - 'resolve' => function ($value, $args) { |
|
112 | + 'resolve' => function($value, $args) { |
|
113 | 113 | return empty($args['shorten']) ? $value : $value; |
114 | 114 | } |
115 | 115 | ], |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'code' => new StringType(), |
118 | 118 | ] |
119 | 119 | ]), |
120 | - 'resolve' => function ($value, $args) { |
|
120 | + 'resolve' => function($value, $args) { |
|
121 | 121 | $data = ['firstName' => 'John', 'code' => '007']; |
122 | 122 | if (!empty($args['upper'])) { |
123 | 123 | foreach ($data as $key => $value) { |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | ], |
137 | 137 | 'randomUser' => [ |
138 | 138 | 'type' => new TestObjectType(), |
139 | - 'resolve' => function () { |
|
139 | + 'resolve' => function() { |
|
140 | 140 | return ['invalidField' => 'John']; |
141 | 141 | } |
142 | 142 | ], |
143 | 143 | 'invalidValueQuery' => [ |
144 | 144 | 'type' => new TestObjectType(), |
145 | - 'resolve' => function () { |
|
145 | + 'resolve' => function() { |
|
146 | 146 | return 'stringValue'; |
147 | 147 | } |
148 | 148 | ], |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | ->addField(new Field([ |
168 | 168 | 'name' => 'increaseCounter', |
169 | 169 | 'type' => new IntType(), |
170 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
170 | + 'resolve' => function($value, $args, ResolveInfo $info) { |
|
171 | 171 | return $this->_counter += $args['amount']; |
172 | 172 | }, |
173 | 173 | 'args' => [ |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | ]))->addField(new Field([ |
180 | 180 | 'name' => 'invalidResolveTypeMutation', |
181 | 181 | 'type' => new NonNullType(new IntType()), |
182 | - 'resolve' => function () { |
|
182 | + 'resolve' => function() { |
|
183 | 183 | return null; |
184 | 184 | } |
185 | 185 | ]))->addField(new Field([ |
186 | 186 | 'name' => 'interfacedMutation', |
187 | 187 | 'type' => new TestInterfaceType(), |
188 | - 'resolve' => function () { |
|
188 | + 'resolve' => function() { |
|
189 | 189 | return ['name' => 'John']; |
190 | 190 | } |
191 | 191 | ])); |
@@ -231,43 +231,43 @@ discard block |
||
231 | 231 | 'fields' => [ |
232 | 232 | 'listQuery' => [ |
233 | 233 | 'type' => new ListType(new TestEnumType()), |
234 | - 'resolve' => function () { |
|
234 | + 'resolve' => function() { |
|
235 | 235 | return 'invalid list'; |
236 | 236 | } |
237 | 237 | ], |
238 | 238 | 'listEnumQuery' => [ |
239 | 239 | 'type' => new ListType(new TestEnumType()), |
240 | - 'resolve' => function () { |
|
240 | + 'resolve' => function() { |
|
241 | 241 | return ['invalid enum']; |
242 | 242 | } |
243 | 243 | ], |
244 | 244 | 'invalidEnumQuery' => [ |
245 | 245 | 'type' => new TestEnumType(), |
246 | - 'resolve' => function () { |
|
246 | + 'resolve' => function() { |
|
247 | 247 | return 'invalid enum'; |
248 | 248 | } |
249 | 249 | ], |
250 | 250 | 'enumQuery' => [ |
251 | 251 | 'type' => new TestEnumType(), |
252 | - 'resolve' => function () { |
|
252 | + 'resolve' => function() { |
|
253 | 253 | return 1; |
254 | 254 | } |
255 | 255 | ], |
256 | 256 | 'invalidNonNullQuery' => [ |
257 | 257 | 'type' => new NonNullType(new IntType()), |
258 | - 'resolve' => function () { |
|
258 | + 'resolve' => function() { |
|
259 | 259 | return null; |
260 | 260 | } |
261 | 261 | ], |
262 | 262 | 'invalidNonNullInsideQuery' => [ |
263 | 263 | 'type' => new NonNullType(new IntType()), |
264 | - 'resolve' => function () { |
|
264 | + 'resolve' => function() { |
|
265 | 265 | return 'hello'; |
266 | 266 | } |
267 | 267 | ], |
268 | 268 | 'objectQuery' => [ |
269 | 269 | 'type' => new TestObjectType(), |
270 | - 'resolve' => function () { |
|
270 | + 'resolve' => function() { |
|
271 | 271 | return ['name' => 'John']; |
272 | 272 | } |
273 | 273 | ], |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | 'enum' => new TestEnumType(), |
280 | 280 | ], |
281 | 281 | ]), |
282 | - 'resolve' => function () { |
|
282 | + 'resolve' => function() { |
|
283 | 283 | return [ |
284 | 284 | 'object' => [ |
285 | 285 | 'name' => 'John' |
@@ -348,10 +348,10 @@ discard block |
||
348 | 348 | ] |
349 | 349 | ]); |
350 | 350 | |
351 | - $union = new UnionType([ |
|
351 | + $union = new UnionType([ |
|
352 | 352 | 'name' => 'TestUnion', |
353 | 353 | 'types' => [$object1, $object2], |
354 | - 'resolveType' => function ($object) use ($object1, $object2) { |
|
354 | + 'resolveType' => function($object) use ($object1, $object2) { |
|
355 | 355 | if (isset($object['id'])) { |
356 | 356 | return $object1; |
357 | 357 | } |
@@ -362,11 +362,11 @@ discard block |
||
362 | 362 | $invalidUnion = new UnionType([ |
363 | 363 | 'name' => 'TestUnion', |
364 | 364 | 'types' => [$object1, $object2], |
365 | - 'resolveType' => function ($object) use ($object3) { |
|
365 | + 'resolveType' => function($object) use ($object3) { |
|
366 | 366 | return $object3; |
367 | 367 | } |
368 | 368 | ]); |
369 | - $processor = new Processor(new Schema([ |
|
369 | + $processor = new Processor(new Schema([ |
|
370 | 370 | 'query' => new ObjectType([ |
371 | 371 | 'name' => 'RootQuery', |
372 | 372 | 'fields' => [ |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | 'args' => [ |
376 | 376 | 'type' => ['type' => 'string'] |
377 | 377 | ], |
378 | - 'resolve' => function ($value, $args) { |
|
378 | + 'resolve' => function($value, $args) { |
|
379 | 379 | if ($args['type'] == 'object1') { |
380 | 380 | return [ |
381 | 381 | 'id' => 43 |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | ], |
390 | 390 | 'invalidUnion' => [ |
391 | 391 | 'type' => $invalidUnion, |
392 | - 'resolve' => function () { |
|
392 | + 'resolve' => function() { |
|
393 | 393 | return ['name' => 'name resolved']; |
394 | 394 | } |
395 | 395 | ], |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | } |
57 | 57 | |
58 | - public function testNestedVariables() { |
|
58 | + public function testNestedVariables() { |
|
59 | 59 | $processor = new Processor(new TestSchema()); |
60 | 60 | $noArgsQuery = '{ me { echo(value:"foo") } }'; |
61 | 61 | $expectedData = ['data' => ['me' => ['echo' => 'foo']]]; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | }'; |
82 | 82 | $processor->processPayload($parameterizedQueryQuery, ['value' => 1]); |
83 | 83 | $this->assertArrayNotHasKey('errors', $processor->getResponseData()); |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | 86 | public function testListNullResponse() |
87 | 87 | { |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | $this->assertEquals(['data' => ['me' => ['firstName' => 'JOHN']]], $processor->getResponseData()); |
193 | 193 | |
194 | 194 | $schema->getMutationType() |
195 | - ->addField(new Field([ |
|
196 | - 'name' => 'increaseCounter', |
|
197 | - 'type' => new IntType(), |
|
198 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
199 | - return $this->_counter += $args['amount']; |
|
200 | - }, |
|
201 | - 'args' => [ |
|
202 | - 'amount' => [ |
|
203 | - 'type' => new IntType(), |
|
204 | - 'default' => 1 |
|
205 | - ] |
|
206 | - ] |
|
207 | - ]))->addField(new Field([ |
|
195 | + ->addField(new Field([ |
|
196 | + 'name' => 'increaseCounter', |
|
197 | + 'type' => new IntType(), |
|
198 | + 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
199 | + return $this->_counter += $args['amount']; |
|
200 | + }, |
|
201 | + 'args' => [ |
|
202 | + 'amount' => [ |
|
203 | + 'type' => new IntType(), |
|
204 | + 'default' => 1 |
|
205 | + ] |
|
206 | + ] |
|
207 | + ]))->addField(new Field([ |
|
208 | 208 | 'name' => 'invalidResolveTypeMutation', |
209 | 209 | 'type' => new NonNullType(new IntType()), |
210 | 210 | 'resolve' => function () { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | 'description' => 'latest description', |
136 | 136 | 'deprecationReason' => 'for test', |
137 | 137 | 'isDeprecated' => true, |
138 | - 'resolve' => function () { |
|
138 | + 'resolve' => function() { |
|
139 | 139 | return [ |
140 | 140 | 'id' => 1, |
141 | 141 | 'name' => 'Alex' |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | ['name' => 'String', 'fields' => null], |
198 | 198 | ['name' => '__Schema', 'fields' => [['name' => 'queryType'], ['name' => 'mutationType'], ['name' => 'subscriptionType'], ['name' => 'types'], ['name' => 'directives']]], |
199 | 199 | ['name' => '__Type', 'fields' => [['name' => 'name'], ['name' => 'kind'], ['name' => 'description'], ['name' => 'ofType'], ['name' => 'inputFields'], ['name' => 'enumValues'], ['name' => 'fields'], ['name' => 'interfaces'], ['name' => 'possibleTypes']]], |
200 | - ['name' => '__InputValue', 'fields' => [['name' => 'name'], ['name' => 'description'], ['name' => 'type'], ['name' => 'defaultValue'],]], |
|
201 | - ['name' => '__EnumValue', 'fields' => [['name' => 'name'], ['name' => 'description'], ['name' => 'deprecationReason'], ['name' => 'isDeprecated'],]], |
|
200 | + ['name' => '__InputValue', 'fields' => [['name' => 'name'], ['name' => 'description'], ['name' => 'type'], ['name' => 'defaultValue'], ]], |
|
201 | + ['name' => '__EnumValue', 'fields' => [['name' => 'name'], ['name' => 'description'], ['name' => 'deprecationReason'], ['name' => 'isDeprecated'], ]], |
|
202 | 202 | ['name' => 'Boolean', 'fields' => null], |
203 | 203 | ['name' => '__Field', 'fields' => [['name' => 'name'], ['name' => 'description'], ['name' => 'isDeprecated'], ['name' => 'deprecationReason'], ['name' => 'type'], ['name' => 'args']]], |
204 | 204 | ['name' => '__Subscription', 'fields' => [['name' => 'name']]], |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | 'id' => ['type' => new IntType()], |
288 | 288 | 'name' => ['type' => new IntType()], |
289 | 289 | ], |
290 | - 'resolveType' => function ($type) { |
|
290 | + 'resolveType' => function($type) { |
|
291 | 291 | |
292 | 292 | } |
293 | 293 | ]); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | $unionType = new UnionType([ |
316 | 316 | 'name' => 'UnionType', |
317 | 317 | 'types' => [$object1, $object2], |
318 | - 'resolveType' => function () { |
|
318 | + 'resolveType' => function() { |
|
319 | 319 | |
320 | 320 | } |
321 | 321 | ]); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | 'args' => [ |
327 | 327 | 'id' => ['type' => TypeMap::TYPE_INT] |
328 | 328 | ], |
329 | - 'resolve' => function () { |
|
329 | + 'resolve' => function() { |
|
330 | 330 | return [ |
331 | 331 | 'id' => 1, |
332 | 332 | 'name' => 'Alex' |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | ] |
353 | 353 | ]) |
354 | 354 | ], |
355 | - 'resolve' => function () { |
|
355 | + 'resolve' => function() { |
|
356 | 356 | return null; |
357 | 357 | } |
358 | 358 | ])); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | 'fields' => [ |
27 | 27 | 'currentTime' => [ |
28 | 28 | 'type' => new StringType(), |
29 | - 'resolve' => function ($value, $args, $type) { |
|
29 | + 'resolve' => function($value, $args, $type) { |
|
30 | 30 | return 'May 5, 9:00am'; |
31 | 31 | }, |
32 | 32 | 'args' => [ |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | $this->assertEquals(1, count($schema->getMutationType()->getFields())); |
57 | 57 | |
58 | - $schema->addMutationField('changeUser', ['type' => new TestObjectType(), 'resolve' => function () { }]); |
|
58 | + $schema->addMutationField('changeUser', ['type' => new TestObjectType(), 'resolve' => function() { }]); |
|
59 | 59 | $this->assertEquals(2, count($schema->getMutationType()->getFields())); |
60 | 60 | |
61 | 61 | } |