pierreabreup
Reuse object fields as input_object fields in Absinthe
I have a absinthe object type like that:
defmodule ContentProxyGraphql.Schema.ObjectTypes.Content do
use Absinthe.Schema.Notation
use Absinthe.Relay.Schema, :modern
import_types Absinthe.Type.Custom
object :content do
field :type_of, non_null(:string)
field :name, non_null(:string)
field :date_created, non_null(:datetime)
field :date_modified, non_null(:datetime)
field :identifier, non_null(:identifier)
field :publisher, :publisher
end
object :identifier do
field :type_of, non_null(:string)
field :property_id, non_null(:string)
field :value, non_null(:string)
end
object :publisher do
field :type_of, non_null(:string)
field :name, non_null(:string)
end
end
In my schema.ex, I have the query
query do
field :contents, list_of(:content) do
resolve &Resolvers.Resources.Content.list/3
end
end
Now I’m creating the mutation
mutation do
field :create_content, type: :content do
arg :typeOf, non_null(:string)
arg :name, non_null(:string)
arg :dateCreated, non_null(:datetime)
arg :dateModified, non_null(:datetime)
resolve &Resolvers.Resources.Content.create/3
end
end
In my mutation I intend to add arg :identifier and arg :publisher. According to absinthe documentation (Complex Arguments — absinthe v1.11.0) I have to create a input_object :indentifier and a input_object :publisher with their fields, which are the same of respective object :identifier and object :publisher.
Is there a way to reuse object fields inside input_object? I’m trying it to avoid code duplication, in other words, I would like to avoid
input_object :identifier do
field :type_of, non_null(:string)
field :property_id, non_null(:string)
field :value, non_null(:string)
end
@benwilson512 FYI
First Post!
dylan-chong
there is a import_fields function now so you can do inheritance on types. not a perfect solution but way better than not having it at all
0
Last Post!
alexandru-calinoiu
Popular in Questions
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
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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 server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Other popular topics
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
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
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
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
- #api
- #forms
- #metaprogramming
- #security
- #hex









