title: How do I use Absinthe Dataloader for many to many relationships
body: <p>In my phoenix application, I have a many to many relationship between an Artist and a Cause schema implemented using a join table <code>artists_causes</code>. In my Artist schema, I have <code>many_to_many :causes, Cause, join_through: "artists_causes"</code> and in the Cause schema I have <code>many_to_many :artists, Artist, join_through: "artists_causes"</code>
  I am using absinthe for graphql and in my <code>CauseTypes</code> module, I have implemented a the <code>cause</code> object as below</p>
  
  <pre><code>defmodule MyAppWeb.Schema.CauseTypes do
    @moduledoc """
    All types for causes
    """
    use Absinthe.Schema.Notation
    import Absinthe.Resolution.Helpers, only: [dataloader: 1, dataloader: 3]
  
    object :cause do
      field :id, :id
      field :artists, list_of(:artist), resolve: dataloader(Artists)
    end
  
    def dataloader do
      alias MyApp.{Artists, Causes}
      loader = Dataloader.new
      |&gt; Dataloader.add_source(Causes, Causes.datasource())
      |&gt; Dataloader.add_source(Artists, Artists.datasource())
    end
  
    def context(ctx) do
      Map.put(ctx, :loader, dataloader())
    end
  
    def plugins do
      [Absinthe.Middleware.Dataloader] ++ Absinthe.Plugin.defaults()
    end
  end
  </code></pre>
  
  <p>From my understanding, with Absinthe Dataloader, the dataloader/1 is what I need to have the list of Artists loaded. However, I am not able to query for the artists from within a cause getting the error <code>artists: #Ecto.Association.NotLoaded&lt;association :artists is not loaded&gt;</code> when I run the query below in graphiql</p>
  
  <pre><code>query{
   causes{
    id
    artists {
              id
     }
   }
  }
  </code></pre>
  
  <p>Is there any little piece that I am missing on working with many to many relationships?</p>
  
  <p>==========</p>
  
  <h1>Update</h1>
  
  <p>I updated my list_causes function as below</p>
  
  <pre><code>def list_causes do    
     Repo.all(MyApp.Causes.Cause) 
  end
  </code></pre>
  
  <p>to</p>
  
  <pre><code>def list_causes do
      Repo.all(from c in Cause,
      left_join: ac in "artists_causes", on: c.id == ac.cause_id,
      left_join: a in Artist, on: a.id == ac.artist_id,
      preload: [:artists]
      )
    end
  </code></pre>
  
  <p>and , I am now getting the error <code>FunctionClauseError at POST /graphiql\n\nException:\n\n    ** (FunctionClauseError) no function clause matching in anonymous fn/3 in Absinthe.Resolution.Helpers.dataloader/1</code> which maybe pointing towards with the <code>Absinthe.Resolution.Helpers.dataloader/1</code> method. I have the helpers imported Is there something else I could be missing?</p>