ns.bruno
How to create function to return all common fields in absinthe
I’m trying to minimize repetitions in field definitions in a Type, input and query.
With this I don’t know how to do it, so I ask for help from the community.
Below is the code I’m trying to do, but without success.
defmodule MyApp.UserType do
use Absinthe.Schema.Notation
import Absinthe.Schema.Notation
@descricao_type "User registration that can access the system."
@desc @descricao_type
object :user_types do
MyApp.UserType.comuns_fields()
field :password_hash,
non_null(:string),
description: "User-defined and already encrypted password."
end
# São todos os fields/campos que devem estar presentes no momento da inserção/atualização
@desc @descricao_type
input_object :user_input do
MyApp.UserType.comuns_fields()
field :password, non_null(:string),
description: "Password entered by the user to be registered."
end
defmacro comuns_fields() do
quote do
field :email,
non_null(:string),
description: "Email address that will be used to log into the system."
field :enable,
:boolean,
description: "Mark if user is active or not. By default it is active."
end
end
end
I’m getting the following error message:
== Compilation error in file lib/on_sistemas/schema/types/administracao/sistema/usuario_types.ex ==
** (CompileError) lib/my_app/types/user_types.ex:16: undefined function comuns_fields/0 (there is no such import)
(absinthe 1.7.0) expanding macro: Absinthe.Schema.Notation.input_object/2
lib/my_app/types/user_types.ex:16: OnSistemas.Graphql.Schema.Types.Administracao.Sistema.UsuarioType (module)
Marked As Solved
maartenvanvliet
Absinthe has a built-in method to reuse fields.
object :user_fields do
field :email,
non_null(:string),
description: "Email address that will be used to log into the system."
field :enable,
:boolean,
description: "Mark if user is active or not. By default it is active."
end
input_object :user_input do
field :password, non_null(:string),
description: "Password entered by the user to be registered."
import_fields :user_fields
end
2
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir?
...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
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 am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









