Skip to content
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?
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