Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Parse TypeExtensionDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Price committed Sep 14, 2015
1 parent fe341fa commit 8a20eaa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/graphql_lexer.xrl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ StringValue = "{StringCharacter}*"
BooleanValue = true|false
% Reserved words
ReservedWord = query|mutation|fragment|on|type|implements|interface|union|scalar|enum|input|null
ReservedWord = query|mutation|fragment|on|type|implements|interface|union|scalar|enum|input|extend|null
Rules.
Expand Down
7 changes: 5 additions & 2 deletions src/graphql_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Nonterminals
Terminals
'{' '}' '(' ')' '[' ']' '!' ':' '@' '$' '=' '|' '...'
'query' 'mutation' 'fragment' 'on'
'type' 'implements' 'interface' 'union' 'scalar' 'enum' 'input'
'type' 'implements' 'interface' 'union' 'scalar' 'enum' 'input' 'extend'
name int_value float_value string_value boolean_value.

Rootsymbol Document.
Expand Down Expand Up @@ -134,7 +134,7 @@ TypeDefinition -> UnionTypeDefinition : '$1'.
TypeDefinition -> ScalarTypeDefinition : '$1'.
TypeDefinition -> EnumTypeDefinition : '$1'.
TypeDefinition -> InputObjectTypeDefinition : '$1'.
% TypeDefinition -> TypeExtensionDefinition : '$1'.
TypeDefinition -> TypeExtensionDefinition : '$1'.

ObjectTypeDefinition -> 'type' Name '{' FieldDefinitionList '}' :
build_ast_node('ObjectTypeDefinition', [{'name', '$2'}, {'fields', '$4'}]).
Expand Down Expand Up @@ -181,6 +181,9 @@ EnumValueDefinition -> EnumValue : '$1'.
InputObjectTypeDefinition -> 'input' Name '{' InputValueDefinitionList '}' :
build_ast_node('InputObjectTypeDefinition', [{'name', '$2'}, {'fields', '$4'}]).

TypeExtensionDefinition -> 'extend' ObjectTypeDefinition :
build_ast_node('TypeExtensionDefinition', [{'definition', '$2'}]).

Erlang code.

extract_atom({Value, _Line}) -> Value.
Expand Down
13 changes: 13 additions & 0 deletions test/graphql_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,17 @@ defmodule GraphqlParserTest do
[kind: :InputValueDefinition, loc: [start: 0], name: 'y',
type: [kind: :NamedType, loc: [start: 0], name: 'Float']]]]]]
end

test "TypeExtensionDefinition" do
assert_parse 'extend type Story { isHiddenLocally: Boolean }',
[kind: :Document, loc: [start: 0],
definitions: [
[kind: :TypeExtensionDefinition, loc: [start: 0],
definition: [kind: :ObjectTypeDefinition, loc: [start: 0],
name: 'Story',
fields: [
[kind: :FieldDefinition, loc: [start: 0],
name: 'isHiddenLocally',
type: [kind: :NamedType, loc: [start: 0], name: 'Boolean']]]]]]]
end
end

0 comments on commit 8a20eaa

Please sign in to comment.