Skip to content
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

Return a parse error when a variable type is missing #5225

Merged
merged 1 commit into from
Feb 6, 2025
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
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
Loading