Skip to content

Commit ea72c6f

Browse files
committed
check that default value isn't an execution error
1 parent 71669ac commit ea72c6f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/graphql/query/literal_input.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def self.from_arguments(ast_arguments, argument_defns, variables)
7777
# `context` isn't present when pre-calculating defaults
7878
if context
7979
value = arg_defn.prepare(value, context)
80+
if value.is_a?(GraphQL::ExecutionError)
81+
value.ast_node = ast_arg
82+
raise value
83+
end
8084
end
8185
values_hash[arg_name] = value
8286
end

spec/graphql/query/literal_input_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@
2020
end
2121
resolve ->(t, a, c) { a[:value] }
2222
end
23+
24+
field :fieldWithArgumentThatIsBadByDefault do
25+
type types.Int
26+
argument :value do
27+
type types.Int
28+
default_value 7
29+
prepare ->(arg, ctx) do
30+
GraphQL::ExecutionError.new("Always bad")
31+
end
32+
end
33+
34+
resolve ->(*args) { 42 }
35+
end
2336
end
2437

2538
GraphQL::Schema.define(query: query)
@@ -35,6 +48,11 @@
3548
assert_equal(7, result["data"]["addToArgumentValue"])
3649
end
3750

51+
it "raises an execution error if the default value is bad" do
52+
result = schema.execute("{ fieldWithArgumentThatIsBadByDefault }", context: { })
53+
assert_equal(result["errors"], [{"message" => "Always bad"}])
54+
end
55+
3856
it "prepares values from variables" do
3957
result = schema.execute("query ($value: Int!) { addToArgumentValue(value: $value) }", variables: { "value" => 1}, context: { val: 2 } )
4058
assert_equal(result["data"]["addToArgumentValue"], 3)

0 commit comments

Comments
 (0)