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 bug in DataLoader::Source#load_all when sending only falsy values #5167

Merged
merged 1 commit into from
Nov 21, 2024
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/dataloader/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def load_all(values)
end
}

if pending_keys.any?
if pending_keys.size.positive?
rmosolgo marked this conversation as resolved.
Show resolved Hide resolved
sync(pending_keys)
end

Expand Down
40 changes: 40 additions & 0 deletions spec/graphql/dataloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ def recipe(recipe:)
recipe
end

field :recipe_by_id_using_load, Recipe do
argument :id, ID, required: false
end

def recipe_by_id_using_load(id:)
dataloader.with(DataObject).load(id)
end

field :recipes_by_id_using_load_all, [Recipe] do
argument :ids, [ID, null: true]
end

def recipes_by_id_using_load_all(ids:)
dataloader.with(DataObject).load_all(ids)
end

field :recipes_by_id, [Recipe] do
argument :ids, [ID], loads: Recipe, as: :recipes
end
Expand Down Expand Up @@ -901,6 +917,30 @@ def self.included(child_class)
assert_equal 1, context[:batched_calls_counter].count
end

it "works when passing nil into source" do
query_str = <<-GRAPHQL
query($id: ID) {
recipe: recipeByIdUsingLoad(id: $id) {
name
}
}
GRAPHQL
res = schema.execute(query_str, variables: { id: nil })
expected_data = { "recipe" => nil }
assert_equal expected_data, res["data"]

query_str = <<-GRAPHQL
query($ids: [ID]!) {
recipes: recipesByIdUsingLoadAll(ids: $ids) {
name
}
}
GRAPHQL
res = schema.execute(query_str, variables: { ids: [nil] })
expected_data = { "recipes" => nil }
assert_equal expected_data, res["data"]
end

it "Works with input objects using variables, load and request" do
query_str = <<-GRAPHQL
query($input: CommonIngredientsInput!) {
Expand Down
Loading