diff --git a/src/Language/AST/DefinitionNode.php b/src/Language/AST/DefinitionNode.php index f5a6c28..4c099cc 100644 --- a/src/Language/AST/DefinitionNode.php +++ b/src/Language/AST/DefinitionNode.php @@ -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. */ } diff --git a/src/Language/AST/ExecutableDefinitionNode.php b/src/Language/AST/ExecutableDefinitionNode.php new file mode 100644 index 0000000..6b3b572 --- /dev/null +++ b/src/Language/AST/ExecutableDefinitionNode.php @@ -0,0 +1,11 @@ +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();