Skip to content

Commit

Permalink
Fixes issue absinthe-graphql#74
Browse files Browse the repository at this point in the history
Handle case where Dataloader.KV has some results and is asked
to load an id that is neither present in 'results' or 'batches'.

In this case Map.get/2 would return `nil`, which was falling
through and being treated as if the id was found in the results.

This replaces Map.get/2 with Map.get/3 so that we can provide
an explicit value to pattern-match on (:error).
  • Loading branch information
alex-knowles committed Apr 15, 2019
1 parent ef5c978 commit 786abd0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dataloader/kv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ defmodule Dataloader.KV do

def fetch(source, batch_key, id) do
with {:ok, batch} <- Map.fetch(source.results, batch_key) do
case Map.get(batch, id) do
case Map.get(batch, id, :error) do
{:error, reason} -> {:error, reason}
:error -> {:error, "Unable to find id #{inspect(id)}"}
item -> {:ok, item}
end
else
Expand Down

0 comments on commit 786abd0

Please sign in to comment.