View Source CoseDellaVitaEx.ErrorMapper behaviour (CoseDellaVitaEx v0.2.0)

Functions to map Ecto Changeset errors to GraphQL error types.

Link to this section Summary

Callbacks

Maps a custom Ecto Changeset error to a GraphQL error type.

Functions

Maps a built-in Ecto Changeset error to a GraphQL error type.

Link to this section Callbacks

@callback map(map(), String.t()) :: struct()

Maps a custom Ecto Changeset error to a GraphQL error type.

To handle built-in Ecto Changeset errors, call map_default/2 as a fallback.

examples-doctests

Examples / doctests

defmodule MyApp.ErrorMapper do
  @behaviour CoseDellaVitaEx.ErrorMapper

  def map(%{custom_validation: :something}, message), do: %SomeError{message: message}
  def map(opts, message), do: CoseDellaVitaEx.ErrorMapper.map_default(opts, message)
end

Link to this section Functions

Link to this function

map_default(opts, message)

View Source
@spec map_default(map(), String.t()) :: struct()

Maps a built-in Ecto Changeset error to a GraphQL error type.

examples-doctests

Examples / doctests

See CosaDellaVitaEx.Helpers.add_changeset_errors/5.