Skip to content

Commit 027ea0e

Browse files
committed
Merge branch 'master' into enable-sorting-for-batching
2 parents d6746e3 + bb7af4b commit 027ea0e

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

graphene_sqlalchemy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .types import SQLAlchemyObjectType
33
from .utils import get_query, get_session
44

5-
__version__ = "3.0.0b2"
5+
__version__ = "3.0.0b3"
66

77
__all__ = [
88
"__version__",

graphene_sqlalchemy/batching.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""The dataloader uses "select in loading" strategy to load related entities."""
22
from asyncio import get_event_loop
3-
from typing import Dict
3+
from typing import Any, Dict
44

55
import aiodataloader
66
import sqlalchemy
77
from sqlalchemy.orm import Session, strategies
88
from sqlalchemy.orm.query import QueryContext
99

10-
from .utils import is_sqlalchemy_version_less_than
10+
from .utils import (is_graphene_version_less_than,
11+
is_sqlalchemy_version_less_than)
1112

1213

1314
class RelationshipLoader(aiodataloader.DataLoader):
@@ -94,6 +95,20 @@ async def batch_load_fn(self, parents):
9495
] = {}
9596

9697

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

graphene_sqlalchemy/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,16 @@ def sort_argument_for_model(cls, has_default=True):
151151
return Argument(List(enum), default_value=enum.default)
152152

153153

154-
def is_sqlalchemy_version_less_than(version_string):
154+
def is_sqlalchemy_version_less_than(version_string): # pragma: no cover
155155
"""Check the installed SQLAlchemy version"""
156156
return pkg_resources.get_distribution('SQLAlchemy').parsed_version < pkg_resources.parse_version(version_string)
157157

158158

159+
def is_graphene_version_less_than(version_string): # pragma: no cover
160+
"""Check the installed graphene version"""
161+
return pkg_resources.get_distribution('graphene').parsed_version < pkg_resources.parse_version(version_string)
162+
163+
159164
class singledispatchbymatchfunction:
160165
"""
161166
Inspired by @singledispatch, this is a variant that works using a matcher function
@@ -197,6 +202,7 @@ def safe_isinstance_checker(arg):
197202
return isinstance(arg, cls)
198203
except TypeError:
199204
pass
205+
200206
return safe_isinstance_checker
201207

202208

@@ -210,5 +216,6 @@ def registry_sqlalchemy_model_from_str(model_name: str) -> Optional[Any]:
210216

211217
class DummyImport:
212218
"""The dummy module returns 'object' for a query for any member"""
219+
213220
def __getattr__(self, name):
214221
return object

0 commit comments

Comments
 (0)