@@ -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; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $edgeFields = !empty($config['edgeFields']) ? $config['edgeFields'] : []; |
| 53 | 53 | |
| 54 | 54 | $edgeType = new ObjectType([ |
| 55 | - 'name' => $name . 'Edge', |
|
| 55 | + 'name' => $name.'Edge', |
|
| 56 | 56 | 'description' => 'An edge in a connection.', |
| 57 | 57 | 'fields' => array_merge([ |
| 58 | 58 | 'node' => [ |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $connectionFields = !empty($config['connectionFields']) ? $config['connectionFields'] : []; |
| 85 | 85 | |
| 86 | 86 | $connectionType = new ObjectType([ |
| 87 | - 'name' => $name . 'Connection', |
|
| 87 | + 'name' => $name.'Connection', |
|
| 88 | 88 | 'description' => 'A connection to a list of items.', |
| 89 | 89 | 'fields' => array_merge([ |
| 90 | 90 | 'pageInfo' => [ |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | if (!is_array($types)) { |
| 25 | 25 | throw new \Exception('addTypes accept only array of types'); |
| 26 | 26 | } |
| 27 | - foreach($types as $type) { |
|
| 27 | + foreach ($types as $type) { |
|
| 28 | 28 | $this->addType($type); |
| 29 | 29 | } |
| 30 | 30 | return $this; |
@@ -42,7 +42,9 @@ discard block |
||
| 42 | 42 | public function addType(TypeInterface $type) |
| 43 | 43 | { |
| 44 | 44 | $typeName = $this->getTypeName($type); |
| 45 | - if ($this->isTypeNameRegistered($typeName)) return $this; |
|
| 45 | + if ($this->isTypeNameRegistered($typeName)) { |
|
| 46 | + return $this; |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | $this->typesList[$typeName] = $type; |
| 48 | 50 | return $this; |
@@ -54,7 +56,9 @@ discard block |
||
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | private function getTypeName($type) { |
| 57 | - if (is_string($type)) return $type; |
|
| 59 | + if (is_string($type)) { |
|
| 60 | + return $type; |
|
| 61 | + } |
|
| 58 | 62 | if (is_object($type) && $type instanceof AbstractType) { |
| 59 | 63 | return $type->getName(); |
| 60 | 64 | } |
@@ -2,13 +2,13 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace BlogTest; |
| 4 | 4 | |
| 5 | -require_once __DIR__ . '/../../../../../vendor/autoload.php'; |
|
| 6 | -require_once __DIR__ . '/Schema/DataProvider.php'; |
|
| 7 | -require_once __DIR__ . '/Schema/PostType.php'; |
|
| 8 | -require_once __DIR__ . '/Schema/PostStatus.php'; |
|
| 9 | -require_once __DIR__ . '/Schema/ContentBlockInterface.php'; |
|
| 10 | -require_once __DIR__ . '/Schema/LikePostField.php'; |
|
| 11 | -require_once __DIR__ . '/Schema/BannerType.php'; |
|
| 12 | -require_once __DIR__ . '/Schema/ContentBlockUnion.php'; |
|
| 13 | -require_once __DIR__ . '/Schema/PostInputType.php'; |
|
| 14 | -require_once __DIR__ . '/Schema/BlogSchema.php'; |
|
| 5 | +require_once __DIR__.'/../../../../../vendor/autoload.php'; |
|
| 6 | +require_once __DIR__.'/Schema/DataProvider.php'; |
|
| 7 | +require_once __DIR__.'/Schema/PostType.php'; |
|
| 8 | +require_once __DIR__.'/Schema/PostStatus.php'; |
|
| 9 | +require_once __DIR__.'/Schema/ContentBlockInterface.php'; |
|
| 10 | +require_once __DIR__.'/Schema/LikePostField.php'; |
|
| 11 | +require_once __DIR__.'/Schema/BannerType.php'; |
|
| 12 | +require_once __DIR__.'/Schema/ContentBlockUnion.php'; |
|
| 13 | +require_once __DIR__.'/Schema/PostInputType.php'; |
|
| 14 | +require_once __DIR__.'/Schema/BlogSchema.php'; |
|
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | use Youshido\GraphQL\Type\Object\ObjectType; |
| 8 | 8 | |
| 9 | 9 | |
| 10 | -require_once __DIR__ . '/../../../../../vendor/autoload.php'; |
|
| 11 | -require_once __DIR__ . '/inline-schema.php'; |
|
| 10 | +require_once __DIR__.'/../../../../../vendor/autoload.php'; |
|
| 11 | +require_once __DIR__.'/inline-schema.php'; |
|
| 12 | 12 | /** @var ObjectType $rootQueryType */ |
| 13 | 13 | |
| 14 | 14 | $processor = new Processor(new Schema([ |
@@ -17,4 +17,4 @@ discard block |
||
| 17 | 17 | $payload = '{ latestPost { title(truncated: true), summary } }'; |
| 18 | 18 | |
| 19 | 19 | $processor->processPayload($payload); |
| 20 | -echo json_encode($processor->getResponseData()) . "\n"; |
|
| 20 | +echo json_encode($processor->getResponseData())."\n"; |
|
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use Youshido\GraphQL\Type\Object\ObjectType; |
| 7 | 7 | use Youshido\GraphQL\Type\Scalar\StringType; |
| 8 | 8 | |
| 9 | -require_once __DIR__ . '/../../../../../vendor/autoload.php'; |
|
| 9 | +require_once __DIR__.'/../../../../../vendor/autoload.php'; |
|
| 10 | 10 | |
| 11 | 11 | $processor = new Processor(new Schema([ |
| 12 | 12 | 'query' => new ObjectType([ |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | 'fields' => [ |
| 15 | 15 | 'currentTime' => [ |
| 16 | 16 | 'type' => new StringType(), |
| 17 | - 'resolve' => function () { |
|
| 17 | + 'resolve' => function() { |
|
| 18 | 18 | return date('Y-m-d H:ia'); |
| 19 | 19 | } |
| 20 | 20 | ] |
@@ -23,4 +23,4 @@ discard block |
||
| 23 | 23 | ])); |
| 24 | 24 | |
| 25 | 25 | $processor->processPayload('{ currentTime }'); |
| 26 | -echo json_encode($processor->getResponseData()) . "\n"; |
|
| 26 | +echo json_encode($processor->getResponseData())."\n"; |
|
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | $this->memo += $cost; |
| 54 | 54 | |
| 55 | 55 | if ($this->memo > $this->maxScore) { |
| 56 | - throw new \Exception('query exceeded max allowed complexity of ' . $this->maxScore); |
|
| 56 | + throw new \Exception('query exceeded max allowed complexity of '.$this->maxScore); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | return $cost; |
@@ -14,6 +14,9 @@ |
||
| 14 | 14 | trait ResolvableObjectTrait |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | + /** |
|
| 18 | + * @param string|boolean $value |
|
| 19 | + */ |
|
| 17 | 20 | public function resolve($value, array $args, ResolveInfo $info) |
| 18 | 21 | { |
| 19 | 22 | if ($resolveFunction = $this->getConfig()->getResolveFunction()) { |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | 'fields' => [ |
| 97 | 97 | 'list' => [ |
| 98 | 98 | 'type' => new ListType(new StringType()), |
| 99 | - 'resolve' => function () { |
|
| 99 | + 'resolve' => function() { |
|
| 100 | 100 | return null; |
| 101 | 101 | } |
| 102 | 102 | ] |
| 103 | 103 | ] |
| 104 | 104 | ]) |
| 105 | 105 | ])); |
| 106 | - $data = $processor->processPayload(' { list }')->getResponseData(); |
|
| 106 | + $data = $processor->processPayload(' { list }')->getResponseData(); |
|
| 107 | 107 | $this->assertEquals(['data' => ['list' => null]], $data); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -116,20 +116,20 @@ discard block |
||
| 116 | 116 | 'fields' => [ |
| 117 | 117 | 'list' => [ |
| 118 | 118 | 'type' => new ListType(new StringType()), |
| 119 | - 'resolve' => function () { |
|
| 119 | + 'resolve' => function() { |
|
| 120 | 120 | return null; |
| 121 | 121 | } |
| 122 | 122 | ] |
| 123 | 123 | ] |
| 124 | 124 | ]) |
| 125 | 125 | ])); |
| 126 | - $data = $processor->processPayload(' { __schema { subscriptionType { name } } }')->getResponseData(); |
|
| 126 | + $data = $processor->processPayload(' { __schema { subscriptionType { name } } }')->getResponseData(); |
|
| 127 | 127 | $this->assertEquals(['data' => ['__schema' => ['subscriptionType' => null]]], $data); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | public function testSchemaOperations() |
| 131 | 131 | { |
| 132 | - $schema = new Schema([ |
|
| 132 | + $schema = new Schema([ |
|
| 133 | 133 | 'query' => new ObjectType([ |
| 134 | 134 | 'name' => 'RootQuery', |
| 135 | 135 | 'fields' => [ |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | 'args' => [ |
| 143 | 143 | 'shorten' => new BooleanType() |
| 144 | 144 | ], |
| 145 | - 'resolve' => function ($value, $args) { |
|
| 145 | + 'resolve' => function($value, $args) { |
|
| 146 | 146 | return empty($args['shorten']) ? $value['firstName'] : $value['firstName']; |
| 147 | 147 | } |
| 148 | 148 | ], |
| 149 | 149 | 'id_alias' => [ |
| 150 | 150 | 'type' => new IdType(), |
| 151 | - 'resolve' => function ($value) { |
|
| 151 | + 'resolve' => function($value) { |
|
| 152 | 152 | return $value['id']; |
| 153 | 153 | } |
| 154 | 154 | ], |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | 'code' => new StringType(), |
| 157 | 157 | ] |
| 158 | 158 | ]), |
| 159 | - 'resolve' => function ($value, $args) { |
|
| 159 | + 'resolve' => function($value, $args) { |
|
| 160 | 160 | $data = ['id' => '123', 'firstName' => 'John', 'code' => '007']; |
| 161 | 161 | if (!empty($args['upper'])) { |
| 162 | 162 | foreach ($data as $key => $value) { |
@@ -175,19 +175,19 @@ discard block |
||
| 175 | 175 | ], |
| 176 | 176 | 'randomUser' => [ |
| 177 | 177 | 'type' => new TestObjectType(), |
| 178 | - 'resolve' => function () { |
|
| 178 | + 'resolve' => function() { |
|
| 179 | 179 | return ['invalidField' => 'John']; |
| 180 | 180 | } |
| 181 | 181 | ], |
| 182 | 182 | 'invalidValueQuery' => [ |
| 183 | 183 | 'type' => new TestObjectType(), |
| 184 | - 'resolve' => function () { |
|
| 184 | + 'resolve' => function() { |
|
| 185 | 185 | return 'stringValue'; |
| 186 | 186 | } |
| 187 | 187 | ], |
| 188 | 188 | 'labels' => [ |
| 189 | 189 | 'type' => new ListType(new StringType()), |
| 190 | - 'resolve' => function () { |
|
| 190 | + 'resolve' => function() { |
|
| 191 | 191 | return ['one', 'two']; |
| 192 | 192 | } |
| 193 | 193 | ] |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | ->addField(new Field([ |
| 219 | 219 | 'name' => 'increaseCounter', |
| 220 | 220 | 'type' => new IntType(), |
| 221 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
| 221 | + 'resolve' => function($value, $args, ResolveInfo $info) { |
|
| 222 | 222 | return $this->_counter += $args['amount']; |
| 223 | 223 | }, |
| 224 | 224 | 'args' => [ |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | ]))->addField(new Field([ |
| 231 | 231 | 'name' => 'invalidResolveTypeMutation', |
| 232 | 232 | 'type' => new NonNullType(new IntType()), |
| 233 | - 'resolve' => function () { |
|
| 233 | + 'resolve' => function() { |
|
| 234 | 234 | return null; |
| 235 | 235 | } |
| 236 | 236 | ]))->addField(new Field([ |
| 237 | 237 | 'name' => 'interfacedMutation', |
| 238 | 238 | 'type' => new TestInterfaceType(), |
| 239 | - 'resolve' => function () { |
|
| 239 | + 'resolve' => function() { |
|
| 240 | 240 | return ['name' => 'John']; |
| 241 | 241 | } |
| 242 | 242 | ])); |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | ])) |
| 318 | 318 | ], |
| 319 | 319 | 'type' => new StringType(), |
| 320 | - 'resolve' => function ($value, $args) { |
|
| 320 | + 'resolve' => function($value, $args) { |
|
| 321 | 321 | return $args['argument1']; |
| 322 | 322 | } |
| 323 | 323 | ] |
@@ -362,43 +362,43 @@ discard block |
||
| 362 | 362 | 'fields' => [ |
| 363 | 363 | 'listQuery' => [ |
| 364 | 364 | 'type' => new ListType(new TestEnumType()), |
| 365 | - 'resolve' => function () { |
|
| 365 | + 'resolve' => function() { |
|
| 366 | 366 | return 'invalid list'; |
| 367 | 367 | } |
| 368 | 368 | ], |
| 369 | 369 | 'listEnumQuery' => [ |
| 370 | 370 | 'type' => new ListType(new TestEnumType()), |
| 371 | - 'resolve' => function () { |
|
| 371 | + 'resolve' => function() { |
|
| 372 | 372 | return ['invalid enum']; |
| 373 | 373 | } |
| 374 | 374 | ], |
| 375 | 375 | 'invalidEnumQuery' => [ |
| 376 | 376 | 'type' => new TestEnumType(), |
| 377 | - 'resolve' => function () { |
|
| 377 | + 'resolve' => function() { |
|
| 378 | 378 | return 'invalid enum'; |
| 379 | 379 | } |
| 380 | 380 | ], |
| 381 | 381 | 'enumQuery' => [ |
| 382 | 382 | 'type' => new TestEnumType(), |
| 383 | - 'resolve' => function () { |
|
| 383 | + 'resolve' => function() { |
|
| 384 | 384 | return 1; |
| 385 | 385 | } |
| 386 | 386 | ], |
| 387 | 387 | 'invalidNonNullQuery' => [ |
| 388 | 388 | 'type' => new NonNullType(new IntType()), |
| 389 | - 'resolve' => function () { |
|
| 389 | + 'resolve' => function() { |
|
| 390 | 390 | return null; |
| 391 | 391 | } |
| 392 | 392 | ], |
| 393 | 393 | 'invalidNonNullInsideQuery' => [ |
| 394 | 394 | 'type' => new NonNullType(new IntType()), |
| 395 | - 'resolve' => function () { |
|
| 395 | + 'resolve' => function() { |
|
| 396 | 396 | return 'hello'; |
| 397 | 397 | } |
| 398 | 398 | ], |
| 399 | 399 | 'objectQuery' => [ |
| 400 | 400 | 'type' => new TestObjectType(), |
| 401 | - 'resolve' => function () { |
|
| 401 | + 'resolve' => function() { |
|
| 402 | 402 | return ['name' => 'John']; |
| 403 | 403 | } |
| 404 | 404 | ], |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | 'enum' => new TestEnumType(), |
| 411 | 411 | ], |
| 412 | 412 | ]), |
| 413 | - 'resolve' => function () { |
|
| 413 | + 'resolve' => function() { |
|
| 414 | 414 | return [ |
| 415 | 415 | 'object' => [ |
| 416 | 416 | 'name' => 'John' |
@@ -489,10 +489,10 @@ discard block |
||
| 489 | 489 | ] |
| 490 | 490 | ]); |
| 491 | 491 | |
| 492 | - $union = new UnionType([ |
|
| 492 | + $union = new UnionType([ |
|
| 493 | 493 | 'name' => 'TestUnion', |
| 494 | 494 | 'types' => [$object1, $object2], |
| 495 | - 'resolveType' => function ($object) use ($object1, $object2) { |
|
| 495 | + 'resolveType' => function($object) use ($object1, $object2) { |
|
| 496 | 496 | if (isset($object['id'])) { |
| 497 | 497 | return $object1; |
| 498 | 498 | } |
@@ -503,11 +503,11 @@ discard block |
||
| 503 | 503 | $invalidUnion = new UnionType([ |
| 504 | 504 | 'name' => 'TestUnion', |
| 505 | 505 | 'types' => [$object1, $object2], |
| 506 | - 'resolveType' => function ($object) use ($object3) { |
|
| 506 | + 'resolveType' => function($object) use ($object3) { |
|
| 507 | 507 | return $object3; |
| 508 | 508 | } |
| 509 | 509 | ]); |
| 510 | - $processor = new Processor(new Schema([ |
|
| 510 | + $processor = new Processor(new Schema([ |
|
| 511 | 511 | 'query' => new ObjectType([ |
| 512 | 512 | 'name' => 'RootQuery', |
| 513 | 513 | 'fields' => [ |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | 'type' => ['type' => 'string'] |
| 518 | 518 | ], |
| 519 | 519 | 'cost' => 10, |
| 520 | - 'resolve' => function ($value, $args) { |
|
| 520 | + 'resolve' => function($value, $args) { |
|
| 521 | 521 | if ($args['type'] == 'object1') { |
| 522 | 522 | return [ |
| 523 | 523 | 'id' => 43 |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | ], |
| 532 | 532 | 'invalidUnion' => [ |
| 533 | 533 | 'type' => $invalidUnion, |
| 534 | - 'resolve' => function () { |
|
| 534 | + 'resolve' => function() { |
|
| 535 | 535 | return ['name' => 'name resolved']; |
| 536 | 536 | } |
| 537 | 537 | ], |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | 'fields' => [ |
| 594 | 594 | 'currentUser' => [ |
| 595 | 595 | 'type' => new StringType(), |
| 596 | - 'resolve' => function ($source, $args, ResolveInfo $info) { |
|
| 596 | + 'resolve' => function($source, $args, ResolveInfo $info) { |
|
| 597 | 597 | return $info->getContainer()->get('user')['name']; |
| 598 | 598 | } |
| 599 | 599 | ] |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | |
| 612 | 612 | public function testComplexityReducer() |
| 613 | 613 | { |
| 614 | - $schema = new Schema( |
|
| 614 | + $schema = new Schema( |
|
| 615 | 615 | [ |
| 616 | 616 | 'query' => new ObjectType( |
| 617 | 617 | [ |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | 'args' => [ |
| 628 | 628 | 'shorten' => new BooleanType() |
| 629 | 629 | ], |
| 630 | - 'resolve' => function ($value, $args) { |
|
| 630 | + 'resolve' => function($value, $args) { |
|
| 631 | 631 | return empty($args['shorten']) ? $value['firstName'] : $value['firstName']; |
| 632 | 632 | } |
| 633 | 633 | ], |
@@ -636,19 +636,19 @@ discard block |
||
| 636 | 636 | 'likes' => [ |
| 637 | 637 | 'type' => new IntType(), |
| 638 | 638 | 'cost' => 10, |
| 639 | - 'resolve' => function () { |
|
| 639 | + 'resolve' => function() { |
|
| 640 | 640 | return 42; |
| 641 | 641 | } |
| 642 | 642 | ] |
| 643 | 643 | ] |
| 644 | 644 | ] |
| 645 | 645 | ), |
| 646 | - 'cost' => function ($args, $context, $childCost) { |
|
| 646 | + 'cost' => function($args, $context, $childCost) { |
|
| 647 | 647 | $argsCost = isset($args['cost']) ? $args['cost'] : 1; |
| 648 | 648 | |
| 649 | 649 | return 1 + $argsCost * $childCost; |
| 650 | 650 | }, |
| 651 | - 'resolve' => function ($value, $args) { |
|
| 651 | + 'resolve' => function($value, $args) { |
|
| 652 | 652 | $data = ['firstName' => 'John', 'code' => '007']; |
| 653 | 653 | |
| 654 | 654 | return $data; |