From 54f310bde9ec0e622e78a6000b7f3b95728eb466 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Tue, 12 Jul 2016 15:10:50 -0400 Subject: [PATCH 1/4] regression test --- Tests/DataProvider/TestObjectType.php | 14 +++++++++++++- Tests/DataProvider/TestSchema.php | 2 ++ Tests/Schema/ProcessorTest.php | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Tests/DataProvider/TestObjectType.php b/Tests/DataProvider/TestObjectType.php index d35b8667..ade16ffc 100644 --- a/Tests/DataProvider/TestObjectType.php +++ b/Tests/DataProvider/TestObjectType.php @@ -12,6 +12,7 @@ use Youshido\GraphQL\Type\Object\ObjectType; use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; +use Youshido\GraphQL\Type\NonNullType; class TestObjectType extends AbstractObjectType { @@ -27,7 +28,18 @@ public function build($config) 'country' => new StringType(), 'city' => new StringType() ], - ])); + ])) + ->addField( + 'echo', [ + 'type' => new StringType(), + 'args' => [ + 'value' => new NonNullType(new StringType()) + ], + 'resolve' => function ($value, $args, $info) { + return $args['value']; + } + ] + ); } public function getInterfaces() diff --git a/Tests/DataProvider/TestSchema.php b/Tests/DataProvider/TestSchema.php index 7ebf739f..3deaffef 100644 --- a/Tests/DataProvider/TestSchema.php +++ b/Tests/DataProvider/TestSchema.php @@ -12,6 +12,8 @@ use Youshido\GraphQL\Config\Schema\SchemaConfig; use Youshido\GraphQL\Execution\ResolveInfo; use Youshido\GraphQL\Schema\AbstractSchema; +use Youshido\GraphQL\Type\NonNullType; +use Youshido\GraphQL\Type\Scalar\StringType; class TestSchema extends AbstractSchema { diff --git a/Tests/Schema/ProcessorTest.php b/Tests/Schema/ProcessorTest.php index 5f8b5ca1..9044d51d 100644 --- a/Tests/Schema/ProcessorTest.php +++ b/Tests/Schema/ProcessorTest.php @@ -55,6 +55,23 @@ public function testEmptyQueries() } + public function testNestedVariables() { + $processor = new Processor(new TestSchema()); + $no_args_query = '{ me { echo(value:"foo") } }'; + $expected_data = ['data' => ['me' => ['echo' => 'foo']]]; + $processor->processPayload($no_args_query, ['value' => 'foo']); + $this->assertEquals($expected_data, $processor->getResponseData()); + + $parameterized_query = + 'query nestedQuery($value:String!){ + me { + echo(value:$value) + } + }'; + $processor->processPayload($parameterized_query, ['value' => 'foo']); + $this->assertEquals($expected_data, $processor->getResponseData()); + } + public function testListNullResponse() { $processor = new Processor(new Schema([ From f10e6648478851338db53d01c02a3ceea7a875ed Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 13 Jul 2016 14:29:27 -0400 Subject: [PATCH 2/4] new regression test --- Tests/DataProvider/TestObjectType.php | 18 ++++++++++++++++++ Tests/DataProvider/TestSchema.php | 1 + Tests/Schema/ProcessorTest.php | 27 +++++++++++++++++++-------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Tests/DataProvider/TestObjectType.php b/Tests/DataProvider/TestObjectType.php index ade16ffc..a8bc81cf 100644 --- a/Tests/DataProvider/TestObjectType.php +++ b/Tests/DataProvider/TestObjectType.php @@ -8,6 +8,7 @@ namespace Youshido\Tests\DataProvider; +use Youshido\GraphQL\Type\ListType\ListType; use Youshido\GraphQL\Type\Object\AbstractObjectType; use Youshido\GraphQL\Type\Object\ObjectType; use Youshido\GraphQL\Type\Scalar\IntType; @@ -29,6 +30,23 @@ public function build($config) 'city' => new StringType() ], ])) + ->addField('location', [ + 'type' => new ObjectType( + [ + 'name' => 'Location', + 'fields' => [ + 'address' => new StringType() + ] + ] + ), + 'args' => [ + 'noop' => new IntType() + ], + 'resolve' => function ($value, $args, $info) { + return ['address' => '1234 Street']; + } + ] + ) ->addField( 'echo', [ 'type' => new StringType(), diff --git a/Tests/DataProvider/TestSchema.php b/Tests/DataProvider/TestSchema.php index 3deaffef..5b682e92 100644 --- a/Tests/DataProvider/TestSchema.php +++ b/Tests/DataProvider/TestSchema.php @@ -13,6 +13,7 @@ use Youshido\GraphQL\Execution\ResolveInfo; use Youshido\GraphQL\Schema\AbstractSchema; use Youshido\GraphQL\Type\NonNullType; +use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; class TestSchema extends AbstractSchema diff --git a/Tests/Schema/ProcessorTest.php b/Tests/Schema/ProcessorTest.php index 9044d51d..cddefd98 100644 --- a/Tests/Schema/ProcessorTest.php +++ b/Tests/Schema/ProcessorTest.php @@ -57,19 +57,30 @@ public function testEmptyQueries() public function testNestedVariables() { $processor = new Processor(new TestSchema()); - $no_args_query = '{ me { echo(value:"foo") } }'; - $expected_data = ['data' => ['me' => ['echo' => 'foo']]]; - $processor->processPayload($no_args_query, ['value' => 'foo']); - $this->assertEquals($expected_data, $processor->getResponseData()); + $noArgsQuery = '{ me { echo(value:"foo") } }'; + $expectedData = ['data' => ['me' => ['echo' => 'foo']]]; + $processor->processPayload($noArgsQuery, ['value' => 'foo']); + $this->assertEquals($expectedData, $processor->getResponseData()); - $parameterized_query = - 'query nestedQuery($value:String!){ + $parameterizedFieldQuery = + 'query nestedFieldQuery($value:String!){ me { echo(value:$value) } }'; - $processor->processPayload($parameterized_query, ['value' => 'foo']); - $this->assertEquals($expected_data, $processor->getResponseData()); + $processor->processPayload($parameterizedFieldQuery, ['value' => 'foo']); + $this->assertEquals($expectedData, $processor->getResponseData()); + + $parameterizedQueryQuery = + 'query nestedQueryQuery($value:Int){ + me { + location(noop:$value) { + address + } + } + }'; + $processor->processPayload($parameterizedQueryQuery, ['value' => 1]); + $this->assertArrayNotHasKey('errors', $processor->getResponseData()); } public function testListNullResponse() From 9ed11d6a497bd5134733e00ed353970806404870 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 13 Jul 2016 14:30:29 -0400 Subject: [PATCH 3/4] unused use --- Tests/DataProvider/TestObjectType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/DataProvider/TestObjectType.php b/Tests/DataProvider/TestObjectType.php index a8bc81cf..f0e43a8b 100644 --- a/Tests/DataProvider/TestObjectType.php +++ b/Tests/DataProvider/TestObjectType.php @@ -8,7 +8,6 @@ namespace Youshido\Tests\DataProvider; -use Youshido\GraphQL\Type\ListType\ListType; use Youshido\GraphQL\Type\Object\AbstractObjectType; use Youshido\GraphQL\Type\Object\ObjectType; use Youshido\GraphQL\Type\Scalar\IntType; From 28bef5e4e25e514bb8d5641797a455efae3c55e4 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 13 Jul 2016 14:32:43 -0400 Subject: [PATCH 4/4] validate query arguments while processing AST --- src/Execution/Processor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Execution/Processor.php b/src/Execution/Processor.php index 9c8994c1..1dd1e792 100644 --- a/src/Execution/Processor.php +++ b/src/Execution/Processor.php @@ -126,6 +126,10 @@ protected function executeOperation(Query $query, $currentLevelSchema) */ protected function processQueryAST(Query $query, AbstractField $field, $contextValue = null) { + if (!$this->resolveValidator->validateArguments($field, $query, $this->executionContext->getRequest())) { + return null; + } + $resolvedValue = $this->resolveFieldValue($field, $contextValue, $query); if (!$this->resolveValidator->isValidValueForField($field, $resolvedValue)) {