1
1
# -*- coding: utf-8 -*-
2
2
from ..error import GraphQLError
3
3
from ..language import ast
4
- from ..pyutils .defer import DeferredException
5
4
from ..type .definition import GraphQLInterfaceType , GraphQLUnionType
6
5
from ..type .directives import GraphQLIncludeDirective , GraphQLSkipDirective
7
6
from ..type .introspection import (SchemaMetaFieldDef , TypeMetaFieldDef ,
@@ -18,10 +17,10 @@ class ExecutionContext(object):
18
17
Namely, schema of the type system that is currently executing,
19
18
and the fragments defined in the query document"""
20
19
21
- __slots__ = 'schema' , 'fragments' , 'root ' , 'operation' , 'variables ' , 'errors' , 'request_context ' , \
22
- 'argument_values_cache'
20
+ __slots__ = 'schema' , 'fragments' , 'root_value ' , 'operation' , 'variable_values ' , 'errors' , 'context_value ' , \
21
+ 'argument_values_cache' , 'executor'
23
22
24
- def __init__ (self , schema , root , document_ast , operation_name , args , request_context ):
23
+ def __init__ (self , schema , document_ast , root_value , context_value , variable_values , operation_name , executor ):
25
24
"""Constructs a ExecutionContext object from the arguments passed
26
25
to execute, which we will pass throughout the other execution
27
26
methods."""
@@ -53,24 +52,25 @@ def __init__(self, schema, root, document_ast, operation_name, args, request_con
53
52
else :
54
53
raise GraphQLError ('Must provide an operation.' )
55
54
56
- variables = get_variable_values (schema , operation .variable_definitions or [], args )
55
+ variable_values = get_variable_values (schema , operation .variable_definitions or [], variable_values )
57
56
58
57
self .schema = schema
59
58
self .fragments = fragments
60
- self .root = root
59
+ self .root_value = root_value
61
60
self .operation = operation
62
- self .variables = variables
61
+ self .variable_values = variable_values
63
62
self .errors = errors
64
- self .request_context = request_context
63
+ self .context_value = context_value
65
64
self .argument_values_cache = {}
65
+ self .executor = executor
66
66
67
67
def get_argument_values (self , field_def , field_ast ):
68
68
k = field_def , field_ast
69
69
result = self .argument_values_cache .get (k )
70
70
71
71
if not result :
72
72
result = self .argument_values_cache [k ] = get_argument_values (field_def .args , field_ast .arguments ,
73
- self .variables )
73
+ self .variable_values )
74
74
75
75
return result
76
76
@@ -84,12 +84,6 @@ class ExecutionResult(object):
84
84
85
85
def __init__ (self , data = None , errors = None , invalid = False ):
86
86
self .data = data
87
- if errors :
88
- errors = [
89
- error .value if isinstance (error , DeferredException ) else error
90
- for error in errors
91
- ]
92
-
93
87
self .errors = errors
94
88
95
89
if invalid :
@@ -190,6 +184,7 @@ def collect_fields(ctx, runtime_type, selection_set, fields, prev_fragment_names
190
184
def should_include_node (ctx , directives ):
191
185
"""Determines if a field should be included based on the @include and
192
186
@skip directives, where @skip has higher precidence than @include."""
187
+ # TODO: Refactor based on latest code
193
188
if directives :
194
189
skip_ast = None
195
190
@@ -202,7 +197,7 @@ def should_include_node(ctx, directives):
202
197
args = get_argument_values (
203
198
GraphQLSkipDirective .args ,
204
199
skip_ast .arguments ,
205
- ctx .variables ,
200
+ ctx .variable_values ,
206
201
)
207
202
return not args .get ('if' )
208
203
@@ -217,7 +212,7 @@ def should_include_node(ctx, directives):
217
212
args = get_argument_values (
218
213
GraphQLIncludeDirective .args ,
219
214
include_ast .arguments ,
220
- ctx .variables ,
215
+ ctx .variable_values ,
221
216
)
222
217
223
218
return bool (args .get ('if' ))
@@ -249,36 +244,17 @@ def get_field_entry_key(node):
249
244
250
245
class ResolveInfo (object ):
251
246
252
- def __init__ (self , field_name , field_asts , return_type , parent_type , context ):
247
+ def __init__ (self , field_name , field_asts , return_type , parent_type ,
248
+ schema , fragments , root_value , operation , variable_values ):
253
249
self .field_name = field_name
254
250
self .field_asts = field_asts
255
251
self .return_type = return_type
256
252
self .parent_type = parent_type
257
- self .context = context
258
-
259
- @property
260
- def schema (self ):
261
- return self .context .schema
262
-
263
- @property
264
- def fragments (self ):
265
- return self .context .fragments
266
-
267
- @property
268
- def root_value (self ):
269
- return self .context .root
270
-
271
- @property
272
- def operation (self ):
273
- return self .context .operation
274
-
275
- @property
276
- def variable_values (self ):
277
- return self .context .variables
278
-
279
- @property
280
- def request_context (self ):
281
- return self .context .request_context
253
+ self .schema = schema
254
+ self .fragments = fragments
255
+ self .root_value = root_value
256
+ self .operation = operation
257
+ self .variable_values = variable_values
282
258
283
259
284
260
def default_resolve_fn (source , args , info ):
0 commit comments