Absinthe dataloader issue. "** (BadMapError) expected a map, got: {:ok, [model]}" from resolve

I’m trying to link dataloader up.

object :user do
  field(:posts, list_of(:post)) do
    resolve: &MyOwnResolver.function/3
  end
end

This works. And my resolver returns something like {:ok, [post, post, post]}

object :user do
  field(:posts, list_of(:post)) do
    resolve: dataloader(Blog)
  end
end

This fails with the following error:

** (BadMapError) expected a map, got: {:ok, [%Blog.Post{...}]}
Here’s the full trace

(absinthe) lib/absinthe/middleware/map_get.ex:9: Absinthe.Middleware.MapGet.call/2
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:209: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:168: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/4
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:153: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:72: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:257: Absinthe.Phase.Document.Execution.Resolution.build_result/4
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:98: Absinthe.Phase.Document.Execution.Resolution.walk_results/6
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:77: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:98: Absinthe.Phase.Document.Execution.Resolution.walk_results/6
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:77: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:53: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
       (absinthe) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
       (absinthe) lib/absinthe/pipeline.ex:274: Absinthe.Pipeline.run_phase/3
       (absinthe_plug) lib/absinthe/plug.ex:421: Absinthe.Plug.run_query/4
       (absinthe_plug) lib/absinthe/plug.ex:247: Absinthe.Plug.call/2
       (api) lib/api/plugs/admin_graphql.ex:1: API.AdminGraphQL.plug_builder_call/2
       (phoenix) lib/phoenix/router/route.ex:39: Phoenix.Router.Route.call/2
       (phoenix) lib/phoenix/router.ex:275: Phoenix.Router.__call__/1
       (api) lib/plug/error_handler.ex:64: API.Router.call/2

Hi @pejrich neither should work as written since you need to do resolve &MyOwnResolver.function/3 or resolve dataloader(Blog) not resolve: dataloader(Blog).

Correct. That was just a syntax error in my post, my code is resolve dataloader(Blog), not resolve: dataloader(Blog). But there error still exists. I’m not sure why an :ok tuple is cauing an error in this case, since it doesn’t cause an error why I use my own resolver, only when I use dataloader.

Can you show your exact code copied and pasted? What is happening somewhere is that a resolver is returning {:ok, {:ok, list_of_posts}}.

What versions of Absinthe / Dataloader are you on? Do mix deps|grep absinthe and mix deps|grep dataloader

1 Like