From bc2f2cce9f63b6b28649138cee02ffab31f0d547 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 16 Oct 2019 16:38:48 +0200 Subject: [PATCH 1/5] Add failing test --- .../Execution/Arguments/TypedArgsTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/Unit/Execution/Arguments/TypedArgsTest.php b/tests/Unit/Execution/Arguments/TypedArgsTest.php index dc8dd0126e..c00584cbb2 100644 --- a/tests/Unit/Execution/Arguments/TypedArgsTest.php +++ b/tests/Unit/Execution/Arguments/TypedArgsTest.php @@ -40,4 +40,35 @@ public function testSimpleField(): void $this->assertInstanceOf(Argument::class, $bar); $this->assertSame(123, $bar->value); } + + public function testNullableList(): void + { + $this->schema = ' + type Query { + foo(bar: [Int!]): Int + } + '; + + /** @var \Nuwave\Lighthouse\Schema\AST\ASTBuilder $astBuilder */ + $astBuilder = $this->app->make(ASTBuilder::class); + $documentAST = $astBuilder->documentAST(); + /** @var \Nuwave\Lighthouse\Execution\Arguments\TypedArgs $typedArgs */ + $typedArgs = $this->app->make(TypedArgs::class); + + /** @var \GraphQL\Language\AST\ObjectTypeDefinitionNode $queryType */ + $queryType = $documentAST->types['Query']; + + $argumentSet = $typedArgs->fromField( + [ + 'bar' => null, + ], + ASTHelper::firstByName($queryType->fields, 'foo') + ); + + $this->assertCount(1, $argumentSet->arguments); + + $bar = $argumentSet->arguments['bar']; + $this->assertInstanceOf(Argument::class, $bar); + $this->assertSame(null, $bar->value); + } } From 02eea558224b22f6c17a5ca3bb301eeb3a9c7772 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 16 Oct 2019 16:49:02 +0200 Subject: [PATCH 2/5] Fix --- src/Execution/Arguments/TypedArgs.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Execution/Arguments/TypedArgs.php b/src/Execution/Arguments/TypedArgs.php index 49fce9eabc..1576c9d6e7 100644 --- a/src/Execution/Arguments/TypedArgs.php +++ b/src/Execution/Arguments/TypedArgs.php @@ -145,12 +145,17 @@ protected function wrapWithType($valueOrValues, $type) if ($type instanceof ListType) { $typeInList = $type->type; - $values = []; - foreach ($valueOrValues as $singleValue) { - $values [] = $this->wrapWithNamedType($singleValue, $typeInList); + if(is_array($valueOrValues)) { + $values = []; + foreach ($valueOrValues as $singleValue) { + $values [] = $this->wrapWithNamedType($singleValue, $typeInList); + } + + return $values; + } else { + // This case happens if `null` is passed + return $this->wrapWithNamedType($valueOrValues, $typeInList); } - - return $values; } else { return $this->wrapWithNamedType($valueOrValues, $type); } From afbd3569e248139574be555276b7c410610418e1 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 16 Oct 2019 14:49:25 +0000 Subject: [PATCH 3/5] Apply fixes from StyleCI --- src/Execution/Arguments/TypedArgs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Execution/Arguments/TypedArgs.php b/src/Execution/Arguments/TypedArgs.php index 1576c9d6e7..5d56d2c739 100644 --- a/src/Execution/Arguments/TypedArgs.php +++ b/src/Execution/Arguments/TypedArgs.php @@ -145,7 +145,7 @@ protected function wrapWithType($valueOrValues, $type) if ($type instanceof ListType) { $typeInList = $type->type; - if(is_array($valueOrValues)) { + if (is_array($valueOrValues)) { $values = []; foreach ($valueOrValues as $singleValue) { $values [] = $this->wrapWithNamedType($singleValue, $typeInList); From 82dce8fdd699d8113fea5c749a865ded2d9cb697 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 16 Oct 2019 16:50:32 +0200 Subject: [PATCH 4/5] Add CHANGELOG --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a2ca41f8..7bc8e24951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/nuwave/lighthouse/compare/v4.5.0...master) +## [Unreleased](https://github.com/nuwave/lighthouse/compare/v4.5.1...master) + +## [4.5.1](https://github.com/nuwave/lighthouse/compare/v4.5.0...v4.5.1) + +### Fixed + +- Handle `null` being passed to a nullable argument that is a list of type https://github.com/nuwave/lighthouse/pull/1016 ## [4.5.0](https://github.com/nuwave/lighthouse/compare/v4.4.2...v4.5.0) From f398cd2899e550f46867cd3cb0e1806924e7a603 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 16 Oct 2019 17:01:34 +0200 Subject: [PATCH 5/5] Remove useless else --- src/Execution/Arguments/TypedArgs.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Execution/Arguments/TypedArgs.php b/src/Execution/Arguments/TypedArgs.php index 5d56d2c739..aa9083ee30 100644 --- a/src/Execution/Arguments/TypedArgs.php +++ b/src/Execution/Arguments/TypedArgs.php @@ -152,13 +152,13 @@ protected function wrapWithType($valueOrValues, $type) } return $values; - } else { - // This case happens if `null` is passed - return $this->wrapWithNamedType($valueOrValues, $typeInList); } - } else { - return $this->wrapWithNamedType($valueOrValues, $type); + + // This case happens if `null` is passed + return $this->wrapWithNamedType($valueOrValues, $typeInList); } + + return $this->wrapWithNamedType($valueOrValues, $type); } /**