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
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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 I...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Other popular topics
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









