AST: Replaced array with NodeList where missing

This commit is contained in:
Vladimir Razuvaev 2019-06-19 15:52:16 +07:00
parent d1d4455eaa
commit 261f8f5ebd
2 changed files with 11 additions and 10 deletions

View File

@ -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) {

View File

@ -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)
);