Closed djeusette closed 1 year ago
Right so this just means that the batches are accumulated in different passes on the document due to some prior async loading. In your specific case to simplify your query you have:
query Activity($id: UUID!, $after: String, $before: String, $first: Int, $last: Int) {
activity(id: $id) {
# This happens in pass 1
organizer {
id
}
# This happens in pass 1
attendances(after: $after, before: $before, first: $first, last: $last) {
edges {
node {
# This happens in pass 2
attendee {
Based on what I see in your logs it looks like both the organizer
field and the attendances
field use Dataloader. Absinthe runs through the document in its first pass and accumulates batches for those two things, and then it executes them. It can't possibly add attendee
to the first pass because attendances
hasn't resolved yet.
After that first pass Absinthe goes back through, fills in the loaded data, and can proceed to accumulate any new batches further down the tree.
Hi there,
First of all, thank you for your amazing work. Dataloader is definitely game changer!
For some GraphQL queries, the
Absinthe.Middleware.Dataloader
calls multiple timesDataloader.run
, via thebefore_resolution
function I guess, potentially triggering multiple identical Ecto queries.Here is a GraphQL query example:
In the above query, both
organizer
andattendee
resolve toColette.Accounts.User
structs. In both cases, I rely on Dataloader to fetch the data.I use the documented way to load batches, run the loader and get the results. Here is the piece of code:
Here are the interesting logs when resolving the aforementioned Graphql query:
1/ The loader with several batches before the first run. Please, note the batch to fetch users
{:queryable, #PID<0.2009.0>, Colette.Accounts.User, :one, :id, %{}}
2/ Right before the next run with new user batches
Multiple other runs happen right after.
All in all, this results in one Ecto query being called two times with different IDs:
Considering, the organizer is not needed to fetch the attendances and then the attendees, is there any way to prevent different runs on some batches?
Thanks!