Need help with absinthe_ecto?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

absinthe-graphql
127 Stars 32 Forks MIT License 44 Commits 7 Opened issues

Description

DEPRECATED: Use dataloader

Services available

!
?

Need anything else?

Contributors list

Absinthe.Ecto

DEPRECATED: Please use Dataloader.Ecto from the dataloader package instead.

Hex pmLicense

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.

Basic Usage

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!

The

assoc
macro just builds a resolution function which calls
ecto_batch/4
.

See the

ecto_batch/4
function for how to do this from within a regular resolution function.

License

See LICENSE.md.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.