2
2
import functools
3
3
import logging
4
4
import sys
5
+ import warnings
5
6
from rx import Observable
6
7
7
8
from six import string_types
@@ -28,9 +29,31 @@ def subscribe(*args, **kwargs):
28
29
return execute (* args , allow_subscriptions = allow_subscriptions , ** kwargs )
29
30
30
31
31
- def execute (schema , document_ast , root_value = None , context_value = None ,
32
- variable_values = None , operation_name = None , executor = None ,
33
- return_promise = False , middleware = None , allow_subscriptions = False ):
32
+ def execute (schema , document_ast , root = None , context = None ,
33
+ variables = None , operation_name = None , executor = None ,
34
+ return_promise = False , middleware = None , allow_subscriptions = False , ** options ):
35
+
36
+ if root is None and 'root_value' in options :
37
+ warnings .warn (
38
+ 'root_value has been deprecated. Please use root=... instead.' ,
39
+ category = DeprecationWarning ,
40
+ stacklevel = 2
41
+ )
42
+ root = options ['root_value' ]
43
+ if context is None and 'context_value' in options :
44
+ warnings .warn (
45
+ 'context_value has been deprecated. Please use context=... instead.' ,
46
+ category = DeprecationWarning ,
47
+ stacklevel = 2
48
+ )
49
+ context = options ['context_value' ]
50
+ if variables is None and 'variable_values' in options :
51
+ warnings .warn (
52
+ 'variable_values has been deprecated. Please use values=... instead.' ,
53
+ category = DeprecationWarning ,
54
+ stacklevel = 2
55
+ )
56
+ variables = options ['variable_values' ]
34
57
assert schema , 'Must provide schema'
35
58
assert isinstance (schema , GraphQLSchema ), (
36
59
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
@@ -49,38 +72,38 @@ def execute(schema, document_ast, root_value=None, context_value=None,
49
72
if executor is None :
50
73
executor = SyncExecutor ()
51
74
52
- context = ExecutionContext (
75
+ exe_context = ExecutionContext (
53
76
schema ,
54
77
document_ast ,
55
- root_value ,
56
- context_value ,
57
- variable_values ,
78
+ root ,
79
+ context ,
80
+ variables or {} ,
58
81
operation_name ,
59
82
executor ,
60
83
middleware ,
61
84
allow_subscriptions
62
85
)
63
86
64
87
def executor (v ):
65
- return execute_operation (context , context .operation , root_value )
88
+ return execute_operation (exe_context , exe_context .operation , root )
66
89
67
90
def on_rejected (error ):
68
- context .errors .append (error )
91
+ exe_context .errors .append (error )
69
92
return None
70
93
71
94
def on_resolve (data ):
72
95
if isinstance (data , Observable ):
73
96
return data
74
97
75
- if not context .errors :
98
+ if not exe_context .errors :
76
99
return ExecutionResult (data = data )
77
100
78
- return ExecutionResult (data = data , errors = context .errors )
101
+ return ExecutionResult (data = data , errors = exe_context .errors )
79
102
80
103
promise = Promise .resolve (None ).then (executor ).catch (on_rejected ).then (on_resolve )
81
104
82
105
if not return_promise :
83
- context .executor .wait_until_finished ()
106
+ exe_context .executor .wait_until_finished ()
84
107
return promise .get ()
85
108
86
109
return promise
0 commit comments