Skip to content

Commit 0a765a1

Browse files
authored
Made Relationshiploader utilize the new and improved DataLoader implementation housed inside graphene, if possible (graphene >=3.1.1) (#362)
1 parent b3657b0 commit 0a765a1

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

Diff for: graphene_sqlalchemy/batching.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22
from asyncio import get_event_loop
33
from typing import Any, Dict
44

5-
import aiodataloader
65
import sqlalchemy
76
from sqlalchemy.orm import Session, strategies
87
from sqlalchemy.orm.query import QueryContext
98

109
from .utils import is_graphene_version_less_than, is_sqlalchemy_version_less_than
1110

1211

13-
class RelationshipLoader(aiodataloader.DataLoader):
12+
def get_data_loader_impl() -> Any: # pragma: no cover
13+
"""Graphene >= 3.1.1 ships a copy of aiodataloader with minor fixes. To preserve backward-compatibility,
14+
aiodataloader is used in conjunction with older versions of graphene"""
15+
if is_graphene_version_less_than("3.1.1"):
16+
from aiodataloader import DataLoader
17+
else:
18+
from graphene.utils.dataloader import DataLoader
19+
20+
return DataLoader
21+
22+
23+
DataLoader = get_data_loader_impl()
24+
25+
26+
class RelationshipLoader(DataLoader):
1427
cache = False
1528

1629
def __init__(self, relationship_prop, selectin_loader):
@@ -92,20 +105,6 @@ async def batch_load_fn(self, parents):
92105
] = {}
93106

94107

95-
def get_data_loader_impl() -> Any: # pragma: no cover
96-
"""Graphene >= 3.1.1 ships a copy of aiodataloader with minor fixes. To preserve backward-compatibility,
97-
aiodataloader is used in conjunction with older versions of graphene"""
98-
if is_graphene_version_less_than("3.1.1"):
99-
from aiodataloader import DataLoader
100-
else:
101-
from graphene.utils.dataloader import DataLoader
102-
103-
return DataLoader
104-
105-
106-
DataLoader = get_data_loader_impl()
107-
108-
109108
def get_batch_resolver(relationship_prop):
110109
"""Get the resolve function for the given relationship."""
111110

0 commit comments

Comments
 (0)