Skip to content

Instantly share code, notes, and snippets.

@phuochau
Last active October 19, 2017 22:47
Show Gist options
  • Save phuochau/aca2704ff585e6c7e56568dfbe8fc0ca to your computer and use it in GitHub Desktop.
Save phuochau/aca2704ff585e6c7e56568dfbe8fc0ca to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment