23
23
logger = logging .getLogger (__name__ )
24
24
25
25
26
+ def subscribe (* args , ** kwargs ):
27
+ allow_subscriptions = kwargs .pop ('allow_subscriptions' , True )
28
+ return execute (* args , allow_subscriptions = allow_subscriptions , ** kwargs )
29
+
30
+
26
31
def execute (schema , document_ast , root_value = None , context_value = None ,
27
32
variable_values = None , operation_name = None , executor = None ,
28
- return_promise = False , middleware = None ):
33
+ return_promise = False , middleware = None , allow_subscriptions = False ):
29
34
assert schema , 'Must provide schema'
30
35
assert isinstance (schema , GraphQLSchema ), (
31
36
'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,
51
56
variable_values ,
52
57
operation_name ,
53
58
executor ,
54
- middleware
59
+ middleware ,
60
+ allow_subscriptions
55
61
)
56
62
57
63
def executor (v ):
@@ -93,6 +99,12 @@ def execute_operation(exe_context, operation, root_value):
93
99
return execute_fields_serially (exe_context , type , root_value , fields )
94
100
95
101
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
+ )
96
108
return subscribe_fields (exe_context , type , root_value , fields )
97
109
98
110
return execute_fields (exe_context , type , root_value , fields )
0 commit comments