Skip to content

Commit d8df44a

Browse files
committed
Improved code with PEP8, Flake8, isort
1 parent 0b15212 commit d8df44a

File tree

16 files changed

+59
-60
lines changed

16 files changed

+59
-60
lines changed

graphql/execution/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
from .execute import execute as _execute
2222
from .base import ExecutionResult
2323

24+
2425
def execute(schema, root, ast, operation_name='', args=None):
2526
return _execute(schema, ast, root, variable_values=args, operation_name=operation_name)
27+
28+
__all__ = ['execute', 'ExecutionResult']

graphql/execution/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ def get_field_entry_key(node):
251251

252252
class ResolveInfo(object):
253253

254-
def __init__(self, field_name, field_asts, return_type, parent_type, schema, fragments, root_value, operation, variable_values):
254+
def __init__(self, field_name, field_asts, return_type, parent_type,
255+
schema, fragments, root_value, operation, variable_values):
255256
self.field_name = field_name
256257
self.field_asts = field_asts
257258
self.return_type = return_type

graphql/execution/execute.py

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
import functools
33

44
from ..error import GraphQLError
5-
from ..language import ast
6-
from ..language.parser import parse
7-
from ..language.source import Source
5+
from ..pyutils.aplus import Promise, is_thenable, promise_for_dict, promisify
86
from ..pyutils.default_ordered_dict import DefaultOrderedDict
9-
from ..pyutils.aplus import Promise, is_thenable, promisify, promise_for_dict
10-
from ..pyutils.defer import (Deferred, DeferredDict, DeferredList, defer,
11-
succeed)
127
from ..type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList,
138
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
14-
GraphQLUnionType, GraphQLSchema)
15-
from ..validation import validate
9+
GraphQLSchema, GraphQLUnionType)
1610
from .base import (ExecutionContext, ExecutionResult, ResolveInfo, Undefined,
1711
collect_fields, default_resolve_fn, get_field_def,
1812
get_operation_root_type)
1913
from .executors.sync import SyncExecutor
2014

2115

22-
def execute(schema, document_ast, root_value=None, context_value=None, variable_values=None, operation_name=None, executor=None):
16+
def execute(schema, document_ast, root_value=None, context_value=None,
17+
variable_values=None, operation_name=None, executor=None):
2318
assert schema, 'Must provide schema'
24-
assert isinstance(schema, GraphQLSchema), 'Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory.'
19+
assert isinstance(schema, GraphQLSchema), (
20+
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
21+
'not multiple versions of GraphQL installed in your node_modules directory.'
22+
)
2523

2624
if executor is None:
2725
executor = SyncExecutor()
@@ -51,7 +49,6 @@ def on_resolve(data):
5149
return p.value
5250

5351

54-
5552
def execute_operation(exe_context, operation, root_value):
5653
type = get_operation_root_type(exe_context.schema, operation)
5754
fields = collect_fields(
@@ -89,38 +86,13 @@ def collect_result(resolved_result):
8986

9087
results[response_name] = result
9188
return results
89+
9290
def execute_field(prev_promise, response_name):
9391
return prev_promise.then(lambda results: execute_field_callback(results, response_name))
9492

9593
return functools.reduce(execute_field, fields.keys(), Promise.resolve(collections.OrderedDict()))
9694

9795

98-
# def execute_fields_serially(exe_context, parent_type, source_value, fields):
99-
# final_results = collections.OrderedDict()
100-
101-
# prev_promise = Promise.resolve(collections.OrderedDict())
102-
103-
# def on_promise(results, response_name, field_asts):
104-
# result = resolve_field(exe_context, parent_type, source_value, field_asts)
105-
# if result is Undefined:
106-
# return results
107-
108-
# if is_thenable(result):
109-
# def collect_result(resolved_result):
110-
# results[response_name] = resolved_result
111-
# return results
112-
113-
# return promisify(result).then(collect_result)
114-
115-
# results[response_name] = result
116-
# return results
117-
118-
# for response_name, field_asts in fields.items():
119-
# prev_promise = prev_promise.then(lambda results: on_promise(results, response_name, field_asts))
120-
121-
# return prev_promise
122-
123-
12496
def execute_fields(exe_context, parent_type, source_value, fields):
12597
contains_promise = False
12698

@@ -166,8 +138,8 @@ def resolve_field(exe_context, parent_type, source, field_asts):
166138
schema=exe_context.schema,
167139
fragments=exe_context.fragments,
168140
root_value=exe_context.root_value,
169-
operation= exe_context.operation,
170-
variable_values= exe_context.variable_values,
141+
operation=exe_context.operation,
142+
variable_values=exe_context.variable_values,
171143
)
172144

173145
result = resolve_or_error(resolve_fn, source, args, exe_context, info)
@@ -302,7 +274,6 @@ def complete_list_value(exe_context, return_type, field_asts, info, result):
302274
return Promise.all(completed_results) if contains_promise else completed_results
303275

304276

305-
306277
def complete_leaf_value(return_type, result):
307278
"""
308279
Complete a Scalar or Enum by serializing to a valid value, returning null if serialization is not possible.

graphql/execution/executors/asyncio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

3-
from asyncio import Future, ensure_future, iscoroutine, get_event_loop, wait
3+
from asyncio import Future, ensure_future, get_event_loop, iscoroutine, wait
4+
45
from graphql.pyutils.aplus import Promise
56

67

@@ -16,6 +17,7 @@ def handle_future_result(future):
1617

1718

1819
class AsyncioExecutor(object):
20+
1921
def __init__(self):
2022
self.loop = get_event_loop()
2123
self.futures = []

graphql/execution/executors/gevent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import absolute_import
22

33
import gevent
4-
from .utils import process
4+
55
from ...pyutils.aplus import Promise
6+
from .utils import process
67

78

89
class GeventExecutor(object):
10+
911
def __init__(self):
1012
self.jobs = []
1113

graphql/execution/executors/process.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
from multiprocessing import Pool, Process, Queue
1+
from multiprocessing import Process, Queue
2+
23
from ...pyutils.aplus import Promise
34
from .utils import process
45

6+
57
def queue_process(q):
68
promise, fn, args, kwargs = q.get()
79
process(promise, fn, args, kwargs)
810

911

1012
class ProcessExecutor(object):
13+
1114
def __init__(self):
1215
self.processes = []
1316
self.q = Queue()
@@ -20,8 +23,8 @@ def wait_until_finished(self):
2023

2124
def execute(self, fn, *args, **kwargs):
2225
promise = Promise()
23-
24-
q.put([promise, fn, args, kwargs], False)
26+
27+
self.q.put([promise, fn, args, kwargs], False)
2528
_process = Process(target=queue_process, args=(self.q))
2629
_process.start()
2730
self.processes.append(_process)

graphql/execution/executors/sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class SyncExecutor(object):
2+
23
def wait_until_finished(self):
34
pass
45

graphql/execution/executors/thread.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from threading import Thread
2+
23
from ...pyutils.aplus import Promise
34
from .utils import process
45

56

67
class ThreadExecutor(object):
8+
79
def __init__(self):
810
self.threads = []
911

graphql/execution/tests/test_concurrent_executor.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from collections import OrderedDict
21

32
from graphql.error import format_error
3+
from graphql.execution.execute import execute
4+
from graphql.language.parser import parse
45
from graphql.type import (GraphQLArgument, GraphQLField, GraphQLInt,
56
GraphQLList, GraphQLObjectType, GraphQLSchema,
67
GraphQLString)
78
from graphql.type.definition import GraphQLNonNull
8-
from graphql.execution.execute import execute
9-
from graphql.language.parser import parse
109

11-
# from .utils import raise_callback_results
12-
from .utils import resolved, rejected
1310
from ..executors.thread import ThreadExecutor
11+
# from .utils import raise_callback_results
12+
from .utils import rejected, resolved
13+
1414

1515
def test_executes_arbitary_code():
1616
class Data(object):
@@ -118,7 +118,15 @@ def handle_result(result):
118118
assert not result.errors
119119
assert result.data == expected
120120

121-
handle_result(execute(schema, ast, Data(), variable_values={'size': 100}, operation_name='Example', executor=ThreadExecutor()))
121+
handle_result(
122+
execute(
123+
schema,
124+
ast,
125+
Data(),
126+
variable_values={
127+
'size': 100},
128+
operation_name='Example',
129+
executor=ThreadExecutor()))
122130
handle_result(execute(schema, ast, Data(), variable_values={'size': 100}, operation_name='Example'))
123131

124132

graphql/execution/tests/test_execute.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from collections import OrderedDict
32

43
from pytest import raises
54

0 commit comments

Comments
 (0)