2323logger = logging .getLogger (__name__ )
2424
2525
26+ def subscribe (* args , ** kwargs ):
27+ allow_subscriptions = kwargs .pop ('allow_subscriptions' , True )
28+ return execute (* args , allow_subscriptions = allow_subscriptions , ** kwargs )
29+
30+
2631def execute (schema , document_ast , root_value = None , context_value = None ,
2732 variable_values = None , operation_name = None , executor = None ,
28- return_promise = False , middleware = None ):
33+ return_promise = False , middleware = None , allow_subscriptions = False ):
2934 assert schema , 'Must provide schema'
3035 assert isinstance (schema , GraphQLSchema ), (
3136 'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
@@ -51,7 +56,8 @@ def execute(schema, document_ast, root_value=None, context_value=None,
5156 variable_values ,
5257 operation_name ,
5358 executor ,
54- middleware
59+ middleware ,
60+ allow_subscriptions
5561 )
5662
5763 def executor (v ):
@@ -93,6 +99,12 @@ def execute_operation(exe_context, operation, root_value):
9399 return execute_fields_serially (exe_context , type , root_value , fields )
94100
95101 if operation .operation == 'subscription' :
102+ if not exe_context .allow_subscriptions :
103+ raise Exception (
104+ "Subscriptions are not allowed. "
105+ "You will need to either use the subscribe function "
106+ "or pass allow_subscriptions=True"
107+ )
96108 return subscribe_fields (exe_context , type , root_value , fields )
97109
98110 return execute_fields (exe_context , type , root_value , fields )
0 commit comments