Skip to content

Address recent SDL spec changes #1139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/language/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,13 @@ export type DocumentNode = {
};

export type DefinitionNode =
| OperationDefinitionNode
| FragmentDefinitionNode
| ExecutableDefinitionNode
| TypeSystemDefinitionNode; // experimental non-spec addition.

export type ExecutableDefinitionNode =
| OperationDefinitionNode
| FragmentDefinitionNode;

export type OperationDefinitionNode = {
+kind: 'OperationDefinition',
+loc?: Location,
Expand Down
77 changes: 55 additions & 22 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
VariableNode,
DocumentNode,
DefinitionNode,
ExecutableDefinitionNode,
OperationDefinitionNode,
OperationTypeNode,
VariableDefinitionNode,
Expand Down Expand Up @@ -213,26 +214,17 @@ function parseDocument(lexer: Lexer<*>): DocumentNode {

/**
* Definition :
* - OperationDefinition
* - FragmentDefinition
* - ExecutableDefinition
* - TypeSystemDefinition
*/
function parseDefinition(lexer: Lexer<*>): DefinitionNode {
if (peek(lexer, TokenKind.BRACE_L)) {
return parseOperationDefinition(lexer);
}

if (peek(lexer, TokenKind.NAME)) {
switch (lexer.token.value) {
case 'query':
case 'mutation':
case 'subscription':
return parseOperationDefinition(lexer);

case 'fragment':
return parseFragmentDefinition(lexer);

// Note: The schema definition language is an experimental addition.
return parseExecutableDefinition(lexer);
case 'schema':
case 'scalar':
case 'type':
Expand All @@ -242,13 +234,37 @@ function parseDefinition(lexer: Lexer<*>): DefinitionNode {
case 'input':
case 'extend':
case 'directive':
// Note: The schema definition language is an experimental addition.
return parseTypeSystemDefinition(lexer);
}
} else if (peek(lexer, TokenKind.BRACE_L)) {
return parseExecutableDefinition(lexer);
} else if (peekDescription(lexer)) {
// Note: The schema definition language is an experimental addition.
return parseTypeSystemDefinition(lexer);
}

// Note: The schema definition language is an experimental addition.
if (peekDescription(lexer)) {
return parseTypeSystemDefinition(lexer);
throw unexpected(lexer);
}

/**
* ExecutableDefinition :
* - OperationDefinition
* - FragmentDefinition
*/
function parseExecutableDefinition(lexer: Lexer<*>): ExecutableDefinitionNode {
if (peek(lexer, TokenKind.NAME)) {
switch (lexer.token.value) {
case 'query':
case 'mutation':
case 'subscription':
return parseOperationDefinition(lexer);

case 'fragment':
return parseFragmentDefinition(lexer);
}
} else if (peek(lexer, TokenKind.BRACE_L)) {
return parseOperationDefinition(lexer);
}

throw unexpected(lexer);
Expand Down Expand Up @@ -1321,14 +1337,31 @@ function parseDirectiveLocations(lexer: Lexer<*>): Array<NameNode> {
}

/*
* DirectiveLocation: one of
* `QUERY` `SCHEMA` `ENUM`
* `MUTATION` `SCALAR` `ENUM_VALUE`
* `SUBSCRIPTION` `OBJECT` `INPUT_OBJECT`
* `FIELD` `FIELD_DEFINITION` `INPUT_FIELD_DEFINITION`
* `FRAGMENT_DEFINITION` `ARGUMENT_DEFINITION`
* `FRAGMENT_SPREAD` `INTERFACE`
* `INLINE_FRAGMENT` `UNION`
* DirectiveLocation :
* - ExecutableDirectiveLocation
* - TypeSystemDirectiveLocation
*
* ExecutableDirectiveLocation : one of
* `QUERY`
* `MUTATION`
* `SUBSCRIPTION`
* `FIELD`
* `FRAGMENT_DEFINITION`
* `FRAGMENT_SPREAD`
* `INLINE_FRAGMENT`
*
* TypeSystemDirectiveLocation : one of
* `SCHEMA`
* `SCALAR`
* `OBJECT`
* `FIELD_DEFINITION`
* `ARGUMENT_DEFINITION`
* `INTERFACE`
* `UNION`
* `ENUM`
* `ENUM_VALUE`
* `INPUT_OBJECT`
* `INPUT_FIELD_DEFINITION`
*/
function parseDirectiveLocation(lexer: Lexer<*>): NameNode {
const start = lexer.token;
Expand Down