Skip to content

Commit 3e9d42d

Browse files
committed
Don't use executor in run_http_query when return_promise=True
1 parent a61486e commit 3e9d42d

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

graphql_server/__init__.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,26 @@ def run_http_query(
122122

123123
all_params = [get_graphql_params(entry, extra_data) for entry in data]
124124

125-
executor = execute_options.get("executor")
126-
response_executor = executor if executor else SyncExecutor()
125+
if execute_options.get('return_promise'):
126+
results = [
127+
get_response(schema, params, catch_exc, allow_only_query, **execute_options)
128+
for params in all_params
129+
]
130+
else:
131+
executor = execute_options.get("executor")
132+
response_executor = executor if executor else SyncExecutor()
127133

128-
response_promises = [
129-
response_executor.execute(
130-
get_response, schema, params, catch_exc, allow_only_query, **execute_options
131-
)
132-
for params in all_params
133-
]
134-
response_executor.wait_until_finished()
134+
response_promises = [
135+
response_executor.execute(
136+
get_response, schema, params, catch_exc, allow_only_query, **execute_options
137+
)
138+
for params in all_params
139+
]
140+
response_executor.wait_until_finished()
135141

136-
results = [
137-
result.get() if is_thenable(result) else result for result in response_promises
138-
]
142+
results = [
143+
result.get() if is_thenable(result) else result for result in response_promises
144+
]
139145

140146
return ServerResults(results, all_params)
141147

tests/test_query.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from graphql.error import GraphQLError
4+
from promise import Promise
45

56
from graphql_server import (
67
HttpQueryError,
@@ -551,11 +552,45 @@ def execute(self, fn, *args, **kwargs):
551552
{},
552553
dict(query=query),
553554
executor=TestExecutor(),
554-
return_promise=True,
555555
)
556556

557557
assert as_dicts(results) == [{"data": {"test": "Hello World"}}]
558558
assert params == [RequestParams(query=query, variables=None, operation_name=None)]
559559
assert TestExecutor.called
560560
assert TestExecutor.waited
561+
assert not TestExecutor.cleaned
562+
563+
564+
def test_get_reponses_using_executor_return_promise():
565+
class TestExecutor(object):
566+
called = False
567+
waited = False
568+
cleaned = False
569+
570+
def wait_until_finished(self):
571+
TestExecutor.waited = True
572+
573+
def clean(self):
574+
TestExecutor.cleaned = True
575+
576+
def execute(self, fn, *args, **kwargs):
577+
TestExecutor.called = True
578+
return fn(*args, **kwargs)
579+
580+
query = "{test}"
581+
result_promises, params = run_http_query(
582+
schema,
583+
"get",
584+
{},
585+
dict(query=query),
586+
executor=TestExecutor(),
587+
return_promise=True,
588+
)
589+
590+
results = Promise.all(result_promises).get()
591+
592+
assert as_dicts(results) == [{"data": {"test": "Hello World"}}]
593+
assert params == [RequestParams(query=query, variables=None, operation_name=None)]
594+
assert TestExecutor.called
595+
assert not TestExecutor.waited
561596
assert TestExecutor.cleaned

0 commit comments

Comments
 (0)