https://github.com/absinthe-graphql/absinthe_ecto
DEPRECATED: Use dataloader
https://github.com/absinthe-graphql/absinthe_ecto
Last synced: about 2 months ago
JSON representation
DEPRECATED: Use dataloader
- Host: GitHub
- URL: https://github.com/absinthe-graphql/absinthe_ecto
- Owner: absinthe-graphql
- License: mit
- Created: 2016-11-17T17:10:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-24T17:51:03.000Z (about 6 years ago)
- Last Synced: 2024-11-06T22:48:31.407Z (8 months ago)
- Language: Elixir
- Homepage:
- Size: 29.3 KB
- Stars: 130
- Watchers: 15
- Forks: 36
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Absinthe.Ecto
**DEPRECATED**: Please use [Dataloader.Ecto](https://hexdocs.pm/dataloader/Dataloader.Ecto.html) from the [dataloader](https://github.com/absinthe-graphql/dataloader) package instead.
[](https://hex.pm/packages/absinthe_ecto)[](https://opensource.org/licenses/MIT)
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:```elixir
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.Schemaschema "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:
```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](./LICENSE.md).