move NodeTypes enum to seperate class

This commit is contained in:
Andreas Heiberg 2016-11-10 17:25:54 +00:00 committed by vladar
parent 2e25f51829
commit 46788f2ddb
42 changed files with 264 additions and 266 deletions

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ class DirectiveDefinition extends Node implements TypeSystemDefinition
/**
* @var string
*/
public $kind = Node::DIRECTIVE_DEFINITION;
public $kind = NodeType::DIRECTIVE_DEFINITION;
/**
* @var Name

View File

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

View File

@ -6,7 +6,7 @@ class EnumTypeDefinition extends Node implements TypeDefinition
/**
* @var string
*/
public $kind = self::ENUM_TYPE_DEFINITION;
public $kind = NodeType::ENUM_TYPE_DEFINITION;
/**
* @var Name

View File

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

View File

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

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class Field extends Node implements Selection
{
public $kind = Node::FIELD;
public $kind = NodeType::FIELD;
/**
* @var Name

View File

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

View File

@ -1,10 +1,9 @@
<?php
namespace GraphQL\Language\AST;
class FloatValue extends Node implements Value
{
public $kind = Node::FLOAT;
public $kind = NodeType::FLOAT;
/**
* @var string

View File

@ -1,10 +1,9 @@
<?php
namespace GraphQL\Language\AST;
class FragmentDefinition extends Node implements Definition, HasSelectionSet
{
public $kind = Node::FRAGMENT_DEFINITION;
public $kind = NodeType::FRAGMENT_DEFINITION;
/**
* @var Name

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class FragmentSpread extends Node implements Selection
{
public $kind = Node::FRAGMENT_SPREAD;
public $kind = NodeType::FRAGMENT_SPREAD;
/**
* @var Name

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class InlineFragment extends Node implements Selection
{
public $kind = Node::INLINE_FRAGMENT;
public $kind = NodeType::INLINE_FRAGMENT;
/**
* @var NamedType

View File

@ -6,7 +6,7 @@ class InputObjectTypeDefinition extends Node implements TypeDefinition
/**
* @var string
*/
public $kind = Node::INPUT_OBJECT_TYPE_DEFINITION;
public $kind = NodeType::INPUT_OBJECT_TYPE_DEFINITION;
/**
* @var Name

View File

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

View File

@ -1,10 +1,9 @@
<?php
namespace GraphQL\Language\AST;
class IntValue extends Node implements Value
{
public $kind = Node::INT;
public $kind = NodeType::INT;
/**
* @var string

View File

@ -6,7 +6,7 @@ class InterfaceTypeDefinition extends Node implements TypeDefinition
/**
* @var string
*/
public $kind = Node::INTERFACE_TYPE_DEFINITION;
public $kind = NodeType::INTERFACE_TYPE_DEFINITION;
/**
* @var Name

View File

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

View File

@ -1,9 +1,10 @@
<?php
namespace GraphQL\Language\AST;
class ListValue extends Node implements Value
{
public $kind = Node::LST;
public $kind = NodeType::LST;
/**
* @var array<Value>

View File

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

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class NamedType extends Node implements Type
{
public $kind = Node::NAMED_TYPE;
public $kind = NodeType::NAMED_TYPE;
/**
* @var Name

View File

@ -3,78 +3,8 @@ namespace GraphQL\Language\AST;
use GraphQL\Utils;
/**
* Class Node
* @package GraphQL\Language\AST
*/
abstract class Node
{
// constants from language/kinds.js:
const NAME = 'Name';
// Document
const DOCUMENT = 'Document';
const OPERATION_DEFINITION = 'OperationDefinition';
const VARIABLE_DEFINITION = 'VariableDefinition';
const VARIABLE = 'Variable';
const SELECTION_SET = 'SelectionSet';
const FIELD = 'Field';
const ARGUMENT = 'Argument';
// Fragments
const FRAGMENT_SPREAD = 'FragmentSpread';
const INLINE_FRAGMENT = 'InlineFragment';
const FRAGMENT_DEFINITION = 'FragmentDefinition';
// Values
const INT = 'IntValue';
const FLOAT = 'FloatValue';
const STRING = 'StringValue';
const BOOLEAN = 'BooleanValue';
const ENUM = 'EnumValue';
const LST = 'ListValue';
const OBJECT = 'ObjectValue';
const OBJECT_FIELD = 'ObjectField';
// Directives
const DIRECTIVE = 'Directive';
// Types
const NAMED_TYPE = 'NamedType';
const LIST_TYPE = 'ListType';
const NON_NULL_TYPE = 'NonNullType';
// Type System Definitions
const SCHEMA_DEFINITION = 'SchemaDefinition';
const OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition';
// Type Definitions
const SCALAR_TYPE_DEFINITION = 'ScalarTypeDefinition';
const OBJECT_TYPE_DEFINITION = 'ObjectTypeDefinition';
const FIELD_DEFINITION = 'FieldDefinition';
const INPUT_VALUE_DEFINITION = 'InputValueDefinition';
const INTERFACE_TYPE_DEFINITION = 'InterfaceTypeDefinition';
const UNION_TYPE_DEFINITION = 'UnionTypeDefinition';
const ENUM_TYPE_DEFINITION = 'EnumTypeDefinition';
const ENUM_VALUE_DEFINITION = 'EnumValueDefinition';
const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition';
// Type Extensions
const TYPE_EXTENSION_DEFINITION = 'TypeExtensionDefinition';
// Directive Definitions
const DIRECTIVE_DEFINITION = 'DirectiveDefinition';
/**
type Node = Name
| Document

View File

@ -0,0 +1,72 @@
<?php
namespace GraphQL\Language\AST;
class NodeType
{
// constants from language/kinds.js:
const NAME = 'Name';
// Document
const DOCUMENT = 'Document';
const OPERATION_DEFINITION = 'OperationDefinition';
const VARIABLE_DEFINITION = 'VariableDefinition';
const VARIABLE = 'Variable';
const SELECTION_SET = 'SelectionSet';
const FIELD = 'Field';
const ARGUMENT = 'Argument';
// Fragments
const FRAGMENT_SPREAD = 'FragmentSpread';
const INLINE_FRAGMENT = 'InlineFragment';
const FRAGMENT_DEFINITION = 'FragmentDefinition';
// Values
const INT = 'IntValue';
const FLOAT = 'FloatValue';
const STRING = 'StringValue';
const BOOLEAN = 'BooleanValue';
const ENUM = 'EnumValue';
const LST = 'ListValue';
const OBJECT = 'ObjectValue';
const OBJECT_FIELD = 'ObjectField';
// Directives
const DIRECTIVE = 'Directive';
// Types
const NAMED_TYPE = 'NamedType';
const LIST_TYPE = 'ListType';
const NON_NULL_TYPE = 'NonNullType';
// Type System Definitions
const SCHEMA_DEFINITION = 'SchemaDefinition';
const OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition';
// Type Definitions
const SCALAR_TYPE_DEFINITION = 'ScalarTypeDefinition';
const OBJECT_TYPE_DEFINITION = 'ObjectTypeDefinition';
const FIELD_DEFINITION = 'FieldDefinition';
const INPUT_VALUE_DEFINITION = 'InputValueDefinition';
const INTERFACE_TYPE_DEFINITION = 'InterfaceTypeDefinition';
const UNION_TYPE_DEFINITION = 'UnionTypeDefinition';
const ENUM_TYPE_DEFINITION = 'EnumTypeDefinition';
const ENUM_VALUE_DEFINITION = 'EnumValueDefinition';
const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition';
// Type Extensions
const TYPE_EXTENSION_DEFINITION = 'TypeExtensionDefinition';
// Directive Definitions
const DIRECTIVE_DEFINITION = 'DirectiveDefinition';
}

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class NonNullType extends Node implements Type
{
public $kind = Node::NON_NULL_TYPE;
public $kind = NodeType::NON_NULL_TYPE;
/**
* @var Name | ListType

View File

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

View File

@ -6,7 +6,7 @@ class ObjectTypeDefinition extends Node implements TypeDefinition
/**
* @var string
*/
public $kind = Node::OBJECT_TYPE_DEFINITION;
public $kind = NodeType::OBJECT_TYPE_DEFINITION;
/**
* @var Name

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class ObjectValue extends Node implements Value
{
public $kind = Node::OBJECT;
public $kind = NodeType::OBJECT;
/**
* @var array<ObjectField>

View File

@ -6,7 +6,7 @@ class OperationDefinition extends Node implements Definition, HasSelectionSet
/**
* @var string
*/
public $kind = Node::OPERATION_DEFINITION;
public $kind = NodeType::OPERATION_DEFINITION;
/**
* @var Name

View File

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

View File

@ -1,13 +1,12 @@
<?php
namespace GraphQL\Language\AST;
class ScalarTypeDefinition extends Node implements TypeDefinition
{
/**
* @var string
*/
public $kind = Node::SCALAR_TYPE_DEFINITION;
public $kind = NodeType::SCALAR_TYPE_DEFINITION;
/**
* @var Name

View File

@ -6,7 +6,7 @@ class SchemaDefinition extends Node implements TypeSystemDefinition
/**
* @var string
*/
public $kind = Node::SCHEMA_DEFINITION;
public $kind = NodeType::SCHEMA_DEFINITION;
/**
* @var Directive[]

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class SelectionSet extends Node
{
public $kind = Node::SELECTION_SET;
public $kind = NodeType::SELECTION_SET;
/**
* @var array<Selection>

View File

@ -1,10 +1,9 @@
<?php
namespace GraphQL\Language\AST;
class StringValue extends Node implements Value
{
public $kind = Node::STRING;
public $kind = NodeType::STRING;
/**
* @var string

View File

@ -6,7 +6,7 @@ class TypeExtensionDefinition extends Node implements TypeSystemDefinition
/**
* @var string
*/
public $kind = Node::TYPE_EXTENSION_DEFINITION;
public $kind = NodeType::TYPE_EXTENSION_DEFINITION;
/**
* @var ObjectTypeDefinition

View File

@ -6,7 +6,7 @@ class UnionTypeDefinition extends Node implements TypeDefinition
/**
* @var string
*/
public $kind = self::UNION_TYPE_DEFINITION;
public $kind = NodeType::UNION_TYPE_DEFINITION;
/**
* @var Name

View File

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

View File

@ -3,7 +3,7 @@ namespace GraphQL\Language\AST;
class VariableDefinition extends Node implements Definition
{
public $kind = Node::VARIABLE_DEFINITION;
public $kind = NodeType::VARIABLE_DEFINITION;
/**
* @var Variable

View File

@ -24,6 +24,7 @@ use GraphQL\Language\AST\IntValue;
use GraphQL\Language\AST\ListType;
use GraphQL\Language\AST\NamedType;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NonNullType;
use GraphQL\Language\AST\ObjectField;
use GraphQL\Language\AST\ObjectTypeDefinition;
@ -44,16 +45,16 @@ class Printer
{
return Visitor::visit($ast, [
'leave' => [
Node::NAME => function($node) {
NodeType::NAME => function($node) {
return '' . $node->value;
},
Node::VARIABLE => function($node) {
NodeType::VARIABLE => function($node) {
return '$' . $node->name;
},
Node::DOCUMENT => function(Document $node) {
NodeType::DOCUMENT => function(Document $node) {
return $this->join($node->definitions, "\n\n") . "\n";
},
Node::OPERATION_DEFINITION => function(OperationDefinition $node) {
NodeType::OPERATION_DEFINITION => function(OperationDefinition $node) {
$op = $node->operation;
$name = $node->name;
$varDefs = $this->wrap('(', $this->join($node->variableDefinitions, ', '), ')');
@ -65,28 +66,28 @@ class Printer
? $selectionSet
: $this->join([$op, $this->join([$name, $varDefs]), $directives, $selectionSet], ' ');
},
Node::VARIABLE_DEFINITION => function(VariableDefinition $node) {
NodeType::VARIABLE_DEFINITION => function(VariableDefinition $node) {
return $node->variable . ': ' . $node->type . $this->wrap(' = ', $node->defaultValue);
},
Node::SELECTION_SET => function(SelectionSet $node) {
NodeType::SELECTION_SET => function(SelectionSet $node) {
return $this->block($node->selections);
},
Node::FIELD => function(Field $node) {
NodeType::FIELD => function(Field $node) {
return $this->join([
$this->wrap('', $node->alias, ': ') . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')'),
$this->join($node->directives, ' '),
$node->selectionSet
], ' ');
},
Node::ARGUMENT => function(Argument $node) {
NodeType::ARGUMENT => function(Argument $node) {
return $node->name . ': ' . $node->value;
},
// Fragments
Node::FRAGMENT_SPREAD => function(FragmentSpread $node) {
NodeType::FRAGMENT_SPREAD => function(FragmentSpread $node) {
return '...' . $node->name . $this->wrap(' ', $this->join($node->directives, ' '));
},
Node::INLINE_FRAGMENT => function(InlineFragment $node) {
NodeType::INLINE_FRAGMENT => function(InlineFragment $node) {
return $this->join([
"...",
$this->wrap('on ', $node->typeCondition),
@ -94,46 +95,46 @@ class Printer
$node->selectionSet
], ' ');
},
Node::FRAGMENT_DEFINITION => function(FragmentDefinition $node) {
NodeType::FRAGMENT_DEFINITION => function(FragmentDefinition $node) {
return "fragment {$node->name} on {$node->typeCondition} "
. $this->wrap('', $this->join($node->directives, ' '), ' ')
. $node->selectionSet;
},
// Value
Node::INT => function(IntValue $node) {return $node->value;},
Node::FLOAT => function(FloatValue $node) {return $node->value;},
Node::STRING => function(StringValue $node) {return json_encode($node->value);},
Node::BOOLEAN => function(BooleanValue $node) {return $node->value ? 'true' : 'false';},
Node::ENUM => function(EnumValue $node) {return $node->value;},
Node::LST => function(ListValue $node) {return '[' . $this->join($node->values, ', ') . ']';},
Node::OBJECT => function(ObjectValue $node) {return '{' . $this->join($node->fields, ', ') . '}';},
Node::OBJECT_FIELD => function(ObjectField $node) {return $node->name . ': ' . $node->value;},
NodeType::INT => function(IntValue $node) {return $node->value;},
NodeType::FLOAT => function(FloatValue $node) {return $node->value;},
NodeType::STRING => function(StringValue $node) {return json_encode($node->value);},
NodeType::BOOLEAN => function(BooleanValue $node) {return $node->value ? 'true' : 'false';},
NodeType::ENUM => function(EnumValue $node) {return $node->value;},
NodeType::LST => function(ListValue $node) {return '[' . $this->join($node->values, ', ') . ']';},
NodeType::OBJECT => function(ObjectValue $node) {return '{' . $this->join($node->fields, ', ') . '}';},
NodeType::OBJECT_FIELD => function(ObjectField $node) {return $node->name . ': ' . $node->value;},
// Directive
Node::DIRECTIVE => function(Directive $node) {
NodeType::DIRECTIVE => function(Directive $node) {
return '@' . $node->name . $this->wrap('(', $this->join($node->arguments, ', '), ')');
},
// Type
Node::NAMED_TYPE => function(NamedType $node) {return $node->name;},
Node::LIST_TYPE => function(ListType $node) {return '[' . $node->type . ']';},
Node::NON_NULL_TYPE => function(NonNullType $node) {return $node->type . '!';},
NodeType::NAMED_TYPE => function(NamedType $node) {return $node->name;},
NodeType::LIST_TYPE => function(ListType $node) {return '[' . $node->type . ']';},
NodeType::NON_NULL_TYPE => function(NonNullType $node) {return $node->type . '!';},
// Type System Definitions
Node::SCHEMA_DEFINITION => function(SchemaDefinition $def) {
NodeType::SCHEMA_DEFINITION => function(SchemaDefinition $def) {
return $this->join([
'schema',
$this->join($def->directives, ' '),
$this->block($def->operationTypes)
], ' ');
},
Node::OPERATION_TYPE_DEFINITION => function(OperationTypeDefinition $def) {return $def->operation . ': ' . $def->type;},
NodeType::OPERATION_TYPE_DEFINITION => function(OperationTypeDefinition $def) {return $def->operation . ': ' . $def->type;},
Node::SCALAR_TYPE_DEFINITION => function(ScalarTypeDefinition $def) {
NodeType::SCALAR_TYPE_DEFINITION => function(ScalarTypeDefinition $def) {
return $this->join(['scalar', $def->name, $this->join($def->directives, ' ')], ' ');
},
Node::OBJECT_TYPE_DEFINITION => function(ObjectTypeDefinition $def) {
NodeType::OBJECT_TYPE_DEFINITION => function(ObjectTypeDefinition $def) {
return $this->join([
'type',
$def->name,
@ -142,20 +143,20 @@ class Printer
$this->block($def->fields)
], ' ');
},
Node::FIELD_DEFINITION => function(FieldDefinition $def) {
NodeType::FIELD_DEFINITION => function(FieldDefinition $def) {
return $def->name
. $this->wrap('(', $this->join($def->arguments, ', '), ')')
. ': ' . $def->type
. $this->wrap(' ', $this->join($def->directives, ' '));
},
Node::INPUT_VALUE_DEFINITION => function(InputValueDefinition $def) {
NodeType::INPUT_VALUE_DEFINITION => function(InputValueDefinition $def) {
return $this->join([
$def->name . ': ' . $def->type,
$this->wrap('= ', $def->defaultValue),
$this->join($def->directives, ' ')
], ' ');
},
Node::INTERFACE_TYPE_DEFINITION => function(InterfaceTypeDefinition $def) {
NodeType::INTERFACE_TYPE_DEFINITION => function(InterfaceTypeDefinition $def) {
return $this->join([
'interface',
$def->name,
@ -163,7 +164,7 @@ class Printer
$this->block($def->fields)
], ' ');
},
Node::UNION_TYPE_DEFINITION => function(UnionTypeDefinition $def) {
NodeType::UNION_TYPE_DEFINITION => function(UnionTypeDefinition $def) {
return $this->join([
'union',
$def->name,
@ -171,7 +172,7 @@ class Printer
'= ' . $this->join($def->types, ' | ')
], ' ');
},
Node::ENUM_TYPE_DEFINITION => function(EnumTypeDefinition $def) {
NodeType::ENUM_TYPE_DEFINITION => function(EnumTypeDefinition $def) {
return $this->join([
'enum',
$def->name,
@ -179,13 +180,13 @@ class Printer
$this->block($def->values)
], ' ');
},
Node::ENUM_VALUE_DEFINITION => function(EnumValueDefinition $def) {
NodeType::ENUM_VALUE_DEFINITION => function(EnumValueDefinition $def) {
return $this->join([
$def->name,
$this->join($def->directives, ' ')
], ' ');
},
Node::INPUT_OBJECT_TYPE_DEFINITION => function(InputObjectTypeDefinition $def) {
NodeType::INPUT_OBJECT_TYPE_DEFINITION => function(InputObjectTypeDefinition $def) {
return $this->join([
'input',
$def->name,
@ -193,10 +194,10 @@ class Printer
$this->block($def->fields)
], ' ');
},
Node::TYPE_EXTENSION_DEFINITION => function(TypeExtensionDefinition $def) {
NodeType::TYPE_EXTENSION_DEFINITION => function(TypeExtensionDefinition $def) {
return "extend {$def->definition}";
},
Node::DIRECTIVE_DEFINITION => function(DirectiveDefinition $def) {
NodeType::DIRECTIVE_DEFINITION => function(DirectiveDefinition $def) {
return 'directive @' . $def->name . $this->wrap('(', $this->join($def->arguments, ', '), ')')
. ' on ' . $this->join($def->locations, ' | ');
}

View File

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

View File

@ -2,13 +2,10 @@
namespace GraphQL\Tests\Language;
use GraphQL\Language\AST\Argument;
use GraphQL\Language\AST\Document;
use GraphQL\Language\AST\Field;
use GraphQL\Language\AST\IntValue;
use GraphQL\Language\AST\Location;
use GraphQL\Language\AST\Name;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\OperationDefinition;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\SelectionSet;
use GraphQL\Language\AST\StringValue;
use GraphQL\Language\Parser;
@ -270,39 +267,39 @@ fragment $fragmentName on Type {
};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'loc' => $loc(0, 41),
'definitions' => [
[
'kind' => Node::OPERATION_DEFINITION,
'kind' => NodeType::OPERATION_DEFINITION,
'loc' => $loc(0, 40),
'operation' => 'query',
'name' => null,
'variableDefinitions' => null,
'directives' => [],
'selectionSet' => [
'kind' => Node::SELECTION_SET,
'kind' => NodeType::SELECTION_SET,
'loc' => $loc(0, 40),
'selections' => [
[
'kind' => Node::FIELD,
'kind' => NodeType::FIELD,
'loc' => $loc(4, 38),
'alias' => null,
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => $loc(4, 8),
'value' => 'node'
],
'arguments' => [
[
'kind' => Node::ARGUMENT,
'kind' => NodeType::ARGUMENT,
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => $loc(9, 11),
'value' => 'id'
],
'value' => [
'kind' => Node::INT,
'kind' => NodeType::INT,
'loc' => $loc(13, 14),
'value' => '4'
],
@ -311,15 +308,15 @@ fragment $fragmentName on Type {
],
'directives' => [],
'selectionSet' => [
'kind' => Node::SELECTION_SET,
'kind' => NodeType::SELECTION_SET,
'loc' => $loc(16, 38),
'selections' => [
[
'kind' => Node::FIELD,
'kind' => NodeType::FIELD,
'loc' => $loc(22, 24),
'alias' => null,
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => $loc(22, 24),
'value' => 'id'
],
@ -328,11 +325,11 @@ fragment $fragmentName on Type {
'selectionSet' => null
],
[
'kind' => Node::FIELD,
'kind' => NodeType::FIELD,
'loc' => $loc(30, 34),
'alias' => null,
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => $loc(30, 34),
'value' => 'name'
],
@ -402,16 +399,16 @@ fragment $fragmentName on Type {
public function testParsesListValues()
{
$this->assertEquals([
'kind' => Node::LST,
'kind' => NodeType::LST,
'loc' => ['start' => 0, 'end' => 11],
'values' => [
[
'kind' => Node::INT,
'kind' => NodeType::INT,
'loc' => ['start' => 1, 'end' => 4],
'value' => '123'
],
[
'kind' => Node::STRING,
'kind' => NodeType::STRING,
'loc' => ['start' => 5, 'end' => 10],
'value' => 'abc'
]
@ -427,10 +424,10 @@ fragment $fragmentName on Type {
public function testParsesWellKnownTypes()
{
$this->assertEquals([
'kind' => Node::NAMED_TYPE,
'kind' => NodeType::NAMED_TYPE,
'loc' => ['start' => 0, 'end' => 6],
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => ['start' => 0, 'end' => 6],
'value' => 'String'
]
@ -443,10 +440,10 @@ fragment $fragmentName on Type {
public function testParsesCustomTypes()
{
$this->assertEquals([
'kind' => Node::NAMED_TYPE,
'kind' => NodeType::NAMED_TYPE,
'loc' => ['start' => 0, 'end' => 6],
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => ['start' => 0, 'end' => 6],
'value' => 'MyType'
]
@ -459,13 +456,13 @@ fragment $fragmentName on Type {
public function testParsesListTypes()
{
$this->assertEquals([
'kind' => Node::LIST_TYPE,
'kind' => NodeType::LIST_TYPE,
'loc' => ['start' => 0, 'end' => 8],
'type' => [
'kind' => Node::NAMED_TYPE,
'kind' => NodeType::NAMED_TYPE,
'loc' => ['start' => 1, 'end' => 7],
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => ['start' => 1, 'end' => 7],
'value' => 'MyType'
]
@ -479,13 +476,13 @@ fragment $fragmentName on Type {
public function testParsesNonNullTypes()
{
$this->assertEquals([
'kind' => Node::NON_NULL_TYPE,
'kind' => NodeType::NON_NULL_TYPE,
'loc' => ['start' => 0, 'end' => 7],
'type' => [
'kind' => Node::NAMED_TYPE,
'kind' => NodeType::NAMED_TYPE,
'loc' => ['start' => 0, 'end' => 6],
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => ['start' => 0, 'end' => 6],
'value' => 'MyType'
]
@ -499,16 +496,16 @@ fragment $fragmentName on Type {
public function testParsesNestedTypes()
{
$this->assertEquals([
'kind' => Node::LIST_TYPE,
'kind' => NodeType::LIST_TYPE,
'loc' => ['start' => 0, 'end' => 9],
'type' => [
'kind' => Node::NON_NULL_TYPE,
'kind' => NodeType::NON_NULL_TYPE,
'loc' => ['start' => 1, 'end' => 8],
'type' => [
'kind' => Node::NAMED_TYPE,
'kind' => NodeType::NAMED_TYPE,
'loc' => ['start' => 1, 'end' => 7],
'name' => [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'loc' => ['start' => 1, 'end' => 7],
'value' => 'MyType'
]

View File

@ -14,6 +14,7 @@ use GraphQL\Language\AST\Location;
use GraphQL\Language\AST\Name;
use GraphQL\Language\AST\NamedType;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NodeType;
use GraphQL\Language\AST\NonNullType;
use GraphQL\Language\AST\ObjectTypeDefinition;
use GraphQL\Language\AST\ScalarTypeDefinition;
@ -39,10 +40,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -76,12 +77,12 @@ extend type Hello {
return TestUtils::locArray($start, $end);
};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::TYPE_EXTENSION_DEFINITION,
'kind' => NodeType::TYPE_EXTENSION_DEFINITION,
'definition' => [
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(13, 18)),
'interfaces' => [],
'directives' => [],
@ -117,10 +118,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6,11)),
'interfaces' => [],
'directives' => [],
@ -128,7 +129,7 @@ type Hello {
$this->fieldNode(
$this->nameNode('world', $loc(16, 21)),
[
'kind' => Node::NON_NULL_TYPE,
'kind' => NodeType::NON_NULL_TYPE,
'type' => $this->typeNode('String', $loc(23, 29)),
'loc' => $loc(23, 30)
],
@ -154,10 +155,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'interfaces' => [
$this->typeNode('World', $loc(22, 27))
@ -183,10 +184,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'interfaces' => [
$this->typeNode('Wo', $loc(22,24)),
@ -213,10 +214,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::ENUM_TYPE_DEFINITION,
'kind' => NodeType::ENUM_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'directives' => [],
'values' => [$this->enumValueNode('WORLD', $loc(13, 18))],
@ -239,10 +240,10 @@ type Hello {
$doc = Parser::parse($body);
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::ENUM_TYPE_DEFINITION,
'kind' => NodeType::ENUM_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(5, 10)),
'directives' => [],
'values' => [
@ -271,10 +272,10 @@ interface Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::INTERFACE_TYPE_DEFINITION,
'kind' => NodeType::INTERFACE_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(11, 16)),
'directives' => [],
'fields' => [
@ -305,10 +306,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -349,10 +350,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -364,7 +365,7 @@ type Hello {
$this->inputValueNode(
$this->nameNode('flag', $loc(22, 26)),
$this->typeNode('Boolean', $loc(28, 35)),
['kind' => Node::BOOLEAN, 'value' => true, 'loc' => $loc(38, 42)],
['kind' => NodeType::BOOLEAN, 'value' => true, 'loc' => $loc(38, 42)],
$loc(22, 42)
)
],
@ -392,10 +393,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -406,7 +407,7 @@ type Hello {
[
$this->inputValueNode(
$this->nameNode('things', $loc(22,28)),
['kind' => Node::LIST_TYPE, 'type' => $this->typeNode('String', $loc(31, 37)), 'loc' => $loc(30, 38)],
['kind' => NodeType::LIST_TYPE, 'type' => $this->typeNode('String', $loc(31, 37)), 'loc' => $loc(30, 38)],
null,
$loc(22, 38)
)
@ -436,10 +437,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::OBJECT_TYPE_DEFINITION,
'kind' => NodeType::OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'interfaces' => [],
'directives' => [],
@ -482,10 +483,10 @@ type Hello {
$doc = Parser::parse($body);
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::UNION_TYPE_DEFINITION,
'kind' => NodeType::UNION_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'directives' => [],
'types' => [$this->typeNode('World', $loc(14, 19))],
@ -508,10 +509,10 @@ type Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::UNION_TYPE_DEFINITION,
'kind' => NodeType::UNION_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(6, 11)),
'directives' => [],
'types' => [
@ -535,10 +536,10 @@ type Hello {
$doc = Parser::parse($body);
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::SCALAR_TYPE_DEFINITION,
'kind' => NodeType::SCALAR_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(7, 12)),
'directives' => [],
'loc' => $loc(0, 12)
@ -562,10 +563,10 @@ input Hello {
$loc = function($start, $end) {return TestUtils::locArray($start, $end);};
$expected = [
'kind' => Node::DOCUMENT,
'kind' => NodeType::DOCUMENT,
'definitions' => [
[
'kind' => Node::INPUT_OBJECT_TYPE_DEFINITION,
'kind' => NodeType::INPUT_OBJECT_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(7, 12)),
'directives' => [],
'fields' => [
@ -600,8 +601,8 @@ input Hello {
private function typeNode($name, $loc)
{
return [
'kind' => Node::NAMED_TYPE,
'name' => ['kind' => Node::NAME, 'value' => $name, 'loc' => $loc],
'kind' => NodeType::NAMED_TYPE,
'name' => ['kind' => NodeType::NAME, 'value' => $name, 'loc' => $loc],
'loc' => $loc
];
}
@ -609,7 +610,7 @@ input Hello {
private function nameNode($name, $loc)
{
return [
'kind' => Node::NAME,
'kind' => NodeType::NAME,
'value' => $name,
'loc' => $loc
];
@ -623,7 +624,7 @@ input Hello {
private function fieldNodeWithArgs($name, $type, $args, $loc)
{
return [
'kind' => Node::FIELD_DEFINITION,
'kind' => NodeType::FIELD_DEFINITION,
'name' => $name,
'arguments' => $args,
'type' => $type,
@ -635,7 +636,7 @@ input Hello {
private function enumValueNode($name, $loc)
{
return [
'kind' => Node::ENUM_VALUE_DEFINITION,
'kind' => NodeType::ENUM_VALUE_DEFINITION,
'name' => $this->nameNode($name, $loc),
'directives' => [],
'loc' => $loc
@ -645,7 +646,7 @@ input Hello {
private function inputValueNode($name, $type, $defaultValue, $loc)
{
return [
'kind' => Node::INPUT_VALUE_DEFINITION,
'kind' => NodeType::INPUT_VALUE_DEFINITION,
'name' => $name,
'type' => $type,
'defaultValue' => $defaultValue,