dataloader icon indicating copy to clipboard operation
dataloader copied to clipboard

limits or something else?

Open MeterSoft opened this issue 3 years ago • 1 comments

i use v 1.0.7 All association use custom batch. Also i have a big struct like

posts(first: 10) {
  user {
    id
  }
  comments(first: 10) {
    user {
      id
    }
    replies {
      user {
        id
      }
      uploads: {
        user {
          id
        }
      }
    }
  }
}

But looks like when i try load many dataloader batches i got error "Unable to find item [\"a83e3944-1b45-4f70-b400-0f119d989fb0\"] in batch when i remove 1 field with dataloader from query all is ok but after back it query again failed. Any things?

one example

def dataloader_one(source, queryable, type, map_fn \\ & &1) do
   fn parent, _args, %{context: %{loader: loader}} = _resolution ->
     parent_id = Map.get(parent, :id) || Map.get(parent, :__parent_id)

     loader
     |> Dataloader.load(source, {:one, queryable}, [{type, parent_id}])
     |> on_load(fn loader ->
       loader
       |> Dataloader.get(source, {:one, queryable}, [{type, parent_id}])
       |> map_fn.()
       |> wrap_with_ok
     end)
   end
 end
def run_batch(_, query, :quests_count, user_ids, repo_opts, %{current_user: current_user} = params) do
       User.quests_count(current_user.id, user_ids, true)
       |> run_batch_wrapper(params[:repo], user_ids, repo_opts, 0)
     end
def run_batch_wrapper(query, repo, entities_ids, repo_opts, default_value \\ nil, map_fn \\ &(&1)) do
   repo = repo || Repo
   results =
     query
     |> repo.all(repo_opts)
     |> Map.new

   for id <- entities_ids, do: map_fn.(Map.get(results, id, default_value))
 end

MeterSoft avatar Mar 02 '21 12:03 MeterSoft

I have exactly the same problem, but not directly the same. I have this helper:

    dataloader(
      loader, 
      fn object, _args, %{context: %{current_user: user}} ->
        {key, %{user: user, parent: object}}
      end,
      opts
    )

and in some queries it will fail with the same error as you, but when I remove parent: object from the args everything works fine. I spent around 3 days debugging the problem and still could not understand how all this dataloading works from start to end.

Paryz avatar Jul 26 '21 15:07 Paryz

Closing as a lot has changed, please reopen with a test case if this is still an issue.

benwilson512 avatar Oct 31 '22 04:10 benwilson512