@@ -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 | |
@@ -42,8 +42,8 @@ |
||
| 42 | 42 | public function getDescription() |
| 43 | 43 | { |
| 44 | 44 | return 'The `String` scalar type represents textual data, represented as UTF-8 ' . |
| 45 | - 'character sequences. The String type is most often used by GraphQL to ' . |
|
| 46 | - 'represent free-form human-readable text.'; |
|
| 45 | + 'character sequences. The String type is most often used by GraphQL to ' . |
|
| 46 | + 'represent free-form human-readable text.'; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | } |
@@ -29,8 +29,8 @@ |
||
| 29 | 29 | public function getDescription() |
| 30 | 30 | { |
| 31 | 31 | return 'The `Float` scalar type represents signed double-precision fractional ' . |
| 32 | - 'values as specified by ' . |
|
| 33 | - '[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).'; |
|
| 32 | + 'values as specified by ' . |
|
| 33 | + '[IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).'; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | } |
@@ -40,9 +40,9 @@ |
||
| 40 | 40 | public function getDescription() |
| 41 | 41 | { |
| 42 | 42 | return 'The `Int` scalar type represents non-fractional signed whole numeric ' . |
| 43 | - 'values. Int can represent values between -(2^53 - 1) and 2^53 - 1 since ' . |
|
| 44 | - 'represented in JSON as double-precision floating point numbers specified' . |
|
| 45 | - 'by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).'; |
|
| 43 | + 'values. Int can represent values between -(2^53 - 1) and 2^53 - 1 since ' . |
|
| 44 | + 'represented in JSON as double-precision floating point numbers specified' . |
|
| 45 | + 'by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point).'; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | } |
@@ -30,9 +30,9 @@ |
||
| 30 | 30 | public function getDescription() |
| 31 | 31 | { |
| 32 | 32 | return 'The `ID` scalar type represents a unique identifier, often used to ' . |
| 33 | - 'refetch an object or as key for a cache. The ID type appears in a JSON ' . |
|
| 34 | - 'response as a String; however, it is not intended to be human-readable. ' . |
|
| 35 | - 'When expected as an input type, any string (such as `"4"`) or integer ' . |
|
| 36 | - '(such as `4`) input value will be accepted as an ID.'; |
|
| 33 | + 'refetch an object or as key for a cache. The ID type appears in a JSON ' . |
|
| 34 | + 'response as a String; however, it is not intended to be human-readable. ' . |
|
| 35 | + 'When expected as an input type, any string (such as `"4"`) or integer ' . |
|
| 36 | + '(such as `4`) input value will be accepted as an ID.'; |
|
| 37 | 37 | } |
| 38 | 38 | } |
@@ -37,70 +37,70 @@ |
||
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | 39 | $config->getQuery() |
| 40 | - ->addField(new NodeField($fetcher)) |
|
| 41 | - ->addField('rebels', [ |
|
| 42 | - 'type' => new FactionType(), |
|
| 43 | - 'resolve' => function () { |
|
| 44 | - return TestDataProvider::getFaction('rebels'); |
|
| 45 | - } |
|
| 46 | - ]) |
|
| 47 | - ->addField('empire', [ |
|
| 48 | - 'type' => new FactionType(), |
|
| 49 | - 'resolve' => function () { |
|
| 50 | - return TestDataProvider::getFaction('empire'); |
|
| 51 | - } |
|
| 52 | - ]) |
|
| 53 | - ->addField('factions', [ |
|
| 54 | - 'type' => new ListType(new FactionType()), |
|
| 55 | - 'args' => [ |
|
| 56 | - 'names' => [ |
|
| 57 | - 'type' => new ListType(new StringType()) |
|
| 58 | - ] |
|
| 59 | - ], |
|
| 60 | - 'resolve' => function ($value = null, $args, $info) { |
|
| 61 | - return TestDataProvider::getByNames($args['names']); |
|
| 62 | - } |
|
| 63 | - ]); |
|
| 40 | + ->addField(new NodeField($fetcher)) |
|
| 41 | + ->addField('rebels', [ |
|
| 42 | + 'type' => new FactionType(), |
|
| 43 | + 'resolve' => function () { |
|
| 44 | + return TestDataProvider::getFaction('rebels'); |
|
| 45 | + } |
|
| 46 | + ]) |
|
| 47 | + ->addField('empire', [ |
|
| 48 | + 'type' => new FactionType(), |
|
| 49 | + 'resolve' => function () { |
|
| 50 | + return TestDataProvider::getFaction('empire'); |
|
| 51 | + } |
|
| 52 | + ]) |
|
| 53 | + ->addField('factions', [ |
|
| 54 | + 'type' => new ListType(new FactionType()), |
|
| 55 | + 'args' => [ |
|
| 56 | + 'names' => [ |
|
| 57 | + 'type' => new ListType(new StringType()) |
|
| 58 | + ] |
|
| 59 | + ], |
|
| 60 | + 'resolve' => function ($value = null, $args, $info) { |
|
| 61 | + return TestDataProvider::getByNames($args['names']); |
|
| 62 | + } |
|
| 63 | + ]); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | $config->getMutation() |
| 67 | - ->addField( |
|
| 68 | - RelayMutation::buildMutation( |
|
| 69 | - 'introduceShip', |
|
| 70 | - [ |
|
| 71 | - new InputField(['name' => 'shipName', 'type' => new NonNullType(new StringType())]), |
|
| 72 | - new InputField(['name' => 'factionId', 'type' => new NonNullType(new StringType())]) |
|
| 73 | - ], |
|
| 74 | - [ |
|
| 75 | - 'newShipEdge' => [ |
|
| 76 | - 'type' => Connection::edgeDefinition(new ShipType(), 'newShip'), |
|
| 77 | - 'resolve' => function ($value) { |
|
| 78 | - $allShips = TestDataProvider::getShips(); |
|
| 79 | - $newShip = TestDataProvider::getShip($value['shipId']); |
|
| 67 | + ->addField( |
|
| 68 | + RelayMutation::buildMutation( |
|
| 69 | + 'introduceShip', |
|
| 70 | + [ |
|
| 71 | + new InputField(['name' => 'shipName', 'type' => new NonNullType(new StringType())]), |
|
| 72 | + new InputField(['name' => 'factionId', 'type' => new NonNullType(new StringType())]) |
|
| 73 | + ], |
|
| 74 | + [ |
|
| 75 | + 'newShipEdge' => [ |
|
| 76 | + 'type' => Connection::edgeDefinition(new ShipType(), 'newShip'), |
|
| 77 | + 'resolve' => function ($value) { |
|
| 78 | + $allShips = TestDataProvider::getShips(); |
|
| 79 | + $newShip = TestDataProvider::getShip($value['shipId']); |
|
| 80 | 80 | |
| 81 | - return [ |
|
| 82 | - 'cursor' => ArrayConnection::cursorForObjectInConnection($allShips, $newShip), |
|
| 83 | - 'node' => $newShip |
|
| 84 | - ]; |
|
| 85 | - } |
|
| 86 | - ], |
|
| 87 | - 'faction' => [ |
|
| 88 | - 'type' => new FactionType(), |
|
| 89 | - 'resolve' => function ($value) { |
|
| 90 | - return TestDataProvider::getFaction($value['factionId']); |
|
| 91 | - } |
|
| 92 | - ] |
|
| 93 | - ], |
|
| 94 | - function ($value, $args, $info) { |
|
| 95 | - $newShip = TestDataProvider::createShip($args['shipName'], $args['factionId']); |
|
| 81 | + return [ |
|
| 82 | + 'cursor' => ArrayConnection::cursorForObjectInConnection($allShips, $newShip), |
|
| 83 | + 'node' => $newShip |
|
| 84 | + ]; |
|
| 85 | + } |
|
| 86 | + ], |
|
| 87 | + 'faction' => [ |
|
| 88 | + 'type' => new FactionType(), |
|
| 89 | + 'resolve' => function ($value) { |
|
| 90 | + return TestDataProvider::getFaction($value['factionId']); |
|
| 91 | + } |
|
| 92 | + ] |
|
| 93 | + ], |
|
| 94 | + function ($value, $args, $info) { |
|
| 95 | + $newShip = TestDataProvider::createShip($args['shipName'], $args['factionId']); |
|
| 96 | 96 | |
| 97 | - return [ |
|
| 98 | - 'shipId' => $newShip['id'], |
|
| 99 | - 'factionId' => $args['factionId'] |
|
| 100 | - ]; |
|
| 101 | - } |
|
| 102 | - ) |
|
| 103 | - ); |
|
| 97 | + return [ |
|
| 98 | + 'shipId' => $newShip['id'], |
|
| 99 | + 'factionId' => $args['factionId'] |
|
| 100 | + ]; |
|
| 101 | + } |
|
| 102 | + ) |
|
| 103 | + ); |
|
| 104 | 104 | |
| 105 | 105 | /** https://github.com/graphql/graphql-relay-js/blob/master/src/__tests__/starWarsSchema.js */ |
| 106 | 106 | } |
@@ -12,9 +12,6 @@ |
||
| 12 | 12 | use Youshido\GraphQL\Config\Schema\SchemaConfig; |
| 13 | 13 | use Youshido\GraphQL\Execution\ResolveInfo; |
| 14 | 14 | use Youshido\GraphQL\Schema\AbstractSchema; |
| 15 | -use Youshido\GraphQL\Type\NonNullType; |
|
| 16 | -use Youshido\GraphQL\Type\Scalar\IntType; |
|
| 17 | -use Youshido\GraphQL\Type\Scalar\StringType; |
|
| 18 | 15 | |
| 19 | 16 | class TestSchema extends AbstractSchema |
| 20 | 17 | { |
@@ -30,21 +30,21 @@ |
||
| 30 | 30 | ], |
| 31 | 31 | ])) |
| 32 | 32 | ->addField('location', [ |
| 33 | - 'type' => new ObjectType( |
|
| 34 | - [ |
|
| 35 | - 'name' => 'Location', |
|
| 36 | - 'fields' => [ |
|
| 37 | - 'address' => new StringType() |
|
| 38 | - ] |
|
| 39 | - ] |
|
| 40 | - ), |
|
| 41 | - 'args' => [ |
|
| 42 | - 'noop' => new IntType() |
|
| 43 | - ], |
|
| 44 | - 'resolve' => function ($value, $args, $info) { |
|
| 45 | - return ['address' => '1234 Street']; |
|
| 46 | - } |
|
| 47 | - ] |
|
| 33 | + 'type' => new ObjectType( |
|
| 34 | + [ |
|
| 35 | + 'name' => 'Location', |
|
| 36 | + 'fields' => [ |
|
| 37 | + 'address' => new StringType() |
|
| 38 | + ] |
|
| 39 | + ] |
|
| 40 | + ), |
|
| 41 | + 'args' => [ |
|
| 42 | + 'noop' => new IntType() |
|
| 43 | + ], |
|
| 44 | + 'resolve' => function ($value, $args, $info) { |
|
| 45 | + return ['address' => '1234 Street']; |
|
| 46 | + } |
|
| 47 | + ] |
|
| 48 | 48 | ) |
| 49 | 49 | ->addField( |
| 50 | 50 | 'echo', [ |
@@ -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 () { |
@@ -449,68 +449,68 @@ discard block |
||
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | public function testComplexityReducer() { |
| 452 | - $schema = new Schema( |
|
| 453 | - [ |
|
| 454 | - 'query' => new ObjectType( |
|
| 455 | - [ |
|
| 456 | - 'name' => 'RootQuery', |
|
| 457 | - 'fields' => [ |
|
| 458 | - 'me' => [ |
|
| 459 | - 'type' => new ObjectType( |
|
| 460 | - [ |
|
| 461 | - 'name' => 'User', |
|
| 462 | - 'fields' => [ |
|
| 463 | - 'firstName' => [ |
|
| 464 | - 'type' => new StringType(), |
|
| 465 | - 'args' => [ |
|
| 466 | - 'shorten' => new BooleanType() |
|
| 467 | - ], |
|
| 468 | - 'resolve' => function ($value, $args) { |
|
| 452 | + $schema = new Schema( |
|
| 453 | + [ |
|
| 454 | + 'query' => new ObjectType( |
|
| 455 | + [ |
|
| 456 | + 'name' => 'RootQuery', |
|
| 457 | + 'fields' => [ |
|
| 458 | + 'me' => [ |
|
| 459 | + 'type' => new ObjectType( |
|
| 460 | + [ |
|
| 461 | + 'name' => 'User', |
|
| 462 | + 'fields' => [ |
|
| 463 | + 'firstName' => [ |
|
| 464 | + 'type' => new StringType(), |
|
| 465 | + 'args' => [ |
|
| 466 | + 'shorten' => new BooleanType() |
|
| 467 | + ], |
|
| 468 | + 'resolve' => function ($value, $args) { |
|
| 469 | 469 | return empty($args['shorten']) ? $value : $value; |
| 470 | - } |
|
| 471 | - ], |
|
| 472 | - 'lastName' => new StringType(), |
|
| 473 | - 'code' => new StringType(), |
|
| 474 | - 'likes' => [ |
|
| 475 | - 'type' => new IntType(), |
|
| 476 | - 'cost' => 10, |
|
| 477 | - 'resolve' => function () { |
|
| 470 | + } |
|
| 471 | + ], |
|
| 472 | + 'lastName' => new StringType(), |
|
| 473 | + 'code' => new StringType(), |
|
| 474 | + 'likes' => [ |
|
| 475 | + 'type' => new IntType(), |
|
| 476 | + 'cost' => 10, |
|
| 477 | + 'resolve' => function () { |
|
| 478 | 478 | return 42; |
| 479 | - } |
|
| 480 | - ] |
|
| 481 | - ] |
|
| 482 | - ] |
|
| 483 | - ), |
|
| 484 | - 'resolve' => function ($value, $args) { |
|
| 479 | + } |
|
| 480 | + ] |
|
| 481 | + ] |
|
| 482 | + ] |
|
| 483 | + ), |
|
| 484 | + 'resolve' => function ($value, $args) { |
|
| 485 | 485 | $data = ['firstName' => 'John', 'code' => '007']; |
| 486 | 486 | if (!empty($args['upper'])) { |
| 487 | - foreach ($data as $key => $value) { |
|
| 487 | + foreach ($data as $key => $value) { |
|
| 488 | 488 | $data[$key] = strtoupper($value); |
| 489 | - } |
|
| 489 | + } |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | return $data; |
| 493 | - }, |
|
| 494 | - 'args' => [ |
|
| 495 | - 'upper' => [ |
|
| 496 | - 'type' => new BooleanType(), |
|
| 497 | - 'default' => false |
|
| 498 | - ] |
|
| 499 | - ] |
|
| 500 | - ] |
|
| 501 | - ] |
|
| 502 | - ] |
|
| 503 | - ) |
|
| 504 | - ] |
|
| 505 | - ); |
|
| 506 | - $processor = new Processor($schema); |
|
| 507 | - |
|
| 508 | - $processor->setMaxComplexity(10); |
|
| 509 | - |
|
| 510 | - $processor->processPayload('{ me { firstName, lastName } }'); |
|
| 511 | - $this->assertArrayNotHasKey('error', $processor->getResponseData()); |
|
| 512 | - |
|
| 513 | - $processor->processPayload('{ me { firstname likes { count } } }'); |
|
| 514 | - $this->assertEquals(['errors' => [['message' => 'query exceeded max allowed complexity of 10']]], $processor->getResponseData()); |
|
| 493 | + }, |
|
| 494 | + 'args' => [ |
|
| 495 | + 'upper' => [ |
|
| 496 | + 'type' => new BooleanType(), |
|
| 497 | + 'default' => false |
|
| 498 | + ] |
|
| 499 | + ] |
|
| 500 | + ] |
|
| 501 | + ] |
|
| 502 | + ] |
|
| 503 | + ) |
|
| 504 | + ] |
|
| 505 | + ); |
|
| 506 | + $processor = new Processor($schema); |
|
| 507 | + |
|
| 508 | + $processor->setMaxComplexity(10); |
|
| 509 | + |
|
| 510 | + $processor->processPayload('{ me { firstName, lastName } }'); |
|
| 511 | + $this->assertArrayNotHasKey('error', $processor->getResponseData()); |
|
| 512 | + |
|
| 513 | + $processor->processPayload('{ me { firstname likes { count } } }'); |
|
| 514 | + $this->assertEquals(['errors' => [['message' => 'query exceeded max allowed complexity of 10']]], $processor->getResponseData()); |
|
| 515 | 515 | } |
| 516 | 516 | } |