Skip to content

Commit b8f7f65

Browse files
jnakCito
authored andcommitted
Bump Promise version (#260)
Bump Promise version, use ordered dict in more places GraphQLInputObjectTypes now use OrderedDicts as default container_type, and value_from_ast converts JSON objects to OrderedDicts. This also fixes the test_builds_a_schema_with_field_arguments_with_default_values.
1 parent a600f7c commit b8f7f65

File tree

8 files changed

+31
-15
lines changed

8 files changed

+31
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ nosetests.xml
4545
coverage.xml
4646
*.cover
4747
.pytest_cache/
48+
.python-version
4849

4950
# PyBuilder
5051
target/

graphql/execution/executor.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def complete_value(
529529
lambda resolved: complete_value(
530530
exe_context, return_type, field_asts, info, path, resolved
531531
),
532-
lambda error: Promise.rejected(
532+
lambda error: Promise.rejected( # type: ignore
533533
GraphQLLocatedError(field_asts, original_error=error, path=path)
534534
),
535535
)
@@ -602,7 +602,9 @@ def complete_list_value(
602602
completed_results.append(completed_item)
603603
index += 1
604604

605-
return Promise.all(completed_results) if contains_promise else completed_results
605+
return ( # type: ignore
606+
Promise.all(completed_results) if contains_promise else completed_results
607+
)
606608

607609

608610
def complete_leaf_value(
@@ -711,7 +713,9 @@ def complete_object_value(
711713

712714
# Collect sub-fields to execute to complete this value.
713715
subfield_asts = exe_context.get_sub_fields(return_type, field_asts)
714-
return execute_fields(exe_context, return_type, result, subfield_asts, path, info)
716+
return execute_fields( # type: ignore
717+
exe_context, return_type, result, subfield_asts, path, info
718+
)
715719

716720

717721
def complete_nonnull_value(

graphql/execution/executors/thread.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def clean(self):
3535

3636
def execute_in_thread(self, fn, *args, **kwargs):
3737
# type: (Callable, *Any, **Any) -> Promise
38-
promise = Promise()
38+
promise = Promise() # type: ignore
3939
thread = Thread(target=process, args=(promise, fn, args, kwargs))
4040
thread.start()
4141
self.threads.append(thread)

graphql/execution/tests/test_executor_thread.py

+11
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111
GraphQLSchema,
1212
GraphQLString,
1313
)
14+
from pytest import mark
1415

1516
from ..executors.thread import ThreadExecutor
1617
from .test_mutations import assert_evaluate_mutations_serially
1718
from .utils import rejected, resolved
1819

20+
###
21+
# Disabled because all these tests are flaky
22+
# The culprit is that the `ThreadExecutor` incorrectly assumes that
23+
# the `Promise` class is thread-safe.
24+
# See https://git.io/JeA3s
25+
###
1926

27+
28+
@mark.xfail
2029
def test_executes_arbitary_code():
2130
# type: () -> None
2231
class Data(object):
@@ -157,6 +166,7 @@ def handle_result(result):
157166
)
158167

159168

169+
@mark.xfail
160170
def test_synchronous_error_nulls_out_error_subtrees():
161171
# type: () -> None
162172
ast = parse(
@@ -289,6 +299,7 @@ def handle_results(result):
289299
handle_results(execute(schema, ast, Data(), executor=ThreadExecutor()))
290300

291301

302+
@mark.xfail
292303
def test_evaluates_mutations_serially():
293304
# type: () -> None
294305
assert_evaluate_mutations_serially(executor=ThreadExecutor())

graphql/type/definition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def __init__(
649649
self.name = name
650650
self.description = description
651651
if container_type is None:
652-
container_type = dict # type: ignore
652+
container_type = OrderedDict # type: ignore
653653
assert callable(container_type), "container_type must be callable"
654654
self.container_type = container_type
655655
self._fields = fields

graphql/utils/value_from_ast.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ..language import ast
2+
from ..pyutils.ordereddict import OrderedDict
23
from ..type import (
34
GraphQLEnumType,
45
GraphQLInputObjectType,
@@ -56,13 +57,15 @@ def value_from_ast(value_ast, type, variables=None):
5657
for field_ast in value_ast.fields:
5758
field_asts[field_ast.name.value] = field_ast
5859

59-
obj = {}
60+
obj_items = []
6061
for field_name, field in fields.items():
6162
if field_name not in field_asts:
6263
if field.default_value is not None:
6364
# We use out_name as the output name for the
6465
# dict if exists
65-
obj[field.out_name or field_name] = field.default_value
66+
obj_items.append(
67+
(field.out_name or field_name, field.default_value)
68+
)
6669

6770
continue
6871

@@ -72,7 +75,9 @@ def value_from_ast(value_ast, type, variables=None):
7275

7376
# We use out_name as the output name for the
7477
# dict if exists
75-
obj[field.out_name or field_name] = field_value
78+
obj_items.append((field.out_name or field_name, field_value))
79+
80+
obj = OrderedDict(obj_items)
7681

7782
return type.create_container(obj)
7883

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
sys.path[:] = path_copy
2323

24-
install_requires = ["six>=1.10.0", "promise>=2.1", "rx>=1.6,<3"]
24+
install_requires = ["six>=1.10.0", "promise>=2.3", "rx>=1.6,<3"]
2525

2626
tests_requires = [
2727
"pytest>=3.3,<4.0",

tox.ini

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ envlist = py27,py34,py35,py36,py37,pre-commit,pypy,mypy,docs
33

44
[testenv]
55
deps =
6-
pytest>=3.3,<4.0
7-
gevent>=1.1
8-
promise>=2.0
9-
six>=1.10.0
10-
pytest-mock
11-
pytest-benchmark
6+
.[test]
127
commands =
138
py{27,34,py}: py.test graphql tests {posargs}
149
py{35,36,37}: py.test graphql tests tests_py35 {posargs}

0 commit comments

Comments
 (0)