GraphQL\Language\AST\NodeType -> GraphQL\Language\AST\NodeKind

This commit is contained in:
vladar 2016-11-19 17:31:47 +07:00
parent 7340e30753
commit 660200ed50
74 changed files with 326 additions and 326 deletions

View File

@ -7,7 +7,7 @@ use GraphQL\Language\AST\DocumentNode;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Schema;
@ -119,7 +119,7 @@ class Executor
foreach ($documentNode->definitions as $definition) {
switch ($definition->kind) {
case NodeType::OPERATION_DEFINITION:
case NodeKind::OPERATION_DEFINITION:
if (!$operationName && $operation) {
throw new Error(
'Must provide operation name if query contains multiple operations.'
@ -130,7 +130,7 @@ class Executor
$operation = $definition;
}
break;
case NodeType::FRAGMENT_DEFINITION:
case NodeKind::FRAGMENT_DEFINITION:
$fragments[$definition->name->value] = $definition;
break;
default:
@ -271,7 +271,7 @@ class Executor
{
foreach ($selectionSet->selections as $selection) {
switch ($selection->kind) {
case NodeType::FIELD:
case NodeKind::FIELD:
if (!self::shouldIncludeNode($exeContext, $selection->directives)) {
continue;
}
@ -281,7 +281,7 @@ class Executor
}
$fields[$name][] = $selection;
break;
case NodeType::INLINE_FRAGMENT:
case NodeKind::INLINE_FRAGMENT:
if (!self::shouldIncludeNode($exeContext, $selection->directives) ||
!self::doesFragmentConditionMatch($exeContext, $selection, $runtimeType)
) {
@ -295,7 +295,7 @@ class Executor
$visitedFragmentNames
);
break;
case NodeType::FRAGMENT_SPREAD:
case NodeKind::FRAGMENT_SPREAD:
$fragName = $selection->name->value;
if (!empty($visitedFragmentNames[$fragName]) || !self::shouldIncludeNode($exeContext, $selection->directives)) {
continue;

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class ArgumentNode extends Node
{
public $kind = NodeType::ARGUMENT;
public $kind = NodeKind::ARGUMENT;
/**
* @var ValueNode

View File

@ -4,7 +4,7 @@ namespace GraphQL\Language\AST;
class BooleanValueNode extends Node implements ValueNode
{
public $kind = NodeType::BOOLEAN;
public $kind = NodeKind::BOOLEAN;
/**
* @var string

View File

@ -6,7 +6,7 @@ class DirectiveDefinitionNode extends Node implements TypeSystemDefinitionNode
/**
* @var string
*/
public $kind = NodeType::DIRECTIVE_DEFINITION;
public $kind = NodeKind::DIRECTIVE_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class DirectiveNode extends Node
{
public $kind = NodeType::DIRECTIVE;
public $kind = NodeKind::DIRECTIVE;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class DocumentNode extends Node
{
public $kind = NodeType::DOCUMENT;
public $kind = NodeKind::DOCUMENT;
/**
* @var DefinitionNode[]

View File

@ -6,7 +6,7 @@ class EnumTypeDefinitionNode extends Node implements TypeDefinitionNode
/**
* @var string
*/
public $kind = NodeType::ENUM_TYPE_DEFINITION;
public $kind = NodeKind::ENUM_TYPE_DEFINITION;
/**
* @var NameNode

View File

@ -6,7 +6,7 @@ class EnumValueDefinitionNode extends Node
/**
* @var string
*/
public $kind = NodeType::ENUM_VALUE_DEFINITION;
public $kind = NodeKind::ENUM_VALUE_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class EnumValueNode extends Node implements ValueNode
{
public $kind = NodeType::ENUM;
public $kind = NodeKind::ENUM;
/**
* @var string

View File

@ -6,7 +6,7 @@ class FieldDefinitionNode extends Node
/**
* @var string
*/
public $kind = NodeType::FIELD_DEFINITION;
public $kind = NodeKind::FIELD_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class FieldNode extends Node implements SelectionNode
{
public $kind = NodeType::FIELD;
public $kind = NodeKind::FIELD;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class FloatValueNode extends Node implements ValueNode
{
public $kind = NodeType::FLOAT;
public $kind = NodeKind::FLOAT;
/**
* @var string

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class FragmentDefinitionNode extends Node implements DefinitionNode, HasSelectionSet
{
public $kind = NodeType::FRAGMENT_DEFINITION;
public $kind = NodeKind::FRAGMENT_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class FragmentSpreadNode extends Node implements SelectionNode
{
public $kind = NodeType::FRAGMENT_SPREAD;
public $kind = NodeKind::FRAGMENT_SPREAD;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class InlineFragmentNode extends Node implements SelectionNode
{
public $kind = NodeType::INLINE_FRAGMENT;
public $kind = NodeKind::INLINE_FRAGMENT;
/**
* @var NamedTypeNode

View File

@ -6,7 +6,7 @@ class InputObjectTypeDefinitionNode extends Node implements TypeDefinitionNode
/**
* @var string
*/
public $kind = NodeType::INPUT_OBJECT_TYPE_DEFINITION;
public $kind = NodeKind::INPUT_OBJECT_TYPE_DEFINITION;
/**
* @var NameNode

View File

@ -6,7 +6,7 @@ class InputValueDefinitionNode extends Node
/**
* @var string
*/
public $kind = NodeType::INPUT_VALUE_DEFINITION;
public $kind = NodeKind::INPUT_VALUE_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class IntValueNode extends Node implements ValueNode
{
public $kind = NodeType::INT;
public $kind = NodeKind::INT;
/**
* @var string

View File

@ -6,7 +6,7 @@ class InterfaceTypeDefinitionNode extends Node implements TypeDefinitionNode
/**
* @var string
*/
public $kind = NodeType::INTERFACE_TYPE_DEFINITION;
public $kind = NodeKind::INTERFACE_TYPE_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class ListTypeNode extends Node implements TypeNode
{
public $kind = NodeType::LIST_TYPE;
public $kind = NodeKind::LIST_TYPE;
/**
* @var Node

View File

@ -4,7 +4,7 @@ namespace GraphQL\Language\AST;
class ListValueNode extends Node implements ValueNode
{
public $kind = NodeType::LST;
public $kind = NodeKind::LST;
/**
* @var ValueNode[]

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class NameNode extends Node implements TypeNode
{
public $kind = NodeType::NAME;
public $kind = NodeKind::NAME;
/**
* @var string

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class NamedTypeNode extends Node implements TypeNode
{
public $kind = NodeType::NAMED_TYPE;
public $kind = NodeKind::NAMED_TYPE;
/**
* @var NameNode

View File

@ -2,7 +2,7 @@
namespace GraphQL\Language\AST;
class NodeType
class NodeKind
{
// constants from language/kinds.js:

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class NonNullTypeNode extends Node implements TypeNode
{
public $kind = NodeType::NON_NULL_TYPE;
public $kind = NodeKind::NON_NULL_TYPE;
/**
* @var NameNode | ListTypeNode

View File

@ -3,5 +3,5 @@ namespace GraphQL\Language\AST;
class NullValueNode extends Node implements ValueNode
{
public $kind = NodeType::NULL;
public $kind = NodeKind::NULL;
}

View File

@ -4,7 +4,7 @@ namespace GraphQL\Language\AST;
class ObjectFieldNode extends Node
{
public $kind = NodeType::OBJECT_FIELD;
public $kind = NodeKind::OBJECT_FIELD;
/**
* @var NameNode

View File

@ -6,7 +6,7 @@ class ObjectTypeDefinitionNode extends Node implements TypeDefinitionNode
/**
* @var string
*/
public $kind = NodeType::OBJECT_TYPE_DEFINITION;
public $kind = NodeKind::OBJECT_TYPE_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class ObjectValueNode extends Node implements ValueNode
{
public $kind = NodeType::OBJECT;
public $kind = NodeKind::OBJECT;
/**
* @var ObjectFieldNode[]

View File

@ -6,7 +6,7 @@ class OperationDefinitionNode extends Node implements DefinitionNode, HasSelecti
/**
* @var string
*/
public $kind = NodeType::OPERATION_DEFINITION;
public $kind = NodeKind::OPERATION_DEFINITION;
/**
* @var NameNode

View File

@ -6,7 +6,7 @@ class OperationTypeDefinitionNode extends Node
/**
* @var string
*/
public $kind = NodeType::OPERATION_TYPE_DEFINITION;
public $kind = NodeKind::OPERATION_TYPE_DEFINITION;
/**
* One of 'query' | 'mutation' | 'subscription'

View File

@ -6,7 +6,7 @@ class ScalarTypeDefinitionNode extends Node implements TypeDefinitionNode
/**
* @var string
*/
public $kind = NodeType::SCALAR_TYPE_DEFINITION;
public $kind = NodeKind::SCALAR_TYPE_DEFINITION;
/**
* @var NameNode

View File

@ -6,7 +6,7 @@ class SchemaDefinitionNode extends Node implements TypeSystemDefinitionNode
/**
* @var string
*/
public $kind = NodeType::SCHEMA_DEFINITION;
public $kind = NodeKind::SCHEMA_DEFINITION;
/**
* @var DirectiveNode[]

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class SelectionSetNode extends Node
{
public $kind = NodeType::SELECTION_SET;
public $kind = NodeKind::SELECTION_SET;
/**
* @var SelectionNode[]

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class StringValueNode extends Node implements ValueNode
{
public $kind = NodeType::STRING;
public $kind = NodeKind::STRING;
/**
* @var string

View File

@ -6,7 +6,7 @@ class TypeExtensionDefinitionNode extends Node implements TypeSystemDefinitionNo
/**
* @var string
*/
public $kind = NodeType::TYPE_EXTENSION_DEFINITION;
public $kind = NodeKind::TYPE_EXTENSION_DEFINITION;
/**
* @var ObjectTypeDefinitionNode

View File

@ -6,7 +6,7 @@ class UnionTypeDefinitionNode extends Node implements TypeDefinitionNode
/**
* @var string
*/
public $kind = NodeType::UNION_TYPE_DEFINITION;
public $kind = NodeKind::UNION_TYPE_DEFINITION;
/**
* @var NameNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class VariableDefinitionNode extends Node implements DefinitionNode
{
public $kind = NodeType::VARIABLE_DEFINITION;
public $kind = NodeKind::VARIABLE_DEFINITION;
/**
* @var VariableNode

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class VariableNode extends Node
{
public $kind = NodeType::VARIABLE;
public $kind = NodeKind::VARIABLE;
/**
* @var NameNode

View File

@ -23,7 +23,7 @@ use GraphQL\Language\AST\IntValueNode;
use GraphQL\Language\AST\ListTypeNode;
use GraphQL\Language\AST\NamedTypeNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\NonNullTypeNode;
use GraphQL\Language\AST\NullValueNode;
use GraphQL\Language\AST\ObjectFieldNode;
@ -55,16 +55,16 @@ class Printer
{
return Visitor::visit($ast, [
'leave' => [
NodeType::NAME => function(Node $node) {
NodeKind::NAME => function(Node $node) {
return '' . $node->value;
},
NodeType::VARIABLE => function($node) {
NodeKind::VARIABLE => function($node) {
return '$' . $node->name;
},
NodeType::DOCUMENT => function(DocumentNode $node) {
NodeKind::DOCUMENT => function(DocumentNode $node) {
return $this->join($node->definitions, "\n\n") . "\n";
},
NodeType::OPERATION_DEFINITION => function(OperationDefinitionNode $node) {
NodeKind::OPERATION_DEFINITION => function(OperationDefinitionNode $node) {
$op = $node->operation;
$name = $node->name;
$varDefs = $this->wrap('(', $this->join($node->variableDefinitions, ', '), ')');
@ -76,28 +76,28 @@ class Printer
? $selectionSet
: $this->join([$op, $this->join([$name, $varDefs]), $directives, $selectionSet], ' ');
},
NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) {
NodeKind::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) {
return $node->variable . ': ' . $node->type . $this->wrap(' = ', $node->defaultValue);
},
NodeType::SELECTION_SET => function(SelectionSetNode $node) {
NodeKind::SELECTION_SET => function(SelectionSetNode $node) {
return $this->block($node->selections);
},
NodeType::FIELD => function(FieldNode $node) {
NodeKind::FIELD => function(FieldNode $node) {
return $this->join([
$this->wrap('', $node->alias, ': ') . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')'),
$this->join($node->directives, ' '),
$node->selectionSet
], ' ');
},
NodeType::ARGUMENT => function(ArgumentNode $node) {
NodeKind::ARGUMENT => function(ArgumentNode $node) {
return $node->name . ': ' . $node->value;
},
// Fragments
NodeType::FRAGMENT_SPREAD => function(FragmentSpreadNode $node) {
NodeKind::FRAGMENT_SPREAD => function(FragmentSpreadNode $node) {
return '...' . $node->name . $this->wrap(' ', $this->join($node->directives, ' '));
},
NodeType::INLINE_FRAGMENT => function(InlineFragmentNode $node) {
NodeKind::INLINE_FRAGMENT => function(InlineFragmentNode $node) {
return $this->join([
"...",
$this->wrap('on ', $node->typeCondition),
@ -105,73 +105,73 @@ class Printer
$node->selectionSet
], ' ');
},
NodeType::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) {
NodeKind::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) {
return "fragment {$node->name} on {$node->typeCondition} "
. $this->wrap('', $this->join($node->directives, ' '), ' ')
. $node->selectionSet;
},
// Value
NodeType::INT => function(IntValueNode $node) {
NodeKind::INT => function(IntValueNode $node) {
return $node->value;
},
NodeType::FLOAT => function(FloatValueNode $node) {
NodeKind::FLOAT => function(FloatValueNode $node) {
return $node->value;
},
NodeType::STRING => function(StringValueNode $node) {
NodeKind::STRING => function(StringValueNode $node) {
return json_encode($node->value);
},
NodeType::BOOLEAN => function(BooleanValueNode $node) {
NodeKind::BOOLEAN => function(BooleanValueNode $node) {
return $node->value ? 'true' : 'false';
},
NodeType::NULL => function(NullValueNode $node) {
NodeKind::NULL => function(NullValueNode $node) {
return 'null';
},
NodeType::ENUM => function(EnumValueNode $node) {
NodeKind::ENUM => function(EnumValueNode $node) {
return $node->value;
},
NodeType::LST => function(ListValueNode $node) {
NodeKind::LST => function(ListValueNode $node) {
return '[' . $this->join($node->values, ', ') . ']';
},
NodeType::OBJECT => function(ObjectValueNode $node) {
NodeKind::OBJECT => function(ObjectValueNode $node) {
return '{' . $this->join($node->fields, ', ') . '}';
},
NodeType::OBJECT_FIELD => function(ObjectFieldNode $node) {
NodeKind::OBJECT_FIELD => function(ObjectFieldNode $node) {
return $node->name . ': ' . $node->value;
},
// DirectiveNode
NodeType::DIRECTIVE => function(DirectiveNode $node) {
NodeKind::DIRECTIVE => function(DirectiveNode $node) {
return '@' . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')');
},
// Type
NodeType::NAMED_TYPE => function(NamedTypeNode $node) {
NodeKind::NAMED_TYPE => function(NamedTypeNode $node) {
return $node->name;
},
NodeType::LIST_TYPE => function(ListTypeNode $node) {
NodeKind::LIST_TYPE => function(ListTypeNode $node) {
return '[' . $node->type . ']';
},
NodeType::NON_NULL_TYPE => function(NonNullTypeNode $node) {
NodeKind::NON_NULL_TYPE => function(NonNullTypeNode $node) {
return $node->type . '!';
},
// Type System Definitions
NodeType::SCHEMA_DEFINITION => function(SchemaDefinitionNode $def) {
NodeKind::SCHEMA_DEFINITION => function(SchemaDefinitionNode $def) {
return $this->join([
'schema',
$this->join($def->directives, ' '),
$this->block($def->operationTypes)
], ' ');
},
NodeType::OPERATION_TYPE_DEFINITION => function(OperationTypeDefinitionNode $def) {
NodeKind::OPERATION_TYPE_DEFINITION => function(OperationTypeDefinitionNode $def) {
return $def->operation . ': ' . $def->type;
},
NodeType::SCALAR_TYPE_DEFINITION => function(ScalarTypeDefinitionNode $def) {
NodeKind::SCALAR_TYPE_DEFINITION => function(ScalarTypeDefinitionNode $def) {
return $this->join(['scalar', $def->name, $this->join($def->directives, ' ')], ' ');
},
NodeType::OBJECT_TYPE_DEFINITION => function(ObjectTypeDefinitionNode $def) {
NodeKind::OBJECT_TYPE_DEFINITION => function(ObjectTypeDefinitionNode $def) {
return $this->join([
'type',
$def->name,
@ -180,20 +180,20 @@ class Printer
$this->block($def->fields)
], ' ');
},
NodeType::FIELD_DEFINITION => function(FieldDefinitionNode $def) {
NodeKind::FIELD_DEFINITION => function(FieldDefinitionNode $def) {
return $def->name
. $this->wrap('(', $this->join($def->arguments, ', '), ')')
. ': ' . $def->type
. $this->wrap(' ', $this->join($def->directives, ' '));
},
NodeType::INPUT_VALUE_DEFINITION => function(InputValueDefinitionNode $def) {
NodeKind::INPUT_VALUE_DEFINITION => function(InputValueDefinitionNode $def) {
return $this->join([
$def->name . ': ' . $def->type,
$this->wrap('= ', $def->defaultValue),
$this->join($def->directives, ' ')
], ' ');
},
NodeType::INTERFACE_TYPE_DEFINITION => function(InterfaceTypeDefinitionNode $def) {
NodeKind::INTERFACE_TYPE_DEFINITION => function(InterfaceTypeDefinitionNode $def) {
return $this->join([
'interface',
$def->name,
@ -201,7 +201,7 @@ class Printer
$this->block($def->fields)
], ' ');
},
NodeType::UNION_TYPE_DEFINITION => function(UnionTypeDefinitionNode $def) {
NodeKind::UNION_TYPE_DEFINITION => function(UnionTypeDefinitionNode $def) {
return $this->join([
'union',
$def->name,
@ -209,7 +209,7 @@ class Printer
'= ' . $this->join($def->types, ' | ')
], ' ');
},
NodeType::ENUM_TYPE_DEFINITION => function(EnumTypeDefinitionNode $def) {
NodeKind::ENUM_TYPE_DEFINITION => function(EnumTypeDefinitionNode $def) {
return $this->join([
'enum',
$def->name,
@ -217,13 +217,13 @@ class Printer
$this->block($def->values)
], ' ');
},
NodeType::ENUM_VALUE_DEFINITION => function(EnumValueDefinitionNode $def) {
NodeKind::ENUM_VALUE_DEFINITION => function(EnumValueDefinitionNode $def) {
return $this->join([
$def->name,
$this->join($def->directives, ' ')
], ' ');
},
NodeType::INPUT_OBJECT_TYPE_DEFINITION => function(InputObjectTypeDefinitionNode $def) {
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => function(InputObjectTypeDefinitionNode $def) {
return $this->join([
'input',
$def->name,
@ -231,10 +231,10 @@ class Printer
$this->block($def->fields)
], ' ');
},
NodeType::TYPE_EXTENSION_DEFINITION => function(TypeExtensionDefinitionNode $def) {
NodeKind::TYPE_EXTENSION_DEFINITION => function(TypeExtensionDefinitionNode $def) {
return "extend {$def->definition}";
},
NodeType::DIRECTIVE_DEFINITION => function(DirectiveDefinitionNode $def) {
NodeKind::DIRECTIVE_DEFINITION => function(DirectiveDefinitionNode $def) {
return 'directive @' . $def->name . $this->wrap('(', $this->join($def->arguments, ', '), ')')
. ' on ' . $this->join($def->locations, ' | ');
}

View File

@ -2,7 +2,7 @@
namespace GraphQL\Language;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Utils\TypeInfo;
class VisitorOperation
@ -49,45 +49,45 @@ class Visitor
}
public static $visitorKeys = [
NodeType::NAME => [],
NodeType::DOCUMENT => ['definitions'],
NodeType::OPERATION_DEFINITION => ['name', 'variableDefinitions', 'directives', 'selectionSet'],
NodeType::VARIABLE_DEFINITION => ['variable', 'type', 'defaultValue'],
NodeType::VARIABLE => ['name'],
NodeType::SELECTION_SET => ['selections'],
NodeType::FIELD => ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
NodeType::ARGUMENT => ['name', 'value'],
NodeType::FRAGMENT_SPREAD => ['name', 'directives'],
NodeType::INLINE_FRAGMENT => ['typeCondition', 'directives', 'selectionSet'],
NodeType::FRAGMENT_DEFINITION => ['name', 'typeCondition', 'directives', 'selectionSet'],
NodeKind::NAME => [],
NodeKind::DOCUMENT => ['definitions'],
NodeKind::OPERATION_DEFINITION => ['name', 'variableDefinitions', 'directives', 'selectionSet'],
NodeKind::VARIABLE_DEFINITION => ['variable', 'type', 'defaultValue'],
NodeKind::VARIABLE => ['name'],
NodeKind::SELECTION_SET => ['selections'],
NodeKind::FIELD => ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
NodeKind::ARGUMENT => ['name', 'value'],
NodeKind::FRAGMENT_SPREAD => ['name', 'directives'],
NodeKind::INLINE_FRAGMENT => ['typeCondition', 'directives', 'selectionSet'],
NodeKind::FRAGMENT_DEFINITION => ['name', 'typeCondition', 'directives', 'selectionSet'],
NodeType::INT => [],
NodeType::FLOAT => [],
NodeType::STRING => [],
NodeType::BOOLEAN => [],
NodeType::NULL => [],
NodeType::ENUM => [],
NodeType::LST => ['values'],
NodeType::OBJECT => ['fields'],
NodeType::OBJECT_FIELD => ['name', 'value'],
NodeType::DIRECTIVE => ['name', 'arguments'],
NodeType::NAMED_TYPE => ['name'],
NodeType::LIST_TYPE => ['type'],
NodeType::NON_NULL_TYPE => ['type'],
NodeKind::INT => [],
NodeKind::FLOAT => [],
NodeKind::STRING => [],
NodeKind::BOOLEAN => [],
NodeKind::NULL => [],
NodeKind::ENUM => [],
NodeKind::LST => ['values'],
NodeKind::OBJECT => ['fields'],
NodeKind::OBJECT_FIELD => ['name', 'value'],
NodeKind::DIRECTIVE => ['name', 'arguments'],
NodeKind::NAMED_TYPE => ['name'],
NodeKind::LIST_TYPE => ['type'],
NodeKind::NON_NULL_TYPE => ['type'],
NodeType::SCHEMA_DEFINITION => ['directives', 'operationTypes'],
NodeType::OPERATION_TYPE_DEFINITION => ['type'],
NodeType::SCALAR_TYPE_DEFINITION => ['name', 'directives'],
NodeType::OBJECT_TYPE_DEFINITION => ['name', 'interfaces', 'directives', 'fields'],
NodeType::FIELD_DEFINITION => ['name', 'arguments', 'type', 'directives'],
NodeType::INPUT_VALUE_DEFINITION => ['name', 'type', 'defaultValue', 'directives'],
NodeType::INTERFACE_TYPE_DEFINITION => [ 'name', 'directives', 'fields' ],
NodeType::UNION_TYPE_DEFINITION => [ 'name', 'directives', 'types' ],
NodeType::ENUM_TYPE_DEFINITION => [ 'name', 'directives', 'values' ],
NodeType::ENUM_VALUE_DEFINITION => [ 'name', 'directives' ],
NodeType::INPUT_OBJECT_TYPE_DEFINITION => [ 'name', 'directives', 'fields' ],
NodeType::TYPE_EXTENSION_DEFINITION => [ 'definition' ],
NodeType::DIRECTIVE_DEFINITION => [ 'name', 'arguments', 'locations' ]
NodeKind::SCHEMA_DEFINITION => ['directives', 'operationTypes'],
NodeKind::OPERATION_TYPE_DEFINITION => ['type'],
NodeKind::SCALAR_TYPE_DEFINITION => ['name', 'directives'],
NodeKind::OBJECT_TYPE_DEFINITION => ['name', 'interfaces', 'directives', 'fields'],
NodeKind::FIELD_DEFINITION => ['name', 'arguments', 'type', 'directives'],
NodeKind::INPUT_VALUE_DEFINITION => ['name', 'type', 'defaultValue', 'directives'],
NodeKind::INTERFACE_TYPE_DEFINITION => [ 'name', 'directives', 'fields' ],
NodeKind::UNION_TYPE_DEFINITION => [ 'name', 'directives', 'types' ],
NodeKind::ENUM_TYPE_DEFINITION => [ 'name', 'directives', 'values' ],
NodeKind::ENUM_VALUE_DEFINITION => [ 'name', 'directives' ],
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => [ 'name', 'directives', 'fields' ],
NodeKind::TYPE_EXTENSION_DEFINITION => [ 'definition' ],
NodeKind::DIRECTIVE_DEFINITION => [ 'name', 'arguments', 'locations' ]
];
/**

View File

@ -5,7 +5,7 @@ use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\ListTypeNode;
use GraphQL\Language\AST\NamedTypeNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\NonNullTypeNode;
use GraphQL\Schema;
use GraphQL\Type\Definition\AbstractType;
@ -310,7 +310,7 @@ class TypeInfo
$schema = $this->schema;
switch ($node->kind) {
case NodeType::SELECTION_SET:
case NodeKind::SELECTION_SET:
$namedType = Type::getNamedType($this->getType());
$compositeType = null;
if (Type::isCompositeType($namedType)) {
@ -320,7 +320,7 @@ class TypeInfo
$this->parentTypeStack[] = $compositeType; // push
break;
case NodeType::FIELD:
case NodeKind::FIELD:
$parentType = $this->getParentType();
$fieldDef = null;
if ($parentType) {
@ -330,11 +330,11 @@ class TypeInfo
$this->typeStack[] = $fieldDef ? $fieldDef->getType() : null; // push
break;
case NodeType::DIRECTIVE:
case NodeKind::DIRECTIVE:
$this->directive = $schema->getDirective($node->name->value);
break;
case NodeType::OPERATION_DEFINITION:
case NodeKind::OPERATION_DEFINITION:
$type = null;
if ($node->operation === 'query') {
$type = $schema->getQueryType();
@ -346,19 +346,19 @@ class TypeInfo
$this->typeStack[] = $type; // push
break;
case NodeType::INLINE_FRAGMENT:
case NodeType::FRAGMENT_DEFINITION:
case NodeKind::INLINE_FRAGMENT:
case NodeKind::FRAGMENT_DEFINITION:
$typeConditionNode = $node->typeCondition;
$outputType = $typeConditionNode ? self::typeFromAST($schema, $typeConditionNode) : $this->getType();
$this->typeStack[] = $outputType; // push
break;
case NodeType::VARIABLE_DEFINITION:
case NodeKind::VARIABLE_DEFINITION:
$inputType = self::typeFromAST($schema, $node->type);
$this->inputTypeStack[] = $inputType; // push
break;
case NodeType::ARGUMENT:
case NodeKind::ARGUMENT:
$fieldOrDirective = $this->getDirective() ?: $this->getFieldDef();
$argDef = $argType = null;
if ($fieldOrDirective) {
@ -371,12 +371,12 @@ class TypeInfo
$this->inputTypeStack[] = $argType; // push
break;
case NodeType::LST:
case NodeKind::LST:
$listType = Type::getNullableType($this->getInputType());
$this->inputTypeStack[] = ($listType instanceof ListOfType ? $listType->getWrappedType() : null); // push
break;
case NodeType::OBJECT_FIELD:
case NodeKind::OBJECT_FIELD:
$objectType = Type::getNamedType($this->getInputType());
$fieldType = null;
if ($objectType instanceof InputObjectType) {
@ -395,33 +395,33 @@ class TypeInfo
function leave(Node $node)
{
switch ($node->kind) {
case NodeType::SELECTION_SET:
case NodeKind::SELECTION_SET:
array_pop($this->parentTypeStack);
break;
case NodeType::FIELD:
case NodeKind::FIELD:
array_pop($this->fieldDefStack);
array_pop($this->typeStack);
break;
case NodeType::DIRECTIVE:
case NodeKind::DIRECTIVE:
$this->directive = null;
break;
case NodeType::OPERATION_DEFINITION:
case NodeType::INLINE_FRAGMENT:
case NodeType::FRAGMENT_DEFINITION:
case NodeKind::OPERATION_DEFINITION:
case NodeKind::INLINE_FRAGMENT:
case NodeKind::FRAGMENT_DEFINITION:
array_pop($this->typeStack);
break;
case NodeType::VARIABLE_DEFINITION:
case NodeKind::VARIABLE_DEFINITION:
array_pop($this->inputTypeStack);
break;
case NodeType::ARGUMENT:
case NodeKind::ARGUMENT:
$this->argument = null;
array_pop($this->inputTypeStack);
break;
case NodeType::LST:
case NodeType::OBJECT_FIELD:
case NodeKind::LST:
case NodeKind::OBJECT_FIELD:
array_pop($this->inputTypeStack);
break;
}

View File

@ -7,7 +7,7 @@ use GraphQL\Language\AST\ListValueNode;
use GraphQL\Language\AST\DocumentNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\NullValueNode;
use GraphQL\Language\AST\ValueNode;
use GraphQL\Language\AST\VariableNode;
@ -195,7 +195,7 @@ class DocumentValidator
// Input objects check each defined field and look for undefined fields.
if ($type instanceof InputObjectType) {
if ($valueNode->kind !== NodeType::OBJECT) {
if ($valueNode->kind !== NodeKind::OBJECT) {
return [ "Expected \"{$type->name}\", found not an object." ];
}

View File

@ -7,7 +7,7 @@ use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Introspection;
@ -100,7 +100,7 @@ abstract class AbstractQuerySecurity
foreach ($selectionSet->selections as $selection) {
switch ($selection->kind) {
case NodeType::FIELD:
case NodeKind::FIELD:
/* @var FieldNode $selection */
$fieldName = $selection->name->value;
$fieldDef = null;
@ -127,7 +127,7 @@ abstract class AbstractQuerySecurity
// create field context
$_astAndDefs[$responseName][] = [$selection, $fieldDef];
break;
case NodeType::INLINE_FRAGMENT:
case NodeKind::INLINE_FRAGMENT:
/* @var InlineFragmentNode $selection */
$_astAndDefs = $this->collectFieldASTsAndDefs(
$context,
@ -137,7 +137,7 @@ abstract class AbstractQuerySecurity
$_astAndDefs
);
break;
case NodeType::FRAGMENT_SPREAD:
case NodeKind::FRAGMENT_SPREAD:
/* @var FragmentSpreadNode $selection */
$fragName = $selection->name->value;

View File

@ -6,7 +6,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\ArgumentNode;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Printer;
use GraphQL\Language\Visitor;
use GraphQL\Type\Definition\NonNull;
@ -26,7 +26,7 @@ class ArgumentsOfCorrectType
public function __invoke(ValidationContext $context)
{
return [
NodeType::ARGUMENT => function(ArgumentNode $argNode) use ($context) {
NodeKind::ARGUMENT => function(ArgumentNode $argNode) use ($context) {
$argDef = $context->getArgument();
if ($argDef) {
$errors = DocumentValidator::isValidLiteralValue($argDef->getType(), $argNode->value);

View File

@ -4,7 +4,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\VariableDefinitionNode;
use GraphQL\Language\Printer;
use GraphQL\Language\Visitor;
@ -30,7 +30,7 @@ class DefaultValuesOfCorrectType
public function __invoke(ValidationContext $context)
{
return [
NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $varDefNode) use ($context) {
NodeKind::VARIABLE_DEFINITION => function(VariableDefinitionNode $varDefNode) use ($context) {
$name = $varDefNode->variable->name->value;
$defaultValue = $varDefNode->defaultValue;
$type = $context->getInputType();
@ -52,8 +52,8 @@ class DefaultValuesOfCorrectType
}
return Visitor::skipNode();
},
NodeType::SELECTION_SET => function() {return Visitor::skipNode();},
NodeType::FRAGMENT_DEFINITION => function() {return Visitor::skipNode();}
NodeKind::SELECTION_SET => function() {return Visitor::skipNode();},
NodeKind::FRAGMENT_DEFINITION => function() {return Visitor::skipNode();}
];
}
}

View File

@ -5,7 +5,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Schema;
use GraphQL\Type\Definition\AbstractType;
use GraphQL\Utils;
@ -37,7 +37,7 @@ class FieldsOnCorrectType
public function __invoke(ValidationContext $context)
{
return [
NodeType::FIELD => function(FieldNode $node) use ($context) {
NodeKind::FIELD => function(FieldNode $node) use ($context) {
$type = $context->getParentType();
if ($type) {
$fieldDef = $context->getFieldDef();

View File

@ -6,7 +6,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Printer;
use GraphQL\Type\Definition\CompositeType;
use GraphQL\Type\Definition\Type;
@ -28,7 +28,7 @@ class FragmentsOnCompositeTypes
public function __invoke(ValidationContext $context)
{
return [
NodeType::INLINE_FRAGMENT => function(InlineFragmentNode $node) use ($context) {
NodeKind::INLINE_FRAGMENT => function(InlineFragmentNode $node) use ($context) {
$type = $context->getType();
if ($node->typeCondition && $type && !Type::isCompositeType($type)) {
@ -38,7 +38,7 @@ class FragmentsOnCompositeTypes
));
}
},
NodeType::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) use ($context) {
NodeKind::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $node) use ($context) {
$type = $context->getType();
if ($type && !Type::isCompositeType($type)) {

View File

@ -5,7 +5,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\ArgumentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Utils;
use GraphQL\Validator\Messages;
use GraphQL\Validator\ValidationContext;
@ -25,9 +25,9 @@ class KnownArgumentNames
public function __invoke(ValidationContext $context)
{
return [
NodeType::ARGUMENT => function(ArgumentNode $node, $key, $parent, $path, $ancestors) use ($context) {
NodeKind::ARGUMENT => function(ArgumentNode $node, $key, $parent, $path, $ancestors) use ($context) {
$argumentOf = $ancestors[count($ancestors) - 1];
if ($argumentOf->kind === NodeType::FIELD) {
if ($argumentOf->kind === NodeKind::FIELD) {
$fieldDef = $context->getFieldDef();
if ($fieldDef) {
@ -47,7 +47,7 @@ class KnownArgumentNames
));
}
}
} else if ($argumentOf->kind === NodeType::DIRECTIVE) {
} else if ($argumentOf->kind === NodeKind::DIRECTIVE) {
$directive = $context->getDirective();
if ($directive) {
$directiveArgDef = null;

View File

@ -9,7 +9,7 @@ use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Validator\Messages;
use GraphQL\Validator\ValidationContext;
@ -30,7 +30,7 @@ class KnownDirectives
public function __invoke(ValidationContext $context)
{
return [
NodeType::DIRECTIVE => function (DirectiveNode $node, $key, $parent, $path, $ancestors) use ($context) {
NodeKind::DIRECTIVE => function (DirectiveNode $node, $key, $parent, $path, $ancestors) use ($context) {
$directiveDef = null;
foreach ($context->getSchema()->getDirectives() as $def) {
if ($def->name === $node->name->value) {
@ -67,17 +67,17 @@ class KnownDirectives
private function getLocationForAppliedNode(Node $appliedTo)
{
switch ($appliedTo->kind) {
case NodeType::OPERATION_DEFINITION:
case NodeKind::OPERATION_DEFINITION:
switch ($appliedTo->operation) {
case 'query': return DirectiveDef::LOCATION_QUERY;
case 'mutation': return DirectiveDef::LOCATION_MUTATION;
case 'subscription': return DirectiveDef::LOCATION_SUBSCRIPTION;
}
break;
case NodeType::FIELD: return DirectiveDef::LOCATION_FIELD;
case NodeType::FRAGMENT_SPREAD: return DirectiveDef::LOCATION_FRAGMENT_SPREAD;
case NodeType::INLINE_FRAGMENT: return DirectiveDef::LOCATION_INLINE_FRAGMENT;
case NodeType::FRAGMENT_DEFINITION: return DirectiveDef::LOCATION_FRAGMENT_DEFINITION;
case NodeKind::FIELD: return DirectiveDef::LOCATION_FIELD;
case NodeKind::FRAGMENT_SPREAD: return DirectiveDef::LOCATION_FRAGMENT_SPREAD;
case NodeKind::INLINE_FRAGMENT: return DirectiveDef::LOCATION_INLINE_FRAGMENT;
case NodeKind::FRAGMENT_DEFINITION: return DirectiveDef::LOCATION_FRAGMENT_DEFINITION;
}
}
}

View File

@ -5,7 +5,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Validator\ValidationContext;
class KnownFragmentNames
@ -18,7 +18,7 @@ class KnownFragmentNames
public function __invoke(ValidationContext $context)
{
return [
NodeType::FRAGMENT_SPREAD => function(FragmentSpreadNode $node) use ($context) {
NodeKind::FRAGMENT_SPREAD => function(FragmentSpreadNode $node) use ($context) {
$fragmentName = $node->name->value;
$fragment = $context->getFragment($fragmentName);
if (!$fragment) {

View File

@ -4,7 +4,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\NamedTypeNode;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Visitor;
use GraphQL\Validator\ValidationContext;
@ -20,12 +20,12 @@ class KnownTypeNames
$skip = function() {return Visitor::skipNode();};
return [
NodeType::OBJECT_TYPE_DEFINITION => $skip,
NodeType::INTERFACE_TYPE_DEFINITION => $skip,
NodeType::UNION_TYPE_DEFINITION => $skip,
NodeType::INPUT_OBJECT_TYPE_DEFINITION => $skip,
NodeKind::OBJECT_TYPE_DEFINITION => $skip,
NodeKind::INTERFACE_TYPE_DEFINITION => $skip,
NodeKind::UNION_TYPE_DEFINITION => $skip,
NodeKind::INPUT_OBJECT_TYPE_DEFINITION => $skip,
NodeType::NAMED_TYPE => function(NamedTypeNode $node, $key) use ($context) {
NodeKind::NAMED_TYPE => function(NamedTypeNode $node, $key) use ($context) {
$typeName = $node->name->value;
$type = $context->getSchema()->getType($typeName);
if (!$type) {

View File

@ -4,7 +4,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\DocumentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Utils;
use GraphQL\Validator\ValidationContext;
@ -26,16 +26,16 @@ class LoneAnonymousOperation
{
$operationCount = 0;
return [
NodeType::DOCUMENT => function(DocumentNode $node) use (&$operationCount) {
NodeKind::DOCUMENT => function(DocumentNode $node) use (&$operationCount) {
$tmp = Utils::filter(
$node->definitions,
function ($definition) {
return $definition->kind === NodeType::OPERATION_DEFINITION;
return $definition->kind === NodeKind::OPERATION_DEFINITION;
}
);
$operationCount = count($tmp);
},
NodeType::OPERATION_DEFINITION => function(OperationDefinitionNode $node) use (&$operationCount, $context) {
NodeKind::OPERATION_DEFINITION => function(OperationDefinitionNode $node) use (&$operationCount, $context) {
if (!$node->name && $operationCount > 1) {
$context->reportError(
new Error(self::anonOperationNotAloneMessage(), [$node])

View File

@ -13,7 +13,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Visitor;
use GraphQL\Utils;
use GraphQL\Validator\ValidationContext;
@ -45,10 +45,10 @@ class NoFragmentCycles
$this->spreadPathIndexByName = [];
return [
NodeType::OPERATION_DEFINITION => function () {
NodeKind::OPERATION_DEFINITION => function () {
return Visitor::skipNode();
},
NodeType::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) {
NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) {
if (!isset($this->visitedFrags[$node->name->value])) {
$this->detectCycleRecursive($node, $context);
}

View File

@ -6,7 +6,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\VariableNode;
use GraphQL\Language\AST\VariableDefinitionNode;
@ -36,7 +36,7 @@ class NoUndefinedVariables
$variableNameDefined = [];
return [
NodeType::OPERATION_DEFINITION => [
NodeKind::OPERATION_DEFINITION => [
'enter' => function() use (&$variableNameDefined) {
$variableNameDefined = [];
},
@ -59,7 +59,7 @@ class NoUndefinedVariables
}
}
],
NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $def) use (&$variableNameDefined) {
NodeKind::VARIABLE_DEFINITION => function(VariableDefinitionNode $def) use (&$variableNameDefined) {
$variableNameDefined[$def->variable->name->value] = true;
}
];

View File

@ -6,7 +6,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Visitor;
use GraphQL\Validator\Messages;
use GraphQL\Validator\ValidationContext;
@ -28,15 +28,15 @@ class NoUnusedFragments
$this->fragmentDefs = [];
return [
NodeType::OPERATION_DEFINITION => function($node) {
NodeKind::OPERATION_DEFINITION => function($node) {
$this->operationDefs[] = $node;
return Visitor::skipNode();
},
NodeType::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $def) {
NodeKind::FRAGMENT_DEFINITION => function(FragmentDefinitionNode $def) {
$this->fragmentDefs[] = $def;
return Visitor::skipNode();
},
NodeType::DOCUMENT => [
NodeKind::DOCUMENT => [
'leave' => function() use ($context) {
$fragmentNameUsed = [];

View File

@ -4,7 +4,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\Visitor;
use GraphQL\Validator\Messages;
@ -26,7 +26,7 @@ class NoUnusedVariables
$this->variableDefs = [];
return [
NodeType::OPERATION_DEFINITION => [
NodeKind::OPERATION_DEFINITION => [
'enter' => function() {
$this->variableDefs = [];
},
@ -52,7 +52,7 @@ class NoUnusedVariables
}
}
],
NodeType::VARIABLE_DEFINITION => function($def) {
NodeKind::VARIABLE_DEFINITION => function($def) {
$this->variableDefs[] = $def;
}
];

View File

@ -10,7 +10,7 @@ use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\NamedTypeNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Language\Printer;
use GraphQL\Type\Definition\ListOfType;
@ -54,7 +54,7 @@ class OverlappingFieldsCanBeMerged
$this->comparedSet = new PairSet();
return [
NodeType::SELECTION_SET => [
NodeKind::SELECTION_SET => [
// Note: we validate on the reverse traversal so deeper conflicts will be
// caught first, for clearer error messages.
'leave' => function(SelectionSetNode $selectionSet) use ($context) {
@ -318,7 +318,7 @@ class OverlappingFieldsCanBeMerged
$selection = $selectionSet->selections[$i];
switch ($selection->kind) {
case NodeType::FIELD:
case NodeKind::FIELD:
$fieldName = $selection->name->value;
$fieldDef = null;
if ($parentType && method_exists($parentType, 'getFields')) {
@ -334,7 +334,7 @@ class OverlappingFieldsCanBeMerged
}
$_astAndDefs[$responseName][] = [$parentType, $selection, $fieldDef];
break;
case NodeType::INLINE_FRAGMENT:
case NodeKind::INLINE_FRAGMENT:
$typeCondition = $selection->typeCondition;
$inlineFragmentType = $typeCondition
? TypeInfo::typeFromAST($context->getSchema(), $typeCondition)
@ -348,7 +348,7 @@ class OverlappingFieldsCanBeMerged
$_astAndDefs
);
break;
case NodeType::FRAGMENT_SPREAD:
case NodeKind::FRAGMENT_SPREAD:
/** @var FragmentSpreadNode $selection */
$fragName = $selection->name->value;
if (!empty($_visitedFragmentNames[$fragName])) {

View File

@ -6,7 +6,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Utils;
use GraphQL\Validator\ValidationContext;
use GraphQL\Utils\TypeInfo;
@ -26,7 +26,7 @@ class PossibleFragmentSpreads
public function __invoke(ValidationContext $context)
{
return [
NodeType::INLINE_FRAGMENT => function(InlineFragmentNode $node) use ($context) {
NodeKind::INLINE_FRAGMENT => function(InlineFragmentNode $node) use ($context) {
$fragType = $context->getType();
$parentType = $context->getParentType();
@ -37,7 +37,7 @@ class PossibleFragmentSpreads
));
}
},
NodeType::FRAGMENT_SPREAD => function(FragmentSpreadNode $node) use ($context) {
NodeKind::FRAGMENT_SPREAD => function(FragmentSpreadNode $node) use ($context) {
$fragName = $node->name->value;
$fragType = $this->getFragmentType($context, $fragName);
$parentType = $context->getParentType();

View File

@ -6,7 +6,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\DirectiveNode;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Visitor;
use GraphQL\Type\Definition\NonNull;
use GraphQL\Utils;
@ -27,7 +27,7 @@ class ProvidedNonNullArguments
public function __invoke(ValidationContext $context)
{
return [
NodeType::FIELD => [
NodeKind::FIELD => [
'leave' => function(FieldNode $fieldNode) use ($context) {
$fieldDef = $context->getFieldDef();
@ -51,7 +51,7 @@ class ProvidedNonNullArguments
}
}
],
NodeType::DIRECTIVE => [
NodeKind::DIRECTIVE => [
'leave' => function(DirectiveNode $directiveNode) use ($context) {
$directiveDef = $context->getDirective();
if (!$directiveDef) {

View File

@ -8,7 +8,7 @@ use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Language\Visitor;
@ -78,7 +78,7 @@ class QueryComplexity extends AbstractQuerySecurity
return $this->invokeIfNeeded(
$context,
[
NodeType::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) {
NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) {
$this->fieldNodeAndDefs = $this->collectFieldASTsAndDefs(
$context,
$context->getParentType(),
@ -87,11 +87,11 @@ class QueryComplexity extends AbstractQuerySecurity
$this->fieldNodeAndDefs
);
},
NodeType::VARIABLE_DEFINITION => function ($def) {
NodeKind::VARIABLE_DEFINITION => function ($def) {
$this->variableDefs[] = $def;
return Visitor::skipNode();
},
NodeType::OPERATION_DEFINITION => [
NodeKind::OPERATION_DEFINITION => [
'leave' => function (OperationDefinitionNode $operationDefinition) use ($context, &$complexity) {
$complexity = $this->fieldComplexity($operationDefinition, $complexity);
@ -120,7 +120,7 @@ class QueryComplexity extends AbstractQuerySecurity
private function nodeComplexity(Node $node, $complexity = 0)
{
switch ($node->kind) {
case NodeType::FIELD:
case NodeKind::FIELD:
/* @var FieldNode $node */
// default values
$args = [];
@ -148,7 +148,7 @@ class QueryComplexity extends AbstractQuerySecurity
$complexity += call_user_func_array($complexityFn, [$childrenComplexity, $args]);
break;
case NodeType::INLINE_FRAGMENT:
case NodeKind::INLINE_FRAGMENT:
/* @var InlineFragmentNode $node */
// node has children?
if (isset($node->selectionSet)) {
@ -156,7 +156,7 @@ class QueryComplexity extends AbstractQuerySecurity
}
break;
case NodeType::FRAGMENT_SPREAD:
case NodeKind::FRAGMENT_SPREAD:
/* @var FragmentSpreadNode $node */
$fragment = $this->getFragment($node);

View File

@ -6,7 +6,7 @@ use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\InlineFragmentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Validator\ValidationContext;
@ -50,7 +50,7 @@ class QueryDepth extends AbstractQuerySecurity
return $this->invokeIfNeeded(
$context,
[
NodeType::OPERATION_DEFINITION => [
NodeKind::OPERATION_DEFINITION => [
'leave' => function (OperationDefinitionNode $operationDefinition) use ($context) {
$maxDepth = $this->fieldDepth($operationDefinition);
@ -84,7 +84,7 @@ class QueryDepth extends AbstractQuerySecurity
private function nodeDepth(Node $node, $depth = 0, $maxDepth = 0)
{
switch ($node->kind) {
case NodeType::FIELD:
case NodeKind::FIELD:
/* @var FieldNode $node */
// node has children?
if (null !== $node->selectionSet) {
@ -96,7 +96,7 @@ class QueryDepth extends AbstractQuerySecurity
}
break;
case NodeType::INLINE_FRAGMENT:
case NodeKind::INLINE_FRAGMENT:
/* @var InlineFragmentNode $node */
// node has children?
if (null !== $node->selectionSet) {
@ -104,7 +104,7 @@ class QueryDepth extends AbstractQuerySecurity
}
break;
case NodeType::FRAGMENT_SPREAD:
case NodeKind::FRAGMENT_SPREAD:
/* @var FragmentSpreadNode $node */
$fragment = $this->getFragment($node);

View File

@ -5,7 +5,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Type\Definition\Type;
use GraphQL\Validator\Messages;
use GraphQL\Validator\ValidationContext;
@ -25,7 +25,7 @@ class ScalarLeafs
public function __invoke(ValidationContext $context)
{
return [
NodeType::FIELD => function(FieldNode $node) use ($context) {
NodeKind::FIELD => function(FieldNode $node) use ($context) {
$type = $context->getType();
if ($type) {
if (Type::isLeafType($type)) {

View File

@ -4,7 +4,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\ArgumentNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Visitor;
use GraphQL\Validator\ValidationContext;
@ -22,13 +22,13 @@ class UniqueArgumentNames
$this->knownArgNames = [];
return [
NodeType::FIELD => function () {
NodeKind::FIELD => function () {
$this->knownArgNames = [];;
},
NodeType::DIRECTIVE => function () {
NodeKind::DIRECTIVE => function () {
$this->knownArgNames = [];
},
NodeType::ARGUMENT => function (ArgumentNode $node) use ($context) {
NodeKind::ARGUMENT => function (ArgumentNode $node) use ($context) {
$argName = $node->name->value;
if (!empty($this->knownArgNames[$argName])) {
$context->reportError(new Error(

View File

@ -5,7 +5,7 @@ use GraphQL\Error\Error;
use GraphQL\Language\AST\ArgumentNode;
use GraphQL\Language\AST\FragmentDefinitionNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\Visitor;
use GraphQL\Validator\ValidationContext;
@ -23,10 +23,10 @@ class UniqueFragmentNames
$this->knownFragmentNames = [];
return [
NodeType::OPERATION_DEFINITION => function () {
NodeKind::OPERATION_DEFINITION => function () {
return Visitor::skipNode();
},
NodeType::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) {
NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) {
$fragmentName = $node->name->value;
if (!empty($this->knownFragmentNames[$fragmentName])) {
$context->reportError(new Error(

View File

@ -3,7 +3,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\ObjectFieldNode;
use GraphQL\Language\Visitor;
use GraphQL\Validator\ValidationContext;
@ -24,7 +24,7 @@ class UniqueInputFieldNames
$this->knownNameStack = [];
return [
NodeType::OBJECT => [
NodeKind::OBJECT => [
'enter' => function() {
$this->knownNameStack[] = $this->knownNames;
$this->knownNames = [];
@ -33,7 +33,7 @@ class UniqueInputFieldNames
$this->knownNames = array_pop($this->knownNameStack);
}
],
NodeType::OBJECT_FIELD => function(ObjectFieldNode $node) use ($context) {
NodeKind::OBJECT_FIELD => function(ObjectFieldNode $node) use ($context) {
$fieldName = $node->name->value;
if (!empty($this->knownNames[$fieldName])) {

View File

@ -3,7 +3,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\Visitor;
use GraphQL\Validator\ValidationContext;
@ -22,7 +22,7 @@ class UniqueOperationNames
$this->knownOperationNames = [];
return [
NodeType::OPERATION_DEFINITION => function(OperationDefinitionNode $node) use ($context) {
NodeKind::OPERATION_DEFINITION => function(OperationDefinitionNode $node) use ($context) {
$operationName = $node->name;
if ($operationName) {
@ -37,7 +37,7 @@ class UniqueOperationNames
}
return Visitor::skipNode();
},
NodeType::FRAGMENT_DEFINITION => function() {
NodeKind::FRAGMENT_DEFINITION => function() {
return Visitor::skipNode();
}
];

View File

@ -3,7 +3,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\VariableDefinitionNode;
use GraphQL\Validator\ValidationContext;
@ -21,10 +21,10 @@ class UniqueVariableNames
$this->knownVariableNames = [];
return [
NodeType::OPERATION_DEFINITION => function() {
NodeKind::OPERATION_DEFINITION => function() {
$this->knownVariableNames = [];
},
NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) use ($context) {
NodeKind::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) use ($context) {
$variableName = $node->variable->name->value;
if (!empty($this->knownVariableNames[$variableName])) {
$context->reportError(new Error(

View File

@ -4,7 +4,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\VariableDefinitionNode;
use GraphQL\Language\Printer;
use GraphQL\Type\Definition\InputType;
@ -22,7 +22,7 @@ class VariablesAreInputTypes
public function __invoke(ValidationContext $context)
{
return [
NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) use ($context) {
NodeKind::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) use ($context) {
$type = Utils\TypeInfo::typeFromAST($context->getSchema(), $node->type);
// If the variable type is not an input type, return an error.

View File

@ -5,7 +5,7 @@ namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\VariableNode;
use GraphQL\Language\AST\VariableDefinitionNode;
@ -29,7 +29,7 @@ class VariablesInAllowedPosition
public function __invoke(ValidationContext $context)
{
return [
NodeType::OPERATION_DEFINITION => [
NodeKind::OPERATION_DEFINITION => [
'enter' => function () {
$this->varDefMap = [];
},
@ -61,7 +61,7 @@ class VariablesInAllowedPosition
}
}
],
NodeType::VARIABLE_DEFINITION => function (VariableDefinitionNode $varDefNode) {
NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $varDefNode) {
$this->varDefMap[$varDefNode->variable->name->value] = $varDefNode;
}
];

View File

@ -3,7 +3,7 @@ namespace GraphQL\Validator;
use GraphQL\Language\AST\FragmentSpreadNode;
use GraphQL\Language\AST\HasSelectionSet;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\VariableNode;
use GraphQL\Language\Visitor;
@ -133,7 +133,7 @@ class ValidationContext
if (!$fragments) {
$this->fragments = $fragments =
array_reduce($this->getDocument()->definitions, function($frags, $statement) {
if ($statement->kind === NodeType::FRAGMENT_DEFINITION) {
if ($statement->kind === NodeKind::FRAGMENT_DEFINITION) {
$frags[$statement->name->value] = $statement;
}
return $frags;
@ -157,7 +157,7 @@ class ValidationContext
for ($i = 0; $i < count($set->selections); $i++) {
$selection = $set->selections[$i];
if ($selection->kind === NodeType::FRAGMENT_SPREAD) {
if ($selection->kind === NodeKind::FRAGMENT_SPREAD) {
$spreads[] = $selection;
} else if ($selection->selectionSet) {
$setsToVisit[] = $selection->selectionSet;
@ -214,10 +214,10 @@ class ValidationContext
$newUsages = [];
$typeInfo = new TypeInfo($this->schema);
Visitor::visit($node, Visitor::visitWithTypeInfo($typeInfo, [
NodeType::VARIABLE_DEFINITION => function () {
NodeKind::VARIABLE_DEFINITION => function () {
return false;
},
NodeType::VARIABLE => function (VariableNode $variable) use (&$newUsages, $typeInfo) {
NodeKind::VARIABLE => function (VariableNode $variable) use (&$newUsages, $typeInfo) {
$newUsages[] = ['node' => $variable, 'type' => $typeInfo->getInputType()];
}
]));

View File

@ -5,7 +5,7 @@ use GraphQL\Language\AST\ArgumentNode;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\NullValueNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Language\AST\StringValueNode;
@ -259,39 +259,39 @@ fragment $fragmentName on Type {
};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'loc' => $loc(0, 41),
'definitions' => [
[
'kind' => NodeType::OPERATION_DEFINITION,
'kind' => NodeKind::OPERATION_DEFINITION,
'loc' => $loc(0, 40),
'operation' => 'query',
'name' => null,
'variableDefinitions' => null,
'directives' => [],
'selectionSet' => [
'kind' => NodeType::SELECTION_SET,
'kind' => NodeKind::SELECTION_SET,
'loc' => $loc(0, 40),
'selections' => [
[
'kind' => NodeType::FIELD,
'kind' => NodeKind::FIELD,
'loc' => $loc(4, 38),
'alias' => null,
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => $loc(4, 8),
'value' => 'node'
],
'arguments' => [
[
'kind' => NodeType::ARGUMENT,
'kind' => NodeKind::ARGUMENT,
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => $loc(9, 11),
'value' => 'id'
],
'value' => [
'kind' => NodeType::INT,
'kind' => NodeKind::INT,
'loc' => $loc(13, 14),
'value' => '4'
],
@ -300,15 +300,15 @@ fragment $fragmentName on Type {
],
'directives' => [],
'selectionSet' => [
'kind' => NodeType::SELECTION_SET,
'kind' => NodeKind::SELECTION_SET,
'loc' => $loc(16, 38),
'selections' => [
[
'kind' => NodeType::FIELD,
'kind' => NodeKind::FIELD,
'loc' => $loc(22, 24),
'alias' => null,
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => $loc(22, 24),
'value' => 'id'
],
@ -317,11 +317,11 @@ fragment $fragmentName on Type {
'selectionSet' => null
],
[
'kind' => NodeType::FIELD,
'kind' => NodeKind::FIELD,
'loc' => $loc(30, 34),
'alias' => null,
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => $loc(30, 34),
'value' => 'name'
],
@ -391,7 +391,7 @@ fragment $fragmentName on Type {
public function testParsesNullValues()
{
$this->assertEquals([
'kind' => NodeType::NULL,
'kind' => NodeKind::NULL,
'loc' => ['start' => 0, 'end' => 4]
], $this->nodeToArray(Parser::parseValue('null')));
}
@ -402,16 +402,16 @@ fragment $fragmentName on Type {
public function testParsesListValues()
{
$this->assertEquals([
'kind' => NodeType::LST,
'kind' => NodeKind::LST,
'loc' => ['start' => 0, 'end' => 11],
'values' => [
[
'kind' => NodeType::INT,
'kind' => NodeKind::INT,
'loc' => ['start' => 1, 'end' => 4],
'value' => '123'
],
[
'kind' => NodeType::STRING,
'kind' => NodeKind::STRING,
'loc' => ['start' => 5, 'end' => 10],
'value' => 'abc'
]
@ -427,10 +427,10 @@ fragment $fragmentName on Type {
public function testParsesWellKnownTypes()
{
$this->assertEquals([
'kind' => NodeType::NAMED_TYPE,
'kind' => NodeKind::NAMED_TYPE,
'loc' => ['start' => 0, 'end' => 6],
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => ['start' => 0, 'end' => 6],
'value' => 'String'
]
@ -443,10 +443,10 @@ fragment $fragmentName on Type {
public function testParsesCustomTypes()
{
$this->assertEquals([
'kind' => NodeType::NAMED_TYPE,
'kind' => NodeKind::NAMED_TYPE,
'loc' => ['start' => 0, 'end' => 6],
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => ['start' => 0, 'end' => 6],
'value' => 'MyType'
]
@ -459,13 +459,13 @@ fragment $fragmentName on Type {
public function testParsesListTypes()
{
$this->assertEquals([
'kind' => NodeType::LIST_TYPE,
'kind' => NodeKind::LIST_TYPE,
'loc' => ['start' => 0, 'end' => 8],
'type' => [
'kind' => NodeType::NAMED_TYPE,
'kind' => NodeKind::NAMED_TYPE,
'loc' => ['start' => 1, 'end' => 7],
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => ['start' => 1, 'end' => 7],
'value' => 'MyType'
]
@ -479,13 +479,13 @@ fragment $fragmentName on Type {
public function testParsesNonNullTypes()
{
$this->assertEquals([
'kind' => NodeType::NON_NULL_TYPE,
'kind' => NodeKind::NON_NULL_TYPE,
'loc' => ['start' => 0, 'end' => 7],
'type' => [
'kind' => NodeType::NAMED_TYPE,
'kind' => NodeKind::NAMED_TYPE,
'loc' => ['start' => 0, 'end' => 6],
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => ['start' => 0, 'end' => 6],
'value' => 'MyType'
]
@ -499,16 +499,16 @@ fragment $fragmentName on Type {
public function testParsesNestedTypes()
{
$this->assertEquals([
'kind' => NodeType::LIST_TYPE,
'kind' => NodeKind::LIST_TYPE,
'loc' => ['start' => 0, 'end' => 9],
'type' => [
'kind' => NodeType::NON_NULL_TYPE,
'kind' => NodeKind::NON_NULL_TYPE,
'loc' => ['start' => 1, 'end' => 8],
'type' => [
'kind' => NodeType::NAMED_TYPE,
'kind' => NodeKind::NAMED_TYPE,
'loc' => ['start' => 1, 'end' => 7],
'name' => [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'loc' => ['start' => 1, 'end' => 7],
'value' => 'MyType'
]

View File

@ -14,7 +14,7 @@ use GraphQL\Language\AST\Location;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\AST\NamedTypeNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\NonNullTypeNode;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\AST\ScalarTypeDefinitionNode;
@ -40,10 +40,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -77,12 +77,12 @@ extend type Hello {
return TestUtils::locArray($start, $end);
};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::TYPE_EXTENSION_DEFINITION,
'kind' => NodeKind::TYPE_EXTENSION_DEFINITION,
'definition' => [
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(13, 18)),
'interfaces' => [],
'directives' => [],
@ -118,10 +118,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6,11)),
'interfaces' => [],
'directives' => [],
@ -129,7 +129,7 @@ type Hello {
$this->fieldNode(
$this->nameNode('world', $loc(16, 21)),
[
'kind' => NodeType::NON_NULL_TYPE,
'kind' => NodeKind::NON_NULL_TYPE,
'type' => $this->typeNode('String', $loc(23, 29)),
'loc' => $loc(23, 30)
],
@ -155,10 +155,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'interfaces' => [
$this->typeNode('World', $loc(22, 27))
@ -184,10 +184,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'interfaces' => [
$this->typeNode('Wo', $loc(22,24)),
@ -214,10 +214,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::ENUM_TYPE_DEFINITION,
'kind' => NodeKind::ENUM_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'directives' => [],
'values' => [$this->enumValueNode('WORLD', $loc(13, 18))],
@ -240,10 +240,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::ENUM_TYPE_DEFINITION,
'kind' => NodeKind::ENUM_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'directives' => [],
'values' => [
@ -272,10 +272,10 @@ interface Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::INTERFACE_TYPE_DEFINITION,
'kind' => NodeKind::INTERFACE_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(11, 16)),
'directives' => [],
'fields' => [
@ -306,10 +306,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -350,10 +350,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -365,7 +365,7 @@ type Hello {
$this->inputValueNode(
$this->nameNode('flag', $loc(22, 26)),
$this->typeNode('Boolean', $loc(28, 35)),
['kind' => NodeType::BOOLEAN, 'value' => true, 'loc' => $loc(38, 42)],
['kind' => NodeKind::BOOLEAN, 'value' => true, 'loc' => $loc(38, 42)],
$loc(22, 42)
)
],
@ -393,10 +393,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -407,7 +407,7 @@ type Hello {
[
$this->inputValueNode(
$this->nameNode('things', $loc(22,28)),
['kind' => NodeType::LIST_TYPE, 'type' => $this->typeNode('String', $loc(31, 37)), 'loc' => $loc(30, 38)],
['kind' => NodeKind::LIST_TYPE, 'type' => $this->typeNode('String', $loc(31, 37)), 'loc' => $loc(30, 38)],
null,
$loc(22, 38)
)
@ -437,10 +437,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -483,10 +483,10 @@ type Hello {
$doc = Parser::parse($body);
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::UNION_TYPE_DEFINITION,
'kind' => NodeKind::UNION_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'directives' => [],
'types' => [$this->typeNode('World', $loc(14, 19))],
@ -509,10 +509,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::UNION_TYPE_DEFINITION,
'kind' => NodeKind::UNION_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'directives' => [],
'types' => [
@ -536,10 +536,10 @@ type Hello {
$doc = Parser::parse($body);
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::SCALAR_TYPE_DEFINITION,
'kind' => NodeKind::SCALAR_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(7, 12)),
'directives' => [],
'loc' => $loc(0, 12)
@ -563,10 +563,10 @@ input Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => NodeType::DOCUMENT,
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeType::INPUT_OBJECT_TYPE_DEFINITION,
'kind' => NodeKind::INPUT_OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(7, 12)),
'directives' => [],
'fields' => [
@ -601,8 +601,8 @@ input Hello {
private function typeNode($name, $loc)
{
return [
'kind' => NodeType::NAMED_TYPE,
'name' => ['kind' => NodeType::NAME, 'value' => $name, 'loc' => $loc],
'kind' => NodeKind::NAMED_TYPE,
'name' => ['kind' => NodeKind::NAME, 'value' => $name, 'loc' => $loc],
'loc' => $loc
];
}
@ -610,7 +610,7 @@ input Hello {
private function nameNode($name, $loc)
{
return [
'kind' => NodeType::NAME,
'kind' => NodeKind::NAME,
'value' => $name,
'loc' => $loc
];
@ -624,7 +624,7 @@ input Hello {
private function fieldNodeWithArgs($name, $type, $args, $loc)
{
return [
'kind' => NodeType::FIELD_DEFINITION,
'kind' => NodeKind::FIELD_DEFINITION,
'name' => $name,
'arguments' => $args,
'type' => $type,
@ -636,7 +636,7 @@ input Hello {
private function enumValueNode($name, $loc)
{
return [
'kind' => NodeType::ENUM_VALUE_DEFINITION,
'kind' => NodeKind::ENUM_VALUE_DEFINITION,
'name' => $this->nameNode($name, $loc),
'directives' => [],
'loc' => $loc
@ -646,7 +646,7 @@ input Hello {
private function inputValueNode($name, $type, $defaultValue, $loc)
{
return [
'kind' => NodeType::INPUT_VALUE_DEFINITION,
'kind' => NodeKind::INPUT_VALUE_DEFINITION,
'name' => $name,
'type' => $type,
'defaultValue' => $defaultValue,

View File

@ -5,7 +5,7 @@ use GraphQL\Language\AST\DocumentNode;
use GraphQL\Language\AST\FieldNode;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Language\AST\SelectionSetNode;
use GraphQL\Language\Parser;
@ -26,7 +26,7 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
$selectionSet = null;
$editedAst = Visitor::visit($ast, [
NodeType::OPERATION_DEFINITION => [
NodeKind::OPERATION_DEFINITION => [
'enter' => function(OperationDefinitionNode $node) use (&$selectionSet) {
$selectionSet = $node->selectionSet;
@ -64,7 +64,7 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
$definitions = $ast->definitions;
$editedAst = Visitor::visit($ast, [
NodeType::DOCUMENT => [
NodeKind::DOCUMENT => [
'enter' => function (DocumentNode $node) {
$tmp = clone $node;
$tmp->definitions = [];
@ -265,7 +265,7 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
'leave' => function($node) use (&$visited) {
$visited[] = ['leave', $node->kind, isset($node->value) ? $node->value : null];
if ($node->kind === NodeType::NAME && $node->value === 'x') {
if ($node->kind === NodeKind::NAME && $node->value === 'x') {
return Visitor::stop();
}
}
@ -298,10 +298,10 @@ class VisitorTest extends \PHPUnit_Framework_TestCase
$ast = Parser::parse('{ a, b { x }, c }');
Visitor::visit($ast, [
NodeType::NAME => function(NameNode $node) use (&$visited) {
NodeKind::NAME => function(NameNode $node) use (&$visited) {
$visited[] = ['enter', $node->kind, $node->value];
},
NodeType::SELECTION_SET => [
NodeKind::SELECTION_SET => [
'enter' => function(SelectionSetNode $node) use (&$visited) {
$visited[] = ['enter', $node->kind, null];
},