Dilute v0.3.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 objects and their relations based on Ecto.Schema definitions and offers the ability to translate query resolutions into efficient SQL statements.

Types

Absinthe objects placed inside your Types module:

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

  ecto_object(Post)

  ecto_object(Comment)
end

Resolution

The resolver can be defined with:

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 ...

defmodule MyAppWeb.Schema do
  use Absinthe.Schema
  alias MyAppWeb.{Resolver, Schema}
  import_types(Schema.Types)

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

... or the query_fields/2 macro.

defmodule MyAppWeb.Schema do
  use Absinthe.Schema
  alias MyAppWeb.{Resolver, Schema}
  import_types(Schema.Types)

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

Link to this section Summary

Link to this section Functions

Link to this macro

ecto_input_object(module)

View Source (macro)
Link to this macro

ecto_input_object(module, opts)

View Source (macro)
Link to this macro

ecto_input_object(module, opts, block)

View Source (macro)
Link to this macro

ecto_object(module)

View Source (macro)

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

Settings the :associations option to false will omit the associations in the definition. Fields can be excluded using the :exclude option.

ecto_object Post, exclude: :id do
end

Additionally the do block will override any field definitions.

ecto_object Post do
  field(:rating, :float)
end

Ecto allows for Custom Type definitions which have to be overwritten.

Link to this macro

ecto_object(module, opts)

View Source (macro)
Link to this macro

ecto_object(module, opts, block)

View Source (macro)