Move queries and mutations to submodules
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
21
lib/mobilizon_web/schema/utils.ex
Normal file
21
lib/mobilizon_web/schema/utils.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
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: context]
|
||||
end)
|
||||
|
||||
{:error, errors}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user