Skip to content

Commit 156276e

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#221 from swalkinshaw/improve-argument-validation-error-messages
Include expected type in validation error message
2 parents fcd9ab2 + 35148b1 commit 156276e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/graphql/static_validation/rules/argument_literals_are_compatible.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def validate_node(parent, node, defn, context)
1010
if !valid
1111
kind_of_node = node_type(parent)
1212
error_arg_name = parent_name(parent, defn)
13-
context.errors << message("Argument '#{node.name}' on #{kind_of_node} '#{error_arg_name}' has an invalid value", parent, context: context)
13+
context.errors << message("Argument '#{node.name}' on #{kind_of_node} '#{error_arg_name}' has an invalid value. Expected type '#{arg_defn.type}'.", parent, context: context)
1414
end
1515
end
1616
end

spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,42 @@
2525
assert_equal(6, errors.length)
2626

2727
query_root_error = {
28-
"message"=>"Argument 'id' on Field 'cheese' has an invalid value",
28+
"message"=>"Argument 'id' on Field 'cheese' has an invalid value. Expected type 'Int!'.",
2929
"locations"=>[{"line"=>3, "column"=>7}],
3030
"path"=>["query getCheese", "cheese", "id"],
3131
}
3232
assert_includes(errors, query_root_error)
3333

3434
directive_error = {
35-
"message"=>"Argument 'if' on Directive 'skip' has an invalid value",
35+
"message"=>"Argument 'if' on Directive 'skip' has an invalid value. Expected type 'Boolean!'.",
3636
"locations"=>[{"line"=>4, "column"=>30}],
3737
"path"=>["query getCheese", "cheese", "source", "if"],
3838
}
3939
assert_includes(errors, directive_error)
4040

4141
input_object_error = {
42-
"message"=>"Argument 'product' on Field 'badSource' has an invalid value",
42+
"message"=>"Argument 'product' on Field 'badSource' has an invalid value. Expected type '[DairyProductInput]'.",
4343
"locations"=>[{"line"=>6, "column"=>7}],
4444
"path"=>["query getCheese", "badSource", "product"],
4545
}
4646
assert_includes(errors, input_object_error)
4747

4848
input_object_field_error = {
49-
"message"=>"Argument 'source' on InputObject 'DairyProductInput' has an invalid value",
49+
"message"=>"Argument 'source' on InputObject 'DairyProductInput' has an invalid value. Expected type 'DairyAnimal!'.",
5050
"locations"=>[{"line"=>6, "column"=>40}],
5151
"path"=>["query getCheese", "badSource", "product", "source"],
5252
}
5353
assert_includes(errors, input_object_field_error)
5454

5555
missing_required_field_error = {
56-
"message"=>"Argument 'product' on Field 'missingSource' has an invalid value",
56+
"message"=>"Argument 'product' on Field 'missingSource' has an invalid value. Expected type '[DairyProductInput]'.",
5757
"locations"=>[{"line"=>7, "column"=>7}],
5858
"path"=>["query getCheese", "missingSource", "product"],
5959
}
6060
assert_includes(errors, missing_required_field_error)
6161

6262
fragment_error = {
63-
"message"=>"Argument 'source' on Field 'similarCheese' has an invalid value",
63+
"message"=>"Argument 'source' on Field 'similarCheese' has an invalid value. Expected type '[DairyAnimal!]!'.",
6464
"locations"=>[{"line"=>13, "column"=>7}],
6565
"path"=>["fragment cheeseFields", "similarCheese", "source"],
6666
}

0 commit comments

Comments
 (0)