Recreate loader if old loader is on different loop #395
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.
Fix for the problem encountered #35 (comment)
This change makes it so that the batched data loader is recreated at field resolution time if the current event loop is different than the event loop for the loader.
Previously, the loaders were only created at GraphQL
Schema
creation time. In many systems (including FastAPI and Starlette'sTestClient
), theSchema
object is required in order to initiate the mount of the GraphQL routes. Thereafter, a new event loop is created (owned by the request handler).This means that, almost by definition, in many frameworks the initial loaders will be created on one event loop and used on a different event loop in the future. To resolve this problem, this PR makes it so that we only use the memoized loader if it was created on the same event loop as where the resolution is happening.