File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 26
26
GraphiQLOptions ,
27
27
render_graphiql_sync ,
28
28
)
29
+ from graphql_server .utils import ensure_async
29
30
30
31
31
32
class GraphQLView (View ):
@@ -121,7 +122,7 @@ async def get_async_execution_results():
121
122
* (
122
123
ex
123
124
if ex is not None and is_awaitable (ex )
124
- else asyncio . coroutine (lambda : ex )()
125
+ else ensure_async (lambda : ex )()
125
126
for ex in execution_results
126
127
)
127
128
)
Original file line number Diff line number Diff line change
1
+ import sys
2
+ from typing import Awaitable , Callable , TypeVar
3
+
4
+ if sys .version_info >= (3 , 10 ):
5
+ from typing import ParamSpec
6
+ else :
7
+ from typing_extensions import ParamSpec
8
+
9
+
10
+ __all__ = ["ensure_async" ]
11
+
12
+ P = ParamSpec ("P" )
13
+ R = TypeVar ("R" )
14
+
15
+
16
+ def ensure_async (f : Callable [P , R ]) -> Callable [P , Awaitable [R ]]:
17
+ """Convert a sync callable (normal def or lambda) to a coroutine (async def).
18
+
19
+ This is similar to asyncio.coroutine which was deprecated in Python 3.8.
20
+ """
21
+
22
+ async def f_async (* args : P .args , ** kwargs : P .kwargs ) -> R :
23
+ return f (* args , ** kwargs )
24
+
25
+ return f_async
You can’t perform that action at this time.
0 commit comments