Sample for using partitions (types, queries, mutations) in absinthe. It's very useful for big app or umbrella app.
# Types
defmodule Auth.GraphQL.Schema.Account do
use Absinthe.Schema.Notation
object :account do
field :id, :string
field :email, :string
field :password, :string
field :insert_at, :string
field :updated_at, :string
end
end
# Queries
defmodule Auth.GraphQL.Queries.Account do
use Absinthe.Schema.Notation
alias Auth.GraphQL.Resolvers.Account
object :account_queries do
field :accounts, list_of(:account) do
resolve &Account.accounts/2
end
end
end
# Mutations
defmodule Auth.GraphQL.Mutations.Account do
use Absinthe.Schema.Notation
alias Auth.GraphQL.Resolvers.Account
object :account_mutations do
field :register, type: :account do
resolve &Account.register/2
end
end
end
# GraphQL Schema
defmodule ApiWeb.GraphQL.Schema do
use Absinthe.Schema
alias Auth.GraphQL.Resolvers.Account
import_types Auth.GraphQL.Schema.Account
import_types Auth.GraphQL.Queries.Account
import_types Auth.GraphQL.Mutations.Account
query do
import_fields :account_queries
end
mutation do
import_fields :account_mutations
end
end