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
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
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
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
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
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 t...
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
Other popular topics
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
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
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
I would like to know what is the best IDE for elixir development?
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








