DEPRECATED: Use dataloader
Provides some helper functions for easy batching of Ecto assocations
These functions all make use of the batch plugin found in Absinthe, they're merely just some helpful ways to use this plugin in the context of simple ecto associations.
First specify the repo you're going to use:
use Absinthe.Ecto, repo: MyApp.Repo
Then, supposing you have some ecto associations as in this example schema: ```elixir defmodule MyApp.Post do use Ecto.Schema
schema "posts" do belongsto :author, MyApp.User hasmany :comments, MyApp.Comment field :name, :string field :body, :string end end ```
Your graphql post object might look like:
elixir object :post do field :author, :user, resolve: assoc(:author) field :comments, list_of(:comment), resolve: assoc(:comments) field :name, :string field :body, :string end
Now, queries which get the author or comments of many posts will result in just 1 call to the database for each!
assocmacro just builds a resolution function which calls
ecto_batch/4function for how to do this from within a regular resolution function.