StrawHat.GraphQL v0.2.2 StrawHat.GraphQL.MutationResponse View Source

Absinthe Mutation Response utilities. Normally will be use in Absinthe resolvers.

Usage

On the resolver.

Examples

defmodule App.AccountResolver do

  alias StrawHat.GraphQL.MutationResponse

  def create_account(params, _) do
    case App.Account.create_account(params) do
      {:ok, account} -> MutationResponse.succeeded(account)
      {:error, reason} -> MutationResponse.failed(reason)
    end
  end
end

Link to this section Summary

Types

  • successful: When the mutation succeeded or not.
  • payload: Data of the mutation payload.
  • errors: List of StrawHat.Error.t/0.

Functions

Returns a failed mutation response map.

Returns a succeeded mutation response map.

Link to this section Types

Link to this type

mutation_response()

View Source
mutation_response() :: %{
  successful: boolean(),
  payload: any(),
  errors: [StrawHat.Error.t()]
}
  • successful: When the mutation succeeded or not.
  • payload: Data of the mutation payload.
  • errors: List of StrawHat.Error.t/0.

Link to this section Functions

Link to this function

failed(changeset)

View Source
failed(Ecto.Changeset.t()) :: {:ok, mutation_response()}
failed(StrawHat.Error.t()) :: {:ok, mutation_response()}
failed(StrawHat.Error.ErrorList.t()) :: {:ok, mutation_response()}
failed(any()) :: no_return()

Returns a failed mutation response map.

Link to this function

response_with(arg1)

View Source
response_with({:ok, any()} | {:error, any()} | any()) ::
  {:ok, mutation_response()} | no_return()
Link to this function

succeeded(payload)

View Source
succeeded(any()) :: {:ok, mutation_response()}

Returns a succeeded mutation response map.