Skip to content

Commit 8036719

Browse files
committed
Use Executor for getting responses
Use an Executor of the same type as configured to get backend responses.This leverages the batching functionality, allowing batched requests to be processed concurrently.
1 parent 5c7a300 commit 8036719

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

graphql_server/__init__.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from graphql import get_default_backend
66
from graphql.error import format_error as default_format_error
77
from graphql.execution import ExecutionResult
8+
from graphql.execution.executors.sync import SyncExecutor
9+
from promise import Promise, is_thenable
810

911
from .error import HttpQueryError
1012

@@ -67,11 +69,25 @@ def run_http_query(
6769

6870
all_params = [get_graphql_params(entry, extra_data) for entry in data]
6971

70-
responses = [
71-
get_response(schema, params, catch_exc, allow_only_query, **execute_options)
72+
executor = execute_options.get('executor')
73+
if executor is None:
74+
response_executor = SyncExecutor()
75+
else:
76+
response_executor = executor.__class__()
77+
78+
response_promises = [
79+
response_executor.execute(
80+
get_response, schema, params, catch_exc, allow_only_query, **execute_options)
7281
for params in all_params
7382
]
7483

84+
response_executor.wait_until_finished()
85+
86+
responses = map(
87+
lambda result: result.get() if is_thenable(result) else result,
88+
response_promises
89+
)
90+
7591
return responses, all_params
7692

7793

0 commit comments

Comments
 (0)