Skip to content

Conversation

@adaugherty42
Copy link
Contributor

Absinthe.Middleware.Batch is both a plugin and a middleware. When used to resolve a non-federated field, absinthe calls its callbacks in the following order:

before_resolution (Plugin callback)
call (Middleware callback)
after_resolution (Plugin callback)
pipeline (Plugin callback)

The way Batch works is by setting up a data structure in before_resolution, accumulating the ids and setting the resolution state to suspended in call, and then calling the user's batch function in after_resolution. Finally, pipeline detects that the resolution is not complete, so it adds the Resolution phase back into the blueprint pipeline to be run again. When we go through the callbacks a second time, call hits a different pattern match because the state is now suspended, and it calls the user's post-batching function.

Right now EntitiesField is calling the middleware callback a second time before calling after_resolution, which is causing Batch to try to call the post-batching function before it has fired the actual batching function. Dataloader and Async are unaffected by this because they don't use after_resolution in the first place.

This PR shifts the callback order around to more closely match how absinthe resolves normal fields.

Copy link
Collaborator

@kzlsakal kzlsakal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great contribution, thank you @adaugherty42!

@kzlsakal kzlsakal merged commit b442bad into DivvyPayHQ:main Jun 6, 2025
9 checks passed
@kzlsakal kzlsakal added the bug Something isn't working label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants