GreenFairy.Relay.Mutation (GreenFairy v0.3.0)
View SourceRelay-compliant mutation helpers with clientMutationId support.
This module provides macros for defining Relay-style mutations that
automatically handle the clientMutationId field.
Usage
Use relay_mutation instead of field for Relay-compliant mutations:
defmodule MyApp.GraphQL.Mutations.UserMutations do
use GreenFairy.Mutation
import GreenFairy.Relay.Mutation
mutations do
relay_mutation :create_user do
@desc "Creates a new user"
input do
field :email, non_null(:string)
field :name, :string
end
output do
field :user, :user
field :errors, list_of(:string)
end
resolve fn input, ctx ->
case MyApp.Accounts.create_user(input) do
{:ok, user} -> {:ok, %{user: user}}
{:error, changeset} -> {:ok, %{errors: format_errors(changeset)}}
end
end
end
end
endThis generates:
CreateUserInputinput type withclientMutationIdfieldCreateUserPayloadoutput type withclientMutationIdfield- Automatic passthrough of
clientMutationIdfrom input to output
Summary
Functions
Converts a mutation name to its input type name.
Converts a mutation name to its payload type name.
Defines a Relay-compliant mutation with automatic clientMutationId handling.
Functions
Converts a mutation name to its input type name.
Examples
iex> mutation_input_name(:create_user)
:create_user_input
Converts a mutation name to its payload type name.
Examples
iex> mutation_payload_name(:create_user)
:create_user_payload
Defines a Relay-compliant mutation with automatic clientMutationId handling.
Options
:input- Block defining input fields (clientMutationId is added automatically):output- Block defining output fields (clientMutationId is added automatically):resolve- Resolver function