File tree 3 files changed +26
-4
lines changed
3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 2
2
from .types import SQLAlchemyObjectType
3
3
from .utils import get_query , get_session
4
4
5
- __version__ = "3.0.0b2 "
5
+ __version__ = "3.0.0b3 "
6
6
7
7
__all__ = [
8
8
"__version__" ,
Original file line number Diff line number Diff line change 1
1
"""The dataloader uses "select in loading" strategy to load related entities."""
2
2
from asyncio import get_event_loop
3
- from typing import Dict
3
+ from typing import Any , Dict
4
4
5
5
import aiodataloader
6
6
import sqlalchemy
7
7
from sqlalchemy .orm import Session , strategies
8
8
from sqlalchemy .orm .query import QueryContext
9
9
10
- from .utils import is_sqlalchemy_version_less_than
10
+ from .utils import (is_graphene_version_less_than ,
11
+ is_sqlalchemy_version_less_than )
11
12
12
13
13
14
class RelationshipLoader (aiodataloader .DataLoader ):
@@ -94,6 +95,20 @@ async def batch_load_fn(self, parents):
94
95
] = {}
95
96
96
97
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
+
97
112
def get_batch_resolver (relationship_prop ):
98
113
"""Get the resolve function for the given relationship."""
99
114
Original file line number Diff line number Diff line change @@ -151,11 +151,16 @@ def sort_argument_for_model(cls, has_default=True):
151
151
return Argument (List (enum ), default_value = enum .default )
152
152
153
153
154
- def is_sqlalchemy_version_less_than (version_string ):
154
+ def is_sqlalchemy_version_less_than (version_string ): # pragma: no cover
155
155
"""Check the installed SQLAlchemy version"""
156
156
return pkg_resources .get_distribution ('SQLAlchemy' ).parsed_version < pkg_resources .parse_version (version_string )
157
157
158
158
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
+
159
164
class singledispatchbymatchfunction :
160
165
"""
161
166
Inspired by @singledispatch, this is a variant that works using a matcher function
@@ -197,6 +202,7 @@ def safe_isinstance_checker(arg):
197
202
return isinstance (arg , cls )
198
203
except TypeError :
199
204
pass
205
+
200
206
return safe_isinstance_checker
201
207
202
208
@@ -210,5 +216,6 @@ def registry_sqlalchemy_model_from_str(model_name: str) -> Optional[Any]:
210
216
211
217
class DummyImport :
212
218
"""The dummy module returns 'object' for a query for any member"""
219
+
213
220
def __getattr__ (self , name ):
214
221
return object
You can’t perform that action at this time.
0 commit comments