Since I migrated from absinthe_relay
version 1.4
to 1.5
, my code does not compile anymore.
Indeed, I was using a custom macro to extend the payload output/1
macro:
defmodule MyApp.Schema.Notation do
@moduledoc false
defmacro mutation({:output, _, _}, do: block) do
do_output(__CALLER__, block)
end
defmacro mutation({:output, _, _}) do
do_output(__CALLER__, nil)
end
defp do_output(_env, block) do
record_output(block)
end
defp record_output(block) do
body = mutation_output_body()
quote do
output do
unquote(body)
unquote(block)
end
end
end
# success and error fields are automatically added
defp mutation_output_body do
quote do
@desc "Indicates if the command succeeded."
field(:success, non_null(:boolean))
@desc "Error details."
field(:error, :error)
end
end
end
The custom macro was used this way to add the 2 fields :success
and :error
on my mutations outputs:
payload field(:register_user) do
input do
field(:username, non_null(:string))
field(:display_name, non_null(:string))
field(:password, non_null(:string))
field(:role, non_null(:user_role))
field(:blocked, non_null(:boolean))
end
mutation output do
field(:user, :user)
end
resolve(&Accounts.RegisterUser.resolve/3)
end
payload field(:change_user_username) do
input do
field(:user_id, non_null(:id))
field(:username, non_null(:string))
end
mutation(output)
middleware(Absinthe.Relay.Node.ParseIDs, user_id: :user)
resolve(&Accounts.ChangeUserUsername.resolve/3)
end
Since absinthe_relay 1.5
, output/1
was replaced by output/2
and my code does not compile anymore:
$ mix compile
Compiling 6 files (.ex)
== Compilation error in file lib/myapp_web/schema/accounts.ex ==
** (CompileError) lib/myapp_web/schema/accounts.ex:28: undefined function output/1
expanding macro: MyAppWeb.Schema.Notation.mutation/2
lib/myapp_web/schema/accounts.ex:28: MyAppWeb.Schema.Accounts (module)
expanding macro: Absinthe.Schema.Notation.field/3
lib/myapp_web/schema/accounts.ex:12: MyAppWeb.Schema.Accounts (module)
expanding macro: Absinthe.Relay.Mutation.Notation.Modern.payload/2
lib/myapp_web/schema/accounts.ex:12: MyAppWeb.Schema.Accounts (module)
expanding macro: Absinthe.Schema.Notation.object/2
lib/myapp_web/schema/accounts.ex:10: MyAppWeb.Schema.Accounts (module)
(elixir 1.10.4) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
I understand the compilation error: my custom macro is expanded after the new Absinthe.Relay.Mutation.Notation.Modern.payload/2
which rewrites the input and output blocks to add an identifier.
Is there a way to customize/extend the payload output macro to add generic fields with absinthe_relay 1.5
?