|
| 1 | +import asyncio |
1 | 2 | import copy |
2 | 3 | from collections.abc import MutableMapping |
3 | 4 | from functools import partial |
4 | 5 | from typing import List |
5 | 6 |
|
6 | 7 | from flask import Response, render_template_string, request |
7 | 8 | from flask.views import View |
8 | | -from graphql import specified_rules |
| 9 | +from graphql import pyutils, specified_rules |
9 | 10 | from graphql.error import GraphQLError |
10 | 11 | from graphql.type.schema import GraphQLSchema |
11 | 12 |
|
@@ -115,9 +116,23 @@ def dispatch_request(self): |
115 | 116 | middleware=self.get_middleware(), |
116 | 117 | validation_rules=self.get_validation_rules(), |
117 | 118 | execution_context_class=self.get_execution_context_class(), |
| 119 | + run_sync=False, |
118 | 120 | ) |
| 121 | + |
| 122 | + # This is (almost) copied from graphql_server.aiohttp.GraphQLView |
| 123 | + # It is a bit weird as it originally calls await in a loop which |
| 124 | + # a bit breaks the gains from doing operations asynchronously... |
| 125 | + # But maybe it is required for correctness to execute those |
| 126 | + # operations like that, so leaving it. |
| 127 | + exec_res = [ |
| 128 | + ex |
| 129 | + if ex is None or not pyutils.is_awaitable(ex) |
| 130 | + else asyncio.run(ex) |
| 131 | + for ex in execution_results |
| 132 | + ] |
| 133 | + |
119 | 134 | result, status_code = encode_execution_results( |
120 | | - execution_results, |
| 135 | + exec_res, |
121 | 136 | is_batch=isinstance(data, list), |
122 | 137 | format_error=self.format_error, |
123 | 138 | encode=partial(self.encode, pretty=pretty), # noqa |
|
0 commit comments