Dilute v2.0.0-rc.5 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}
dilute_object(Post)
dilute_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
Functions
Defines an Absinthe object based on the ecto schema of the given module.
Link to this section Functions
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.
dilute_object Post, exclude: :id do
end
Additionally the do block will override any field definitions.
dilute_object Post do
field(:rating, :float)
end
Ecto allows for Custom Type definitions which have to be overwritten.