Dataloader compilation error

Hi, I am trying to use dataloader in Absinthe, but am getting this error message on compile:

== Compilation error in file lib/book_list_web/schema.ex ==
** (CompileError) lib/book_list_web/schema.ex:8: cannot import Absinthe.Resolution.Helpers.dataloader/1 because it is undefined or private

Here is where the error occurs:

defmodule BookListWeb.Schema do

  use Absinthe.Schema
  use Absinthe.Ecto, repo: BookList.Repo

  alias BookList.BookSpace.Book

  import Absinthe.Resolution.Helpers, only: [dataloader: 1] . ### ERROR HERE
  import_types Absinthe.Type.Custom

Here are the related lines in mix.exs:

      {:plug_cowboy, "~> 1.0"},
      {:absinthe_ecto, "~> 0.1.0"},
      {:absinthe_plug, "~> 1.3.0"},
      {:dataloader, "~> 1.0.0"},

Absinthe needs to be recompiled now that Dataloader is around.


mix deps.compile absinthe

Hi, just tried that, but the error persists when I do iex -S mix phx.server

It seems you might still be on Absinthe 1.3


Yes, that was indeed it (version). Thanks so much!

You’re welcome!

I jumped the gun and thought you have the same problem I previously had.

For anyone having a similar problem, Absinthe only defines the Dataloader-related functions if Dataloader is around. If you add Dataloader as a new dependency after Absinthe has already been compiled, these functions wouldn’t be available. Recompiling Absinthe fixes this.


I’m having this same issue, even recompiling absinthe doesn’t fix it.

      {:phoenix, "~> 1.4.15"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_ecto, "~> 4.0"},
      {:gettext, "~> 0.11"},
      {:nuki, in_umbrella: true},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:dataloader, "~> 1.0"},
      {:absinthe_plug, "~> 1.4"},
      {:absinthe, "~> 1.4"},
      {:absinthe_ecto, "~> 0.1.3"}

I’m in an umbrella application, added absinthe and dataloader to the phoenix app within the umbrella.

Tried deleting _build and deps but the same result.

defmodule NukiWeb.Schema.ContentTypes do
  import Absinthe.Resolution.Helpers, only: [dataloader: 1]
  use Absinthe.Schema.Notation

# ====

$ iex -S mix phx.server
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

==> nuki_web
Compiling 12 files (.ex)

== Compilation error in file lib/nuki_web/schema/content_types.ex ==
** (CompileError) lib/nuki_web/schema/content_types.ex:12: undefined function dataloader/1
    (elixir 1.10.2) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib 3.6) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir 1.10.2) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

Appreciate any help

Hi Sergio! Are you still running into your issue? If you have a minimal example repo that I can clone, I can take a look.

Hey @aptinio appreciate your help! My project is barebones, just trying to get dataloader to connect two database tables. I can add you to my repo, what’s your github username?

It’s aptinio

Would be search users, after I explained the issue and invited Aptinio I figured out the issue through sheer luck.

In the file where you define your content types, makes sure you’re importing in the right order!

defmodule NukiWeb.Schema.ContentTypes do
  import Absinthe.Resolution.Helpers, only: [dataloader: 1]
  use Absinthe.Schema.Notation

defmodule NukiWeb.Schema.ContentTypes do
  use Absinthe.Schema.Notation
  import Absinthe.Resolution.Helpers, only: [dataloader: 1]

@benwilson512 would love your insight if you have any on this issue - why does the Helpers module need to be imported AFTER the Notation module?

Ah, this is because use Absinthe.Schema.Notation does an import of the Helpers module which ends up overriding any imports done before.


Thanks Ben - that makes sense.