Skip to content

Apply default values that are 'false' #658

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

Merged
merged 3 commits into from
Apr 6, 2017
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
8 changes: 3 additions & 5 deletions lib/graphql/input_object_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ def coerce_non_null_input(value)

if value.key?(input_key)
coerced_value = input_field_defn.type.coerce_input(field_value)
else
coerced_value = input_field_defn.default_value
end

if coerced_value || value.key?(input_key)
input_values[input_key] = coerced_value
elsif input_field_defn.default_value?
default_value = input_field_defn.default_value
input_values[input_key] = default_value
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/graphql/input_object_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
a: String
b: Int!
c: String = "Default"
d: Boolean = false
}
|) }
let(:input_type) { schema.types['ExampleInputObject'] }
Expand Down Expand Up @@ -274,6 +275,13 @@
assert_equal 1, result['b']
assert_equal 'Test', result['c']
end

it "false default values are returned" do
input = MinimumInputObject.new({"b" => 1})
result = input_type.coerce_input(input)

assert_equal false, result['d']
end
end

describe "when sent into a query" do
Expand Down