44import sys
55
66from six import string_types
7- from promise import Promise , promise_for_dict , promisify , is_thenable
7+ from promise import Promise , promise_for_dict , is_thenable
88
99from ..error import GraphQLError , GraphQLLocatedError
1010from ..pyutils .default_ordered_dict import DefaultOrderedDict
1616 collect_fields , default_resolve_fn , get_field_def ,
1717 get_operation_root_type )
1818from .executors .sync import SyncExecutor
19+ from .experimental .executor import execute as experimental_execute
1920from .middleware import MiddlewareManager
2021
2122logger = logging .getLogger (__name__ )
@@ -25,9 +26,19 @@ def is_promise(obj):
2526 return type (obj ) == Promise
2627
2728
29+ use_experimental_executor = False
30+
31+
2832def execute (schema , document_ast , root_value = None , context_value = None ,
2933 variable_values = None , operation_name = None , executor = None ,
3034 return_promise = False , middleware = None ):
35+ if use_experimental_executor :
36+ return experimental_execute (
37+ schema , document_ast , root_value , context_value ,
38+ variable_values , operation_name , executor ,
39+ return_promise , middleware
40+ )
41+
3142 assert schema , 'Must provide schema'
3243 assert isinstance (schema , GraphQLSchema ), (
3344 'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
@@ -106,7 +117,7 @@ def collect_result(resolved_result):
106117 results [response_name ] = resolved_result
107118 return results
108119
109- return promisify ( result ) .then (collect_result , None )
120+ return result .then (collect_result , None )
110121
111122 results [response_name ] = result
112123 return results
@@ -210,9 +221,9 @@ def complete_value_catching_error(exe_context, return_type, field_asts, info, re
210221 if is_thenable (completed ):
211222 def handle_error (error ):
212223 exe_context .errors .append (error )
213- return Promise . fulfilled ( None )
224+ return None
214225
215- return promisify ( completed ). then ( None , handle_error )
226+ return completed . catch ( handle_error )
216227
217228 return completed
218229 except Exception as e :
@@ -242,7 +253,7 @@ def complete_value(exe_context, return_type, field_asts, info, result):
242253 # If field type is NonNull, complete for inner type, and throw field error if result is null.
243254
244255 if is_thenable (result ):
245- return promisify (result ).then (
256+ return Promise . resolve (result ).then (
246257 lambda resolved : complete_value (
247258 exe_context ,
248259 return_type ,
0 commit comments