thojanssens1
Absinthe Dataloader fetches assocs even if already preloaded
Say the Absinthe resolver returns a struct with an assoc that has already been loaded, e.g.
%Organization{
name: "Acme",
members: []
}
When using Dataloader with Absinthe to load the :members for the organization, dataloader will still execute a query to fetch the members while it was already loaded (set to []).
I found this old merge:
- Dataloader Ecto: Prevent reuse of a preloaded child · Issue #18 · absinthe-graphql/dataloader · GitHub
- Prevent Ecto Caching by benwilson512 · Pull Request #19 · absinthe-graphql/dataloader · GitHub
But the above GH comments don’t really state why we ignore already preloaded associations. It only mentions consistency but I do not see why we need to execute preload queries again if those had already been executed against the db, leading to double db requests.
Any idea as to why?
Most Liked
arcyfelix
An example how you can sort it out:
field :members, non_null(list_of(non_null(:member_type))) do
resolve(fn parent, args, context ->
case parent.members do
%Ecto.Association.NotLoaded{} ->
dataloader(:source, :members).(parent, args, context)
members->
{:ok, members}
end
end)
end
1
Popular in Questions
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’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 would like to know what is the best IDE for elixir development?
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
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
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Other popular topics
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
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New







