Skip to content

Commit

Permalink
Merge pull request #5225 from rmosolgo/var-type-parse-fix
Browse files Browse the repository at this point in the history
Return a parse error when a variable type is missing
  • Loading branch information
rmosolgo authored Feb 6, 2025
2 parents 0b1bce6 + ac9a030 commit e2d076c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/graphql/language/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def definition
expect_token(:VAR_SIGN)
var_name = parse_name
expect_token(:COLON)
var_type = self.type
var_type = self.type || raise_parse_error("Missing type definition for variable: $#{var_name}")
default_value = if at?(:EQUALS)
advance_token
value
Expand Down
13 changes: 13 additions & 0 deletions spec/graphql/language/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@
assert_equal "subscription", doc.definitions.first.name
end

it "raises an error for bad variables definition" do
err = assert_raises(GraphQL::ParseError) do
GraphQL.parse("query someQuery($someVariable: ,) { account { id } }")
end
expected_msg = if USING_C_PARSER
"syntax error, unexpected RPAREN (\")\") at [1, 33]"
else
"Missing type definition for variable: $someVariable at [1, 33]"
end

assert_equal expected_msg, err.message
end

it "raises an error when unicode is used as names" do
err = assert_raises(GraphQL::ParseError) {
GraphQL.parse('query 😘 { a b }')
Expand Down

0 comments on commit e2d076c

Please sign in to comment.