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 interface DefinitionNode
{ {
/** /**
* export type DefinitionNode = OperationDefinitionNode * export type DefinitionNode =
* | FragmentDefinitionNode * | ExecutableDefinitionNode
* | TypeSystemDefinitionNode // experimental non-spec addition. * | 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 <?php
namespace GraphQL\Language\AST; namespace GraphQL\Language\AST;
class FragmentDefinitionNode extends Node implements DefinitionNode, HasSelectionSet class FragmentDefinitionNode extends Node implements ExecutableDefinitionNode, HasSelectionSet
{ {
public $kind = NodeKind::FRAGMENT_DEFINITION; public $kind = NodeKind::FRAGMENT_DEFINITION;

View File

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

View File

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