From 261f8f5ebd433605f0fc3981c0e3db12f8c63be2 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Wed, 19 Jun 2019 15:52:16 +0700 Subject: [PATCH] AST: Replaced array with NodeList where missing --- src/Utils/AST.php | 4 ++-- tests/Utils/AstFromValueTest.php | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Utils/AST.php b/src/Utils/AST.php index 4fab803..24bd77c 100644 --- a/src/Utils/AST.php +++ b/src/Utils/AST.php @@ -183,7 +183,7 @@ class AST $valuesNodes[] = $itemNode; } - return new ListValueNode(['values' => $valuesNodes]); + return new ListValueNode(['values' => new NodeList($valuesNodes)]); } return self::astFromValue($value, $itemType); @@ -235,7 +235,7 @@ class AST ]); } - return new ObjectValueNode(['fields' => $fieldNodes]); + return new ObjectValueNode(['fields' => new NodeList($fieldNodes)]); } if ($type instanceof ScalarType || $type instanceof EnumType) { diff --git a/tests/Utils/AstFromValueTest.php b/tests/Utils/AstFromValueTest.php index b01a73c..02e7582 100644 --- a/tests/Utils/AstFromValueTest.php +++ b/tests/Utils/AstFromValueTest.php @@ -10,6 +10,7 @@ use GraphQL\Language\AST\FloatValueNode; use GraphQL\Language\AST\IntValueNode; use GraphQL\Language\AST\ListValueNode; use GraphQL\Language\AST\NameNode; +use GraphQL\Language\AST\NodeList; use GraphQL\Language\AST\NullValueNode; use GraphQL\Language\AST\ObjectFieldNode; use GraphQL\Language\AST\ObjectValueNode; @@ -179,18 +180,18 @@ class AstFromValueTest extends TestCase public function testConvertsArrayValuesToListASTs() : void { $value1 = new ListValueNode([ - 'values' => [ + 'values' => new NodeList([ new StringValueNode(['value' => 'FOO']), new StringValueNode(['value' => 'BAR']), - ], + ]), ]); self::assertEquals($value1, AST::astFromValue(['FOO', 'BAR'], Type::listOf(Type::string()))); $value2 = new ListValueNode([ - 'values' => [ + 'values' => new NodeList([ new EnumValueNode(['value' => 'HELLO']), new EnumValueNode(['value' => 'GOODBYE']), - ], + ]), ]); self::assertEquals($value2, AST::astFromValue(['HELLO', 'GOODBYE'], Type::listOf($this->myEnum()))); } @@ -220,10 +221,10 @@ class AstFromValueTest extends TestCase ]); $expected = new ObjectValueNode([ - 'fields' => [ + 'fields' => new NodeList([ $this->objectField('foo', new IntValueNode(['value' => '3'])), $this->objectField('bar', new EnumValueNode(['value' => 'HELLO'])), - ], + ]), ]); $data = ['foo' => 3, 'bar' => 'HELLO']; @@ -259,9 +260,9 @@ class AstFromValueTest extends TestCase self::assertEquals( new ObjectValueNode([ - 'fields' => [ + 'fields' => new NodeList([ $this->objectField('foo', new NullValueNode([])), - ], + ]), ]), AST::astFromValue(['foo' => null], $inputObj) );