absinthe_ecto

DEPRECATED: Use dataloader

Latest version: 0.1.3 registry icon
Maintenance score
0
Safety score
0
Popularity score
73
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High
0.1.3 0 0 0 0
0.1.2 0 0 0 0
0.1.1 0 0 0 0
0.1.0 0 0 0 0

Stability
Latest release:

0.1.3 - this version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



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:

defmodule MyApp.Post do
  use Ecto.Schema

  schema "posts" do
    belongs_to :author, MyApp.User
    has_many :comments, MyApp.Comment
    field :name, :string
    field :body, :string
  end
end

Your graphql post object might look like:

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.