fix plugin and middleware callback order for EntitiesField #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Absinthe.Middleware.Batchis 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
Batchworks is by setting up a data structure inbefore_resolution, accumulating the ids and setting the resolution state tosuspendedincall, and then calling the user's batch function inafter_resolution. Finally,pipelinedetects that the resolution is not complete, so it adds theResolutionphase back into the blueprint pipeline to be run again. When we go through the callbacks a second time,callhits a different pattern match because the state is nowsuspended, and it calls the user's post-batching function.Right now
EntitiesFieldis calling the middleware callback a second time before callingafter_resolution, which is causingBatchto try to call the post-batching function before it has fired the actual batching function.DataloaderandAsyncare unaffected by this because they don't useafter_resolutionin the first place.This PR shifts the callback order around to more closely match how absinthe resolves normal fields.