From d56b0c2e5d3119f0845736ed1b5bf6887595ad84 Mon Sep 17 00:00:00 2001 From: Ferran Vidal Date: Wed, 6 Jan 2021 15:38:54 +0100 Subject: [PATCH 1/4] Make sure that internal_error_message is used during ErrorHandler initialization Third argument for `Overblog\GraphQLBundle\Error\ErrorHandler` is the default message to use when an error happen. As described in the documentation `overblog_graphql.errors_handler.internal_error_message` can be used to set a custom message. --- src/DependencyInjection/OverblogGraphQLExtension.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/OverblogGraphQLExtension.php b/src/DependencyInjection/OverblogGraphQLExtension.php index b7edc491d..4305141af 100644 --- a/src/DependencyInjection/OverblogGraphQLExtension.php +++ b/src/DependencyInjection/OverblogGraphQLExtension.php @@ -207,7 +207,8 @@ private function setErrorHandler(array $config, ContainerBuilder $container): vo $container->register(ErrorHandler::class) ->setArgument(0, new Reference(EventDispatcherInterface::class)) - ->setArgument(1, new Reference(ExceptionConverterInterface::class)); + ->setArgument(1, new Reference(ExceptionConverterInterface::class)) + ->setArgument(2, $config['errors_handler']['internal_error_message']); $container->register(ErrorHandlerListener::class) ->setArgument(0, new Reference(ErrorHandler::class)) From 8c5a472643a60b341af24e80b3b6a691cbaaf5d3 Mon Sep 17 00:00:00 2001 From: Dmitry Hordinsky Date: Mon, 11 Jan 2021 16:11:56 +0200 Subject: [PATCH 2/4] Fix error for non-nullable array of non-nullable elements annotation --- src/Transformer/ArgumentsTransformer.php | 7 +- .../Transformer/ArgumentsTransformerTest.php | 74 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/Transformer/ArgumentsTransformer.php b/src/Transformer/ArgumentsTransformer.php index 9c310a0db..148e2681b 100644 --- a/src/Transformer/ArgumentsTransformer.php +++ b/src/Transformer/ArgumentsTransformer.php @@ -132,7 +132,12 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info { $isRequired = '!' === $argType[strlen($argType) - 1]; $isMultiple = '[' === $argType[0]; - $endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0); + $isStrictMultiple = false; + if ($isMultiple) { + $isStrictMultiple = '!' === $argType[strpos($argType, ']') - 1]; + } + + $endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0) + ($isStrictMultiple ? 1 : 0); $type = substr($argType, $isMultiple ? 1 : 0, $endIndex > 0 ? -$endIndex : strlen($argType)); $result = $this->populateObject($this->getType($type, $info), $data, $isMultiple, $info); diff --git a/tests/Transformer/ArgumentsTransformerTest.php b/tests/Transformer/ArgumentsTransformerTest.php index 71ef0b398..0071a8bc6 100644 --- a/tests/Transformer/ArgumentsTransformerTest.php +++ b/tests/Transformer/ArgumentsTransformerTest.php @@ -5,8 +5,11 @@ namespace Overblog\GraphQLBundle\Tests\Transformer; use Exception; +use Generator; use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\InputObjectType; +use GraphQL\Type\Definition\ListOfType; +use GraphQL\Type\Definition\NonNull; use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type; use GraphQL\Type\Schema; @@ -300,4 +303,75 @@ public function testRaisedErrorsForMultipleInputs(): void $this->assertEquals($e->toState(), $expected); } } + + public function getWrappedInputObject(): Generator + { + $inputObject = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string(), + 'field2' => Type::int(), + 'field3' => Type::boolean(), + ], + ]); + yield [$inputObject, false]; + yield [new NonNull($inputObject), false]; + } + + /** @dataProvider getWrappedInputObject */ + public function testInputObjectWithWrappingType(Type $type): void + { + $transformer = $this->getTransformer([ + 'InputType1' => ['type' => 'input', 'class' => InputType1::class], + ], new ConstraintViolationList() + ); + $info = $this->getResolveInfo(self::getTypes()); + + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; + + $inputValue = $transformer->getInstanceAndValidate($type->toString(), $data, $info, 'input1'); + + /** @var InputType1 $inputValue */ + $this->assertInstanceOf(InputType1::class, $inputValue); + $this->assertEquals($inputValue->field1, $data['field1']); + $this->assertEquals($inputValue->field2, $data['field2']); + $this->assertEquals($inputValue->field3, $data['field3']); + } + + public function getWrappedInputObjectList(): Generator + { + $inputObject = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string(), + 'field2' => Type::int(), + 'field3' => Type::boolean(), + ], + ]); + yield [new ListOfType($inputObject)]; + yield [new ListOfType(new NonNull($inputObject))]; + yield [new NonNull(new ListOfType($inputObject))]; + yield [new NonNull(new ListOfType(new NonNull($inputObject)))]; + } + + /** @dataProvider getWrappedInputObjectList */ + public function testInputObjectWithWrappingTypeList(Type $type): void + { + $transformer = $this->getTransformer( + ['InputType1' => ['type' => 'input', 'class' => InputType1::class]], + new ConstraintViolationList() + ); + $info = $this->getResolveInfo(self::getTypes()); + + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; + + $inputValue = $transformer->getInstanceAndValidate($type->toString(), [$data], $info, 'input1'); + $inputValue = reset($inputValue); + + /** @var InputType1 $inputValue */ + $this->assertInstanceOf(InputType1::class, $inputValue); + $this->assertEquals($inputValue->field1, $data['field1']); + $this->assertEquals($inputValue->field2, $data['field2']); + $this->assertEquals($inputValue->field3, $data['field3']); + } } From 32cb7344326f5ae91c37052245c669245c574e31 Mon Sep 17 00:00:00 2001 From: Dmitry Hordinsky Date: Mon, 11 Jan 2021 16:11:56 +0200 Subject: [PATCH 3/4] Fix error for non-nullable array of non-nullable elements annotation --- src/Transformer/ArgumentsTransformer.php | 9 ++- .../Transformer/ArgumentsTransformerTest.php | 75 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/Transformer/ArgumentsTransformer.php b/src/Transformer/ArgumentsTransformer.php index 4d201e2c3..8102f42f7 100644 --- a/src/Transformer/ArgumentsTransformer.php +++ b/src/Transformer/ArgumentsTransformer.php @@ -142,8 +142,13 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info { $isRequired = '!' === $argType[\strlen($argType) - 1]; $isMultiple = '[' === $argType[0]; - $endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0); - $type = \substr($argType, $isMultiple ? 1 : 0, $endIndex > 0 ? -$endIndex : \strlen($argType)); + $isStrictMultiple = false; + if ($isMultiple) { + $isStrictMultiple = '!' === $argType[strpos($argType, ']') - 1]; + } + + $endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0) + ($isStrictMultiple ? 1 : 0); + $type = \substr($argType, $isMultiple ? 1 : 0, $endIndex > 0 ? -$endIndex : strlen($argType)); $result = $this->populateObject($this->getType($type, $info), $data, $isMultiple, $info); $errors = []; diff --git a/tests/Transformer/ArgumentsTransformerTest.php b/tests/Transformer/ArgumentsTransformerTest.php index c20804fde..a94b47ad5 100644 --- a/tests/Transformer/ArgumentsTransformerTest.php +++ b/tests/Transformer/ArgumentsTransformerTest.php @@ -4,8 +4,12 @@ namespace Overblog\GraphQLBundle\Tests\Transformer; +use Exception; +use Generator; use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\InputObjectType; +use GraphQL\Type\Definition\ListOfType; +use GraphQL\Type\Definition\NonNull; use GraphQL\Type\Definition\ResolveInfo; use GraphQL\Type\Definition\Type; use GraphQL\Type\Schema; @@ -180,4 +184,75 @@ public function testRaisedErrors(): void $this->assertEquals($e->toState(), $expected); } } + + public function getWrappedInputObject(): Generator + { + $inputObject = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string(), + 'field2' => Type::int(), + 'field3' => Type::boolean(), + ], + ]); + yield [$inputObject, false]; + yield [new NonNull($inputObject), false]; + } + + /** @dataProvider getWrappedInputObject */ + public function testInputObjectWithWrappingType(Type $type): void + { + $transformer = $this->getTransformer([ + 'InputType1' => ['type' => 'input', 'class' => InputType1::class], + ], new ConstraintViolationList() + ); + $info = $this->getResolveInfo(self::getTypes()); + + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; + + $inputValue = $transformer->getInstanceAndValidate($type->toString(), $data, $info, 'input1'); + + /** @var InputType1 $inputValue */ + $this->assertInstanceOf(InputType1::class, $inputValue); + $this->assertEquals($inputValue->field1, $data['field1']); + $this->assertEquals($inputValue->field2, $data['field2']); + $this->assertEquals($inputValue->field3, $data['field3']); + } + + public function getWrappedInputObjectList(): Generator + { + $inputObject = new InputObjectType([ + 'name' => 'InputType1', + 'fields' => [ + 'field1' => Type::string(), + 'field2' => Type::int(), + 'field3' => Type::boolean(), + ], + ]); + yield [new ListOfType($inputObject)]; + yield [new ListOfType(new NonNull($inputObject))]; + yield [new NonNull(new ListOfType($inputObject))]; + yield [new NonNull(new ListOfType(new NonNull($inputObject)))]; + } + + /** @dataProvider getWrappedInputObjectList */ + public function testInputObjectWithWrappingTypeList(Type $type): void + { + $transformer = $this->getTransformer( + ['InputType1' => ['type' => 'input', 'class' => InputType1::class]], + new ConstraintViolationList() + ); + $info = $this->getResolveInfo(self::getTypes()); + + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; + + $inputValue = $transformer->getInstanceAndValidate($type->toString(), [$data], $info, 'input1'); + $inputValue = reset($inputValue); + + /** @var InputType1 $inputValue */ + $this->assertInstanceOf(InputType1::class, $inputValue); + $this->assertEquals($inputValue->field1, $data['field1']); + $this->assertEquals($inputValue->field2, $data['field2']); + $this->assertEquals($inputValue->field3, $data['field3']); + } } From f187a08b65a28dd9feb7678a621e53fc36e93a5e Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Wed, 13 Jan 2021 12:33:51 +0100 Subject: [PATCH 4/4] Fix CS --- src/Transformer/ArgumentsTransformer.php | 4 ++-- tests/Transformer/ArgumentsTransformerTest.php | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Transformer/ArgumentsTransformer.php b/src/Transformer/ArgumentsTransformer.php index 8102f42f7..1f49747ab 100644 --- a/src/Transformer/ArgumentsTransformer.php +++ b/src/Transformer/ArgumentsTransformer.php @@ -144,11 +144,11 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info $isMultiple = '[' === $argType[0]; $isStrictMultiple = false; if ($isMultiple) { - $isStrictMultiple = '!' === $argType[strpos($argType, ']') - 1]; + $isStrictMultiple = '!' === $argType[\strpos($argType, ']') - 1]; } $endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0) + ($isStrictMultiple ? 1 : 0); - $type = \substr($argType, $isMultiple ? 1 : 0, $endIndex > 0 ? -$endIndex : strlen($argType)); + $type = \substr($argType, $isMultiple ? 1 : 0, $endIndex > 0 ? -$endIndex : \strlen($argType)); $result = $this->populateObject($this->getType($type, $info), $data, $isMultiple, $info); $errors = []; diff --git a/tests/Transformer/ArgumentsTransformerTest.php b/tests/Transformer/ArgumentsTransformerTest.php index a94b47ad5..3cd2a592f 100644 --- a/tests/Transformer/ArgumentsTransformerTest.php +++ b/tests/Transformer/ArgumentsTransformerTest.php @@ -4,7 +4,6 @@ namespace Overblog\GraphQLBundle\Tests\Transformer; -use Exception; use Generator; use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\InputObjectType; @@ -212,7 +211,7 @@ public function testInputObjectWithWrappingType(Type $type): void $inputValue = $transformer->getInstanceAndValidate($type->toString(), $data, $info, 'input1'); - /** @var InputType1 $inputValue */ + /* @var InputType1 $inputValue */ $this->assertInstanceOf(InputType1::class, $inputValue); $this->assertEquals($inputValue->field1, $data['field1']); $this->assertEquals($inputValue->field2, $data['field2']); @@ -247,9 +246,9 @@ public function testInputObjectWithWrappingTypeList(Type $type): void $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; $inputValue = $transformer->getInstanceAndValidate($type->toString(), [$data], $info, 'input1'); - $inputValue = reset($inputValue); + $inputValue = \reset($inputValue); - /** @var InputType1 $inputValue */ + /* @var InputType1 $inputValue */ $this->assertInstanceOf(InputType1::class, $inputValue); $this->assertEquals($inputValue->field1, $data['field1']); $this->assertEquals($inputValue->field2, $data['field2']);