Skip to content

Fix: RelationshipLoader should utilize DataLoader from the get_data_loader_impl() function, and not directly from aiodataloader library #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions graphene_sqlalchemy/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
from asyncio import get_event_loop
from typing import Any, Dict

import aiodataloader
import sqlalchemy
from sqlalchemy.orm import Session, strategies
from sqlalchemy.orm.query import QueryContext

from .utils import is_graphene_version_less_than, is_sqlalchemy_version_less_than


class RelationshipLoader(aiodataloader.DataLoader):
def get_data_loader_impl() -> Any: # pragma: no cover
"""Graphene >= 3.1.1 ships a copy of aiodataloader with minor fixes. To preserve backward-compatibility,
aiodataloader is used in conjunction with older versions of graphene"""
if is_graphene_version_less_than("3.1.1"):
from aiodataloader import DataLoader
else:
from graphene.utils.dataloader import DataLoader

return DataLoader


DataLoader = get_data_loader_impl()


class RelationshipLoader(DataLoader):
cache = False

def __init__(self, relationship_prop, selectin_loader):
Expand Down Expand Up @@ -92,20 +105,6 @@ async def batch_load_fn(self, parents):
] = {}


def get_data_loader_impl() -> Any: # pragma: no cover
"""Graphene >= 3.1.1 ships a copy of aiodataloader with minor fixes. To preserve backward-compatibility,
aiodataloader is used in conjunction with older versions of graphene"""
if is_graphene_version_less_than("3.1.1"):
from aiodataloader import DataLoader
else:
from graphene.utils.dataloader import DataLoader

return DataLoader


DataLoader = get_data_loader_impl()


def get_batch_resolver(relationship_prop):
"""Get the resolve function for the given relationship."""

Expand Down