Skip to content
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: 6 additions & 1 deletion lib/graphql/language/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ def definition
parse_operation_type
end

op_name = at?(:IDENTIFIER) ? parse_name : nil
op_name = case token_name
when :LPAREN, :LCURLY, :DIR_SIGN
nil
else
parse_name
end

variable_definitions = if at?(:LPAREN)
expect_token(:LPAREN)
Expand Down
6 changes: 5 additions & 1 deletion spec/graphql/language/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@
it "allows fields, arguments, and enum values named type" do
doc = GraphQL.parse("{ type(type: type) }")
assert_instance_of GraphQL::Language::Nodes::Enum, doc.definitions.first.selections.first.arguments.first.value
end

it "allows operation names to match operation types" do
doc = GraphQL.parse("query subscription { foo }")
assert_equal "subscription", doc.definitions.first.name
end

it "raises an error when unicode is used as names" do
Expand All @@ -117,7 +121,7 @@
expected_msg = if USING_C_PARSER
"syntax error, unexpected invalid token (\"\\xF0\"), expecting LCURLY at [1, 7]"
else
"Expected LCURLY, actual: UNKNOWN_CHAR (\"\\xF0\") at [1, 7]"
"Expected NAME, actual: UNKNOWN_CHAR (\"\\xF0\") at [1, 7]"
end

assert_equal expected_msg, err.message
Expand Down