itopiz
How to extend the payload output macro in absinthe_relay 1.5?
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?
First Post!
itopiz
@benwilson512: any idea?
Popular in Questions
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
In AR this is so simple
@articles = current_user.articles
How to do in Ecto?
def index(conn, _params) do
current_user = conn.assig...
New
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217
Let’s say I have a map with required and optional k...
New
Other popular topics
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New







