tansan
How can I setup the schema for self-referencing association?
I have a self-referencing model, and I was able to get it to work with the following. However, this leads to 2 different cached objects in Apollo. Ex, ChildCategory:[id] and Category:[Id]. I would like to have a single source of truth so it makes optimistic updates more manageable.
object :child_category do
field :id, :id
field :name, :string
field :category_id, :id
end
object :category do
field :id, :id
field :name, :string
field :categories, list_of(:child_category), resolve: dataloader(DataloaderQueries, :categories)
end
I tried this, but it leads to an error saying it can’t query the categoryId on category. I also don’t want there to be infinite recursion. I want the second level of categories to exclude the key categories.
object :category do
field :id, :id
field :name, :string
field :categories, list_of(:category), resolve: dataloader(DataloaderQueries, :categories)
end
Marked As Solved
tansan
I figured it out. I needed to add category_id here:
object :category do
field :id, :id
field :name, :string
field :category_id, :id
field :categories, list_of(:category), resolve: dataloader(DataloaderQueries, :categories)
end
Also Liked
benwilson512
Author of Craft GraphQL APIs in Elixir with Absinthe
Yeah, Absinthe doesn’t implicitly add id fields like ecto does, because they don’t always. make sense to add.
1
tansan
Thanks for taking the time to reply and help! It’s a big reason why I love Absinthe.
1
Popular in Questions
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
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 t...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
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 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
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Other popular topics
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
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
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
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
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
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
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
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New







