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

fix: Apply default values to variables in Request.prepare only if they are nil #92

Merged
merged 2 commits into from
Nov 19, 2023
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/stitching/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def fragment_definitions

def prepare!
operation.variables.each do |v|
@variables[v.name] ||= v.default_value
@variables[v.name] = v.default_value if @variables[v.name].nil?
end

if @may_contain_runtime_directives
Expand Down
15 changes: 15 additions & 0 deletions test/graphql/stitching/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ def test_prepare_variables_collects_variable_defaults
assert_equal expected, request.variables
end

def test_prepare_variables_preserves_boolean_values
query = <<~GRAPHQL
query($a: Boolean, $b: Boolean, $c: Boolean = true) {
base(a: $a, b: $b, c: $c) { id }
}
GRAPHQL

variables = { "a" => true, "b" => false, "c" => false }
request = GraphQL::Stitching::Request.new(GraphQL.parse(query), variables: variables)
request.prepare!

expected = { "a" => true, "b" => false, "c" => false }
assert_equal expected, request.variables
end

def test_applies_skip_and_include_directives_via_boolean_literals
query = <<~GRAPHQL
query {
Expand Down
Loading