@@ -35,13 +35,13 @@ |
||
35 | 35 | if (empty(self::$objectsHash[$type])) { |
36 | 36 | $name = ucfirst($type); |
37 | 37 | |
38 | - $className = 'Youshido\GraphQL\Type\Scalar\\' . $name . 'Type'; |
|
38 | + $className = 'Youshido\GraphQL\Type\Scalar\\'.$name.'Type'; |
|
39 | 39 | self::$objectsHash[$type] = new $className(); |
40 | 40 | } |
41 | 41 | |
42 | 42 | return self::$objectsHash[$type]; |
43 | 43 | } else { |
44 | - throw new ConfigurationException('Configuration problem with type ' . $type); |
|
44 | + throw new ConfigurationException('Configuration problem with type '.$type); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 |
@@ -27,13 +27,13 @@ |
||
27 | 27 | 'title' => new StringType(), |
28 | 28 | ] |
29 | 29 | ]); |
30 | - $processor = new Processor(new Schema([ |
|
30 | + $processor = new Processor(new Schema([ |
|
31 | 31 | 'query' => new ObjectType([ |
32 | 32 | 'name' => 'RootQueryType', |
33 | 33 | 'fields' => [ |
34 | 34 | 'latestReport' => [ |
35 | 35 | 'type' => $reportType, |
36 | - 'resolve' => function () { |
|
36 | + 'resolve' => function() { |
|
37 | 37 | return [ |
38 | 38 | 'title' => 'Accident #1', |
39 | 39 | 'time' => '13:30:12', |
@@ -168,7 +168,9 @@ |
||
168 | 168 | $value = []; |
169 | 169 | |
170 | 170 | if ($fieldType->getKind() == TypeMap::KIND_LIST) { |
171 | - if (!$this->resolveValidator->hasArrayAccess($resolvedValue)) return null; |
|
171 | + if (!$this->resolveValidator->hasArrayAccess($resolvedValue)) { |
|
172 | + return null; |
|
173 | + } |
|
172 | 174 | foreach ($resolvedValue as $resolvedValueItem) { |
173 | 175 | $value[] = []; |
174 | 176 | $index = count($value) - 1; |
@@ -27,7 +27,6 @@ |
||
27 | 27 | use Youshido\GraphQL\Schema\AbstractSchema; |
28 | 28 | use Youshido\GraphQL\Type\AbstractType; |
29 | 29 | use Youshido\GraphQL\Type\Object\AbstractObjectType; |
30 | -use Youshido\GraphQL\Type\Scalar\AbstractScalarType; |
|
31 | 30 | use Youshido\GraphQL\Type\TypeInterface; |
32 | 31 | use Youshido\GraphQL\Type\TypeMap; |
33 | 32 | use Youshido\GraphQL\Type\TypeService; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | - * @param Query|Field $query |
|
114 | + * @param Query $query |
|
115 | 115 | * @param AbstractObjectType $currentLevelSchema |
116 | 116 | * @return array|bool|mixed |
117 | 117 | */ |
@@ -260,6 +260,9 @@ discard block |
||
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | + /** |
|
264 | + * @param AbstractField $field |
|
265 | + */ |
|
263 | 266 | protected function createResolveInfo($field, $fields) { |
264 | 267 | return new ResolveInfo($field, $fields, $this->executionContext); |
265 | 268 | } |
@@ -322,7 +325,7 @@ discard block |
||
322 | 325 | } |
323 | 326 | |
324 | 327 | /** |
325 | - * @param $query Query|FragmentInterface |
|
328 | + * @param Query $query Query|FragmentInterface |
|
326 | 329 | * @param $queryType AbstractObjectType|TypeInterface|Field|AbstractType |
327 | 330 | * @param $resolvedValue mixed |
328 | 331 | * @param $value array |
@@ -494,7 +497,7 @@ discard block |
||
494 | 497 | * Fragments (anonymous and named), and Fields. The core of the function is simple: recurse until we hit the base |
495 | 498 | * case of a Field and yield that back up to the visitor up in `doVisit`. |
496 | 499 | * |
497 | - * @param Query|Field|FragmentInterface $queryNode |
|
500 | + * @param Query $queryNode |
|
498 | 501 | * @param AbstractField $currentLevelAST |
499 | 502 | * |
500 | 503 | * @return \Generator |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | 'fields' => [ |
94 | 94 | 'list' => [ |
95 | 95 | 'type' => new ListType(new StringType()), |
96 | - 'resolve' => function () { |
|
96 | + 'resolve' => function() { |
|
97 | 97 | return null; |
98 | 98 | } |
99 | 99 | ] |
100 | 100 | ] |
101 | 101 | ]) |
102 | 102 | ])); |
103 | - $data = $processor->processPayload(' { list }')->getResponseData(); |
|
103 | + $data = $processor->processPayload(' { list }')->getResponseData(); |
|
104 | 104 | $this->assertEquals(['data' => ['list' => null]], $data); |
105 | 105 | } |
106 | 106 | |
@@ -113,20 +113,20 @@ discard block |
||
113 | 113 | 'fields' => [ |
114 | 114 | 'list' => [ |
115 | 115 | 'type' => new ListType(new StringType()), |
116 | - 'resolve' => function () { |
|
116 | + 'resolve' => function() { |
|
117 | 117 | return null; |
118 | 118 | } |
119 | 119 | ] |
120 | 120 | ] |
121 | 121 | ]) |
122 | 122 | ])); |
123 | - $data = $processor->processPayload(' { __schema { subscriptionType { name } } }')->getResponseData(); |
|
123 | + $data = $processor->processPayload(' { __schema { subscriptionType { name } } }')->getResponseData(); |
|
124 | 124 | $this->assertEquals(['data' => ['__schema' => ['subscriptionType' => null]]], $data); |
125 | 125 | } |
126 | 126 | |
127 | 127 | public function testSchemaOperations() |
128 | 128 | { |
129 | - $schema = new Schema([ |
|
129 | + $schema = new Schema([ |
|
130 | 130 | 'query' => new ObjectType([ |
131 | 131 | 'name' => 'RootQuery', |
132 | 132 | 'fields' => [ |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | 'args' => [ |
140 | 140 | 'shorten' => new BooleanType() |
141 | 141 | ], |
142 | - 'resolve' => function ($value, $args) { |
|
142 | + 'resolve' => function($value, $args) { |
|
143 | 143 | return empty($args['shorten']) ? $value : $value; |
144 | 144 | } |
145 | 145 | ], |
146 | 146 | 'id_alias' => [ |
147 | 147 | 'type' => new IdType(), |
148 | - 'resolve' => function ($value) { |
|
148 | + 'resolve' => function($value) { |
|
149 | 149 | return $value['id']; |
150 | 150 | } |
151 | 151 | ], |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'code' => new StringType(), |
154 | 154 | ] |
155 | 155 | ]), |
156 | - 'resolve' => function ($value, $args) { |
|
156 | + 'resolve' => function($value, $args) { |
|
157 | 157 | $data = ['id' => '123', 'firstName' => 'John', 'code' => '007']; |
158 | 158 | if (!empty($args['upper'])) { |
159 | 159 | foreach ($data as $key => $value) { |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | ], |
173 | 173 | 'randomUser' => [ |
174 | 174 | 'type' => new TestObjectType(), |
175 | - 'resolve' => function () { |
|
175 | + 'resolve' => function() { |
|
176 | 176 | return ['invalidField' => 'John']; |
177 | 177 | } |
178 | 178 | ], |
179 | 179 | 'invalidValueQuery' => [ |
180 | 180 | 'type' => new TestObjectType(), |
181 | - 'resolve' => function () { |
|
181 | + 'resolve' => function() { |
|
182 | 182 | return 'stringValue'; |
183 | 183 | } |
184 | 184 | ], |
185 | 185 | 'labels' => [ |
186 | 186 | 'type' => new ListType(new StringType()), |
187 | - 'resolve' => function () { |
|
187 | + 'resolve' => function() { |
|
188 | 188 | return ['one', 'two']; |
189 | 189 | } |
190 | 190 | ] |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | ->addField(new Field([ |
216 | 216 | 'name' => 'increaseCounter', |
217 | 217 | 'type' => new IntType(), |
218 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
218 | + 'resolve' => function($value, $args, ResolveInfo $info) { |
|
219 | 219 | return $this->_counter += $args['amount']; |
220 | 220 | }, |
221 | 221 | 'args' => [ |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | ]))->addField(new Field([ |
228 | 228 | 'name' => 'invalidResolveTypeMutation', |
229 | 229 | 'type' => new NonNullType(new IntType()), |
230 | - 'resolve' => function () { |
|
230 | + 'resolve' => function() { |
|
231 | 231 | return null; |
232 | 232 | } |
233 | 233 | ]))->addField(new Field([ |
234 | 234 | 'name' => 'interfacedMutation', |
235 | 235 | 'type' => new TestInterfaceType(), |
236 | - 'resolve' => function () { |
|
236 | + 'resolve' => function() { |
|
237 | 237 | return ['name' => 'John']; |
238 | 238 | } |
239 | 239 | ])); |
@@ -279,43 +279,43 @@ discard block |
||
279 | 279 | 'fields' => [ |
280 | 280 | 'listQuery' => [ |
281 | 281 | 'type' => new ListType(new TestEnumType()), |
282 | - 'resolve' => function () { |
|
282 | + 'resolve' => function() { |
|
283 | 283 | return 'invalid list'; |
284 | 284 | } |
285 | 285 | ], |
286 | 286 | 'listEnumQuery' => [ |
287 | 287 | 'type' => new ListType(new TestEnumType()), |
288 | - 'resolve' => function () { |
|
288 | + 'resolve' => function() { |
|
289 | 289 | return ['invalid enum']; |
290 | 290 | } |
291 | 291 | ], |
292 | 292 | 'invalidEnumQuery' => [ |
293 | 293 | 'type' => new TestEnumType(), |
294 | - 'resolve' => function () { |
|
294 | + 'resolve' => function() { |
|
295 | 295 | return 'invalid enum'; |
296 | 296 | } |
297 | 297 | ], |
298 | 298 | 'enumQuery' => [ |
299 | 299 | 'type' => new TestEnumType(), |
300 | - 'resolve' => function () { |
|
300 | + 'resolve' => function() { |
|
301 | 301 | return 1; |
302 | 302 | } |
303 | 303 | ], |
304 | 304 | 'invalidNonNullQuery' => [ |
305 | 305 | 'type' => new NonNullType(new IntType()), |
306 | - 'resolve' => function () { |
|
306 | + 'resolve' => function() { |
|
307 | 307 | return null; |
308 | 308 | } |
309 | 309 | ], |
310 | 310 | 'invalidNonNullInsideQuery' => [ |
311 | 311 | 'type' => new NonNullType(new IntType()), |
312 | - 'resolve' => function () { |
|
312 | + 'resolve' => function() { |
|
313 | 313 | return 'hello'; |
314 | 314 | } |
315 | 315 | ], |
316 | 316 | 'objectQuery' => [ |
317 | 317 | 'type' => new TestObjectType(), |
318 | - 'resolve' => function () { |
|
318 | + 'resolve' => function() { |
|
319 | 319 | return ['name' => 'John']; |
320 | 320 | } |
321 | 321 | ], |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | 'enum' => new TestEnumType(), |
328 | 328 | ], |
329 | 329 | ]), |
330 | - 'resolve' => function () { |
|
330 | + 'resolve' => function() { |
|
331 | 331 | return [ |
332 | 332 | 'object' => [ |
333 | 333 | 'name' => 'John' |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | ] |
397 | 397 | ]); |
398 | 398 | |
399 | - $union = new UnionType([ |
|
399 | + $union = new UnionType([ |
|
400 | 400 | 'name' => 'TestUnion', |
401 | 401 | 'types' => [$object1, $object2], |
402 | - 'resolveType' => function ($object) use ($object1, $object2) { |
|
402 | + 'resolveType' => function($object) use ($object1, $object2) { |
|
403 | 403 | if (isset($object['id'])) { |
404 | 404 | return $object1; |
405 | 405 | } |
@@ -410,11 +410,11 @@ discard block |
||
410 | 410 | $invalidUnion = new UnionType([ |
411 | 411 | 'name' => 'TestUnion', |
412 | 412 | 'types' => [$object1, $object2], |
413 | - 'resolveType' => function ($object) use ($object3) { |
|
413 | + 'resolveType' => function($object) use ($object3) { |
|
414 | 414 | return $object3; |
415 | 415 | } |
416 | 416 | ]); |
417 | - $processor = new Processor(new Schema([ |
|
417 | + $processor = new Processor(new Schema([ |
|
418 | 418 | 'query' => new ObjectType([ |
419 | 419 | 'name' => 'RootQuery', |
420 | 420 | 'fields' => [ |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | 'type' => ['type' => 'string'] |
425 | 425 | ], |
426 | 426 | 'cost' => 10, |
427 | - 'resolve' => function ($value, $args) { |
|
427 | + 'resolve' => function($value, $args) { |
|
428 | 428 | if ($args['type'] == 'object1') { |
429 | 429 | return [ |
430 | 430 | 'id' => 43 |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | ], |
439 | 439 | 'invalidUnion' => [ |
440 | 440 | 'type' => $invalidUnion, |
441 | - 'resolve' => function () { |
|
441 | + 'resolve' => function() { |
|
442 | 442 | return ['name' => 'name resolved']; |
443 | 443 | } |
444 | 444 | ], |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | 'args' => [ |
499 | 499 | 'shorten' => new BooleanType() |
500 | 500 | ], |
501 | - 'resolve' => function ($value, $args) { |
|
501 | + 'resolve' => function($value, $args) { |
|
502 | 502 | return empty($args['shorten']) ? $value : $value; |
503 | 503 | } |
504 | 504 | ], |
@@ -507,18 +507,18 @@ discard block |
||
507 | 507 | 'likes' => [ |
508 | 508 | 'type' => new IntType(), |
509 | 509 | 'cost' => 10, |
510 | - 'resolve' => function () { |
|
510 | + 'resolve' => function() { |
|
511 | 511 | return 42; |
512 | 512 | } |
513 | 513 | ] |
514 | 514 | ] |
515 | 515 | ] |
516 | 516 | ), |
517 | - 'cost' => function ($args, $context, $childCost) { |
|
517 | + 'cost' => function($args, $context, $childCost) { |
|
518 | 518 | $argsCost = isset($args['cost']) ? $args['cost'] : 1; |
519 | 519 | return 1 + $argsCost * $childCost; |
520 | 520 | }, |
521 | - 'resolve' => function ($value, $args) { |
|
521 | + 'resolve' => function($value, $args) { |
|
522 | 522 | $data = ['firstName' => 'John', 'code' => '007']; |
523 | 523 | |
524 | 524 | return $data; |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | $processor->processPayload('{ me { badfield } }'); |
550 | 550 | $this->assertArraySubset(['errors' => [['message' => 'Field "badfield" not found in type "User"']]], $processor->getResponseData()); |
551 | 551 | |
552 | - foreach (range(1,5) as $cost_multiplier) { |
|
552 | + foreach (range(1, 5) as $cost_multiplier) { |
|
553 | 553 | $visitor = new \Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor(1000); // arbitrarily high cost |
554 | 554 | $processor->processPayload("{ me (cost: $cost_multiplier) { firstName, lastName, code, likes } }", ['cost' => $cost_multiplier], [$visitor]); |
555 | 555 | $expected = 1 + 13 * (1 + $cost_multiplier); |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | $this->assertEquals(['data' => ['labels' => ['one', 'two']]], $processor->getResponseData()); |
213 | 213 | |
214 | 214 | $schema->getMutationType() |
215 | - ->addField(new Field([ |
|
216 | - 'name' => 'increaseCounter', |
|
217 | - 'type' => new IntType(), |
|
218 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
219 | - return $this->_counter += $args['amount']; |
|
220 | - }, |
|
221 | - 'args' => [ |
|
222 | - 'amount' => [ |
|
223 | - 'type' => new IntType(), |
|
224 | - 'default' => 1 |
|
225 | - ] |
|
226 | - ] |
|
227 | - ]))->addField(new Field([ |
|
215 | + ->addField(new Field([ |
|
216 | + 'name' => 'increaseCounter', |
|
217 | + 'type' => new IntType(), |
|
218 | + 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
219 | + return $this->_counter += $args['amount']; |
|
220 | + }, |
|
221 | + 'args' => [ |
|
222 | + 'amount' => [ |
|
223 | + 'type' => new IntType(), |
|
224 | + 'default' => 1 |
|
225 | + ] |
|
226 | + ] |
|
227 | + ]))->addField(new Field([ |
|
228 | 228 | 'name' => 'invalidResolveTypeMutation', |
229 | 229 | 'type' => new NonNullType(new IntType()), |
230 | 230 | 'resolve' => function () { |
@@ -482,82 +482,82 @@ discard block |
||
482 | 482 | } |
483 | 483 | |
484 | 484 | public function testComplexityReducer() { |
485 | - $schema = new Schema( |
|
486 | - [ |
|
487 | - 'query' => new ObjectType( |
|
488 | - [ |
|
489 | - 'name' => 'RootQuery', |
|
490 | - 'fields' => [ |
|
491 | - 'me' => [ |
|
492 | - 'type' => new ObjectType( |
|
493 | - [ |
|
494 | - 'name' => 'User', |
|
495 | - 'fields' => [ |
|
496 | - 'firstName' => [ |
|
497 | - 'type' => new StringType(), |
|
498 | - 'args' => [ |
|
499 | - 'shorten' => new BooleanType() |
|
500 | - ], |
|
501 | - 'resolve' => function ($value, $args) { |
|
485 | + $schema = new Schema( |
|
486 | + [ |
|
487 | + 'query' => new ObjectType( |
|
488 | + [ |
|
489 | + 'name' => 'RootQuery', |
|
490 | + 'fields' => [ |
|
491 | + 'me' => [ |
|
492 | + 'type' => new ObjectType( |
|
493 | + [ |
|
494 | + 'name' => 'User', |
|
495 | + 'fields' => [ |
|
496 | + 'firstName' => [ |
|
497 | + 'type' => new StringType(), |
|
498 | + 'args' => [ |
|
499 | + 'shorten' => new BooleanType() |
|
500 | + ], |
|
501 | + 'resolve' => function ($value, $args) { |
|
502 | 502 | return empty($args['shorten']) ? $value : $value; |
503 | - } |
|
504 | - ], |
|
505 | - 'lastName' => new StringType(), |
|
506 | - 'code' => new StringType(), |
|
507 | - 'likes' => [ |
|
508 | - 'type' => new IntType(), |
|
509 | - 'cost' => 10, |
|
510 | - 'resolve' => function () { |
|
503 | + } |
|
504 | + ], |
|
505 | + 'lastName' => new StringType(), |
|
506 | + 'code' => new StringType(), |
|
507 | + 'likes' => [ |
|
508 | + 'type' => new IntType(), |
|
509 | + 'cost' => 10, |
|
510 | + 'resolve' => function () { |
|
511 | 511 | return 42; |
512 | - } |
|
513 | - ] |
|
514 | - ] |
|
515 | - ] |
|
516 | - ), |
|
517 | - 'cost' => function ($args, $context, $childCost) { |
|
512 | + } |
|
513 | + ] |
|
514 | + ] |
|
515 | + ] |
|
516 | + ), |
|
517 | + 'cost' => function ($args, $context, $childCost) { |
|
518 | 518 | $argsCost = isset($args['cost']) ? $args['cost'] : 1; |
519 | 519 | return 1 + $argsCost * $childCost; |
520 | - }, |
|
521 | - 'resolve' => function ($value, $args) { |
|
520 | + }, |
|
521 | + 'resolve' => function ($value, $args) { |
|
522 | 522 | $data = ['firstName' => 'John', 'code' => '007']; |
523 | 523 | |
524 | 524 | return $data; |
525 | - }, |
|
526 | - 'args' => [ |
|
527 | - 'cost' => [ |
|
528 | - 'type' => new IntType(), |
|
529 | - 'default' => 1 |
|
530 | - ] |
|
531 | - ] |
|
532 | - ] |
|
533 | - ] |
|
534 | - ] |
|
535 | - ) |
|
536 | - ] |
|
537 | - ); |
|
538 | - $processor = new Processor($schema); |
|
539 | - |
|
540 | - $processor->setMaxComplexity(10); |
|
541 | - |
|
542 | - $processor->processPayload('{ me { firstName, lastName } }'); |
|
543 | - $this->assertArrayNotHasKey('error', $processor->getResponseData()); |
|
544 | - |
|
545 | - $processor->processPayload('{ me { firstName, likes } }'); |
|
546 | - $this->assertEquals(['errors' => [['message' => 'query exceeded max allowed complexity of 10']]], $processor->getResponseData()); |
|
547 | - |
|
548 | - // don't let complexity reducer affect query errors |
|
549 | - $processor->processPayload('{ me { badfield } }'); |
|
550 | - $this->assertArraySubset(['errors' => [['message' => 'Field "badfield" is not found in type "User"']]], $processor->getResponseData()); |
|
525 | + }, |
|
526 | + 'args' => [ |
|
527 | + 'cost' => [ |
|
528 | + 'type' => new IntType(), |
|
529 | + 'default' => 1 |
|
530 | + ] |
|
531 | + ] |
|
532 | + ] |
|
533 | + ] |
|
534 | + ] |
|
535 | + ) |
|
536 | + ] |
|
537 | + ); |
|
538 | + $processor = new Processor($schema); |
|
551 | 539 | |
552 | - foreach (range(1,5) as $cost_multiplier) { |
|
540 | + $processor->setMaxComplexity(10); |
|
541 | + |
|
542 | + $processor->processPayload('{ me { firstName, lastName } }'); |
|
543 | + $this->assertArrayNotHasKey('error', $processor->getResponseData()); |
|
544 | + |
|
545 | + $processor->processPayload('{ me { firstName, likes } }'); |
|
546 | + $this->assertEquals(['errors' => [['message' => 'query exceeded max allowed complexity of 10']]], $processor->getResponseData()); |
|
547 | + |
|
548 | + // don't let complexity reducer affect query errors |
|
549 | + $processor->processPayload('{ me { badfield } }'); |
|
550 | + $this->assertArraySubset(['errors' => [['message' => 'Field "badfield" is not found in type "User"']]], $processor->getResponseData()); |
|
551 | + |
|
552 | + foreach (range(1,5) as $cost_multiplier) { |
|
553 | 553 | $visitor = new \Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor(1000); // arbitrarily high cost |
554 | 554 | $processor->processPayload("{ me (cost: $cost_multiplier) { firstName, lastName, code, likes } }", ['cost' => $cost_multiplier], [$visitor]); |
555 | 555 | $expected = 1 + 13 * (1 + $cost_multiplier); |
556 | 556 | $this->assertEquals($expected, $visitor->getMemo()); |
557 | - } |
|
557 | + } |
|
558 | 558 | |
559 | - // TODO, variables not yet supported |
|
560 | - /*$query = 'query costQuery ($cost: Int) { me (cost: $cost) { firstName, lastName, code, likes } }'; |
|
559 | + // TODO, variables not yet supported |
|
560 | + /*$query = 'query costQuery ($cost: Int) { me (cost: $cost) { firstName, lastName, code, likes } }'; |
|
561 | 561 | foreach (range(1,5) as $cost_multiplier) { |
562 | 562 | $visitor = new \Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor(1000); // arbitrarily high cost |
563 | 563 | $processor->processPayload($query, ['cost' => $cost_multiplier], [$visitor]); |
@@ -29,38 +29,38 @@ |
||
29 | 29 | |
30 | 30 | abstract class AbstractQueryVisitor { |
31 | 31 | |
32 | - /** |
|
33 | - * @var int initial value of $this->memo |
|
34 | - */ |
|
35 | - protected $initialValue = 0; |
|
32 | + /** |
|
33 | + * @var int initial value of $this->memo |
|
34 | + */ |
|
35 | + protected $initialValue = 0; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var mixed the accumulator |
|
39 | - */ |
|
40 | - protected $memo; |
|
37 | + /** |
|
38 | + * @var mixed the accumulator |
|
39 | + */ |
|
40 | + protected $memo; |
|
41 | 41 | |
42 | - /** |
|
43 | - * AbstractQueryVisitor constructor. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
42 | + /** |
|
43 | + * AbstractQueryVisitor constructor. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | 46 | $this->memo = $this->initialValue; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return mixed getter for the memo, in case callers want to inspect it after a process run |
|
51 | - */ |
|
52 | - public function getMemo() { |
|
49 | + /** |
|
50 | + * @return mixed getter for the memo, in case callers want to inspect it after a process run |
|
51 | + */ |
|
52 | + public function getMemo() { |
|
53 | 53 | return $this->memo; |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Visit a query node. See class docstring. |
|
58 | - * |
|
59 | - * @param array $args |
|
60 | - * @param FieldConfig $fieldConfig |
|
61 | - * @param int $childScore |
|
62 | - * |
|
63 | - * @return int|null |
|
64 | - */ |
|
65 | - abstract public function visit(array $args, FieldConfig $fieldConfig, $childScore = 0); |
|
56 | + /** |
|
57 | + * Visit a query node. See class docstring. |
|
58 | + * |
|
59 | + * @param array $args |
|
60 | + * @param FieldConfig $fieldConfig |
|
61 | + * @param int $childScore |
|
62 | + * |
|
63 | + * @return int|null |
|
64 | + */ |
|
65 | + abstract public function visit(array $args, FieldConfig $fieldConfig, $childScore = 0); |
|
66 | 66 | } |
67 | 67 | \ No newline at end of file |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | $authors = []; |
44 | 44 | while (count($authors) < rand(1, 4)) { |
45 | 45 | $authors[] = [ |
46 | - 'name' => 'Author ' . substr(md5(time()), 0, 4) |
|
46 | + 'name' => 'Author '.substr(md5(time()), 0, 4) |
|
47 | 47 | ]; |
48 | 48 | } |
49 | 49 | $data[] = [ |
50 | 50 | 'id' => $i, |
51 | - 'title' => 'Title of ' . $i, |
|
51 | + 'title' => 'Title of '.$i, |
|
52 | 52 | 'authors' => $authors, |
53 | 53 | ]; |
54 | 54 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | // return true; |
70 | 70 | $p->processPayload('{ posts { id, title, authors { name } } }'); |
71 | 71 | $res = $p->getResponseData(); |
72 | - echo "Count: " . count($res['data']['posts']) . "\n"; |
|
72 | + echo "Count: ".count($res['data']['posts'])."\n"; |
|
73 | 73 | printf("Test Time: %04f\n", microtime(true) - $time); |
74 | 74 | // $p->getResponseData(); |
75 | 75 | } |
@@ -9,13 +9,7 @@ discard block |
||
9 | 9 | namespace Youshido\Tests\Library\Type; |
10 | 10 | |
11 | 11 | |
12 | -use Youshido\GraphQL\Execution\Context\ExecutionContext; |
|
13 | 12 | use Youshido\GraphQL\Execution\Processor; |
14 | -use Youshido\GraphQL\Execution\Request; |
|
15 | -use Youshido\GraphQL\Field\Field; |
|
16 | -use Youshido\GraphQL\Parser\Ast\Argument; |
|
17 | -use Youshido\GraphQL\Parser\Ast\ArgumentValue\Literal; |
|
18 | -use Youshido\GraphQL\Parser\Ast\Query; |
|
19 | 13 | use Youshido\GraphQL\Schema\Schema; |
20 | 14 | use Youshido\GraphQL\Type\InputObject\InputObjectType; |
21 | 15 | use Youshido\GraphQL\Type\ListType\ListType; |
@@ -24,7 +18,6 @@ discard block |
||
24 | 18 | use Youshido\GraphQL\Type\Scalar\BooleanType; |
25 | 19 | use Youshido\GraphQL\Type\Scalar\StringType; |
26 | 20 | use Youshido\GraphQL\Type\TypeMap; |
27 | -use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidator; |
|
28 | 21 | use Youshido\Tests\DataProvider\TestInputObjectType; |
29 | 22 | |
30 | 23 | class InputObjectTypeTest extends \PHPUnit_Framework_TestCase |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | 'fields' => [ |
61 | 61 | 'empty' => [ |
62 | 62 | 'type' => new StringType(), |
63 | - 'resolve' => function () { |
|
63 | + 'resolve' => function() { |
|
64 | 64 | return null; |
65 | 65 | } |
66 | 66 | ] |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ])) |
80 | 80 | ], |
81 | 81 | 'type' => new BooleanType(), |
82 | - 'resolve' => function ($object, $args) { |
|
82 | + 'resolve' => function($object, $args) { |
|
83 | 83 | return true; |
84 | 84 | } |
85 | 85 | ] |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | 'fields' => [ |
101 | 101 | 'empty' => [ |
102 | 102 | 'type' => new StringType(), |
103 | - 'resolve' => function () { } |
|
103 | + 'resolve' => function() { } |
|
104 | 104 | ], |
105 | 105 | ] |
106 | 106 | ]), |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ] |
123 | 123 | ]) |
124 | 124 | ], |
125 | - 'resolve' => function () { return 'success message'; } |
|
125 | + 'resolve' => function() { return 'success message'; } |
|
126 | 126 | ] |
127 | 127 | ] |
128 | 128 | ]) |
@@ -35,7 +35,7 @@ |
||
35 | 35 | $isValid = is_null($value) || is_array($value) || (is_object($value) && in_array('IteratorAggregate', class_implements($value))); |
36 | 36 | $itemType = $this->config->get('itemType'); |
37 | 37 | if ($isValid && $itemType->isInputType()) { |
38 | - foreach($value as $item) { |
|
38 | + foreach ($value as $item) { |
|
39 | 39 | $isValid = $itemType->isValidValue($item); |
40 | 40 | if (!$isValid) return false; |
41 | 41 | } |
@@ -37,7 +37,9 @@ |
||
37 | 37 | if ($isValid && $itemType->isInputType()) { |
38 | 38 | foreach($value as $item) { |
39 | 39 | $isValid = $itemType->isValidValue($item); |
40 | - if (!$isValid) return false; |
|
40 | + if (!$isValid) { |
|
41 | + return false; |
|
42 | + } |
|
41 | 43 | } |
42 | 44 | } |
43 | 45 | return $isValid; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | if ($value && $value->getKind() == TypeMap::KIND_ENUM) { |
59 | 59 | $data = []; |
60 | 60 | foreach ($value->getValues() as $enumValue) { |
61 | - if(!$args['includeDeprecated'] && (isset($enumValue['isDeprecated']) && $enumValue['isDeprecated'])) { |
|
61 | + if (!$args['includeDeprecated'] && (isset($enumValue['isDeprecated']) && $enumValue['isDeprecated'])) { |
|
62 | 62 | continue; |
63 | 63 | } |
64 | 64 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** @var AbstractObjectType $value */ |
94 | - return array_filter($value->getConfig()->getFields(), function ($field) use ($args) { |
|
94 | + return array_filter($value->getConfig()->getFields(), function($field) use ($args) { |
|
95 | 95 | /** @var $field Field */ |
96 | 96 | if (in_array($field->getName(), ['__type', '__schema']) || (!$args['includeDeprecated'] && $field->isDeprecated())) { |
97 | 97 | return false; |