Dilute v0.1.1 Dilute View Source

Ecto.Schema are very similar to Absinthe.Type.Object definitions and are required to be kept in sync. Dilute is able to derive Absinthe.Type.Object on their relations based on Ecto.Schema definitions.

Types

Absinthe objects placed inside your Types module:

defmodule MyAppWeb.Schema.Types do
  use Absinthe.Schema.Notation
  require Dilute
  alias MyApp.Blog.{Post, Comment}

  Dilute.object(Post)
  Dilute.object(Comment)
end

Resolution

The resolver can be defined as:

defmodule MyAppWeb.Resolver do
  use Dilute.Resolver, types: MyAppWeb.Schema.Types, repo: MyApp.Repo
end

Queries can either be defined using the resolve/3 function or the query_fields/2 macro

defmodule MyAppWeb.Schema do
  use Absinthe.Schema
  import_types(MyAppWeb.Schema.Types)

  alias BlogWeb.Resolvers

  query do
    @desc "Get one Post"
    field :post, :post do
        resolve(&MyAppWeb.Resolver.resolve/3)
    end

    @desc "Get all Posts"
    field :posts, list_of(:post) do
      resolve(&MyAppWeb.Resolver.resolve/3)
    end

    query do
      MyWebApp.Schema.query_fields(:post, &Resolver.resolve/3)
    end
  end
end

Link to this section Summary

Functions

Defines an Absinthe object based on the ecto schema of the given module

Link to this section Functions

Link to this macro object(module) View Source (macro)

Defines an Absinthe object based on the ecto schema of the given module.

Fields can be excluded by including the respective field in the @exclude attribute:

@exclude [
  # ...
  {User, [:email, :forename]}
  # ...
]

Dilute.object(User)