Address recent SDL spec changes

This should be the last set of spec changes for a standardized SDL

ref: graphql/graphql-js#1139
This commit is contained in:
Daniel Tschinder 2018-02-13 18:18:50 +01:00
parent 50cbfb4a44
commit 6d08c342c9
5 changed files with 46 additions and 16 deletions

View File

@ -4,8 +4,8 @@ namespace GraphQL\Language\AST;
interface DefinitionNode
{
/**
* export type DefinitionNode = OperationDefinitionNode
* | FragmentDefinitionNode
* | TypeSystemDefinitionNode // experimental non-spec addition.
* export type DefinitionNode =
* | ExecutableDefinitionNode
* | TypeSystemDefinitionNode; // experimental non-spec addition.
*/
}

View File

@ -0,0 +1,11 @@
<?php
namespace GraphQL\Language\AST;
interface ExecutableDefinitionNode extends DefinitionNode
{
/**
* export type ExecutableDefinitionNode =
* | OperationDefinitionNode
* | FragmentDefinitionNode;
*/
}

View File

@ -1,7 +1,7 @@
<?php
namespace GraphQL\Language\AST;
class FragmentDefinitionNode extends Node implements DefinitionNode, HasSelectionSet
class FragmentDefinitionNode extends Node implements ExecutableDefinitionNode, HasSelectionSet
{
public $kind = NodeKind::FRAGMENT_DEFINITION;

View File

@ -1,7 +1,7 @@
<?php
namespace GraphQL\Language\AST;
class OperationDefinitionNode extends Node implements DefinitionNode, HasSelectionSet
class OperationDefinitionNode extends Node implements ExecutableDefinitionNode, HasSelectionSet
{
/**
* @var string

View File

@ -6,6 +6,7 @@ use GraphQL\Language\AST\DirectiveDefinitionNode;
use GraphQL\Language\AST\EnumTypeDefinitionNode;
use GraphQL\Language\AST\EnumTypeExtensionNode;
use GraphQL\Language\AST\EnumValueDefinitionNode;
use GraphQL\Language\AST\ExecutableDefinitionNode;
use GraphQL\Language\AST\FieldDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeExtensionNode;
@ -328,24 +329,18 @@ class Parser
}
/**
* @return OperationDefinitionNode|FragmentDefinitionNode|TypeSystemDefinitionNode
* @return ExecutableDefinitionNode|TypeSystemDefinitionNode
* @throws SyntaxError
*/
function parseDefinition()
{
if ($this->peek(Token::BRACE_L)) {
return $this->parseOperationDefinition();
}
if ($this->peek(Token::NAME)) {
switch ($this->lexer->token->value) {
case 'query':
case 'mutation':
case 'subscription':
return $this->parseOperationDefinition();
case 'fragment':
return $this->parseFragmentDefinition();
return $this->parseExecutableDefinition();
// Note: The schema definition language is an experimental addition.
case 'schema':
@ -357,13 +352,37 @@ class Parser
case 'input':
case 'extend':
case 'directive':
// Note: The schema definition language is an experimental addition.
return $this->parseTypeSystemDefinition();
}
} else if ($this->peek(Token::BRACE_L)) {
return $this->parseExecutableDefinition();
} else if ($this->peekDescription()) {
// Note: The schema definition language is an experimental addition.
return $this->parseTypeSystemDefinition();
}
// Note: The schema definition language is an experimental addition.
if ($this->peekDescription()) {
return $this->parseTypeSystemDefinition();
throw $this->unexpected();
}
/**
* @return ExecutableDefinitionNode
* @throws SyntaxError
*/
function parseExecutableDefinition()
{
if ($this->peek(Token::NAME)) {
switch ($this->lexer->token->value) {
case 'query':
case 'mutation':
case 'subscription':
return $this->parseOperationDefinition();
case 'fragment':
return $this->parseFragmentDefinition();
}
} else if ($this->peek(Token::BRACE_L)) {
return $this->parseOperationDefinition();
}
throw $this->unexpected();