debianize-mobilizon/lib/mobilizon_web/schema/utils.ex
Thomas Citharel 681653e035
Introduce registerPerson mutation
To register a profile from an unactivated user

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

👤 Fix Person interface use

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Change host function for data property

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2019-01-30 15:59:27 +01:00

22 lines
548 B
Elixir

defmodule MobilizonWeb.Schema.Utils do
def handle_errors(fun) do
fn source, args, info ->
case Absinthe.Resolution.call(fun, source, args, info) do
{:error, %Ecto.Changeset{} = changeset} -> format_changeset(changeset)
val -> val
end
end
end
def format_changeset(changeset) do
# {:error, [email: {"has already been taken", []}]}
errors =
changeset.errors
|> Enum.map(fn {key, {value, _context}} ->
[message: "#{value}", details: key]
end)
{:error, errors}
end
end