@@ -205,14 +205,10 @@ async def execute_operation(
205
205
request_data : GraphQLRequestData ,
206
206
context : Context ,
207
207
root_value : Optional [RootValue ],
208
+ allowed_operation_types : set [OperationType ],
208
209
) -> ExecutionResult :
209
210
request_adapter = self .request_adapter_class (request )
210
211
211
- allowed_operation_types = operation_type_from_http (request_adapter .method )
212
-
213
- if not self .allow_queries_via_get and request_adapter .method == "GET" :
214
- allowed_operation_types = allowed_operation_types - {OperationType .QUERY }
215
-
216
212
assert self .schema
217
213
218
214
if request_data .protocol == "multipart-subscription" :
@@ -331,12 +327,6 @@ async def run(
331
327
request = cast ("Request" , request )
332
328
333
329
request_adapter = self .request_adapter_class (request )
334
- sub_response = await self .get_sub_response (request )
335
- context = (
336
- await self .get_context (request , response = sub_response )
337
- if context is UNSET
338
- else context
339
- )
340
330
341
331
if not self .is_request_allowed (request_adapter ):
342
332
raise HTTPException (405 , "GraphQL only supports GET and POST requests." )
@@ -349,17 +339,38 @@ async def run(
349
339
except KeyError as e :
350
340
raise HTTPException (400 , "File(s) missing in form data" ) from e
351
341
352
- if self .should_render_graphql_ide (request_adapter ):
342
+ allowed_operation_types = operation_type_from_http (request_adapter .method )
343
+
344
+ if not self .allow_queries_via_get and request_adapter .method == "GET" :
345
+ allowed_operation_types = allowed_operation_types - {OperationType .QUERY }
346
+
347
+ if request_adapter .method == "GET" :
348
+ if not self .allow_queries_via_get :
349
+ allowed_operation_types = allowed_operation_types - {
350
+ OperationType .QUERY
351
+ }
352
+
353
+ should_render_graphql_ide = self .should_render_graphql_ide (request_adapter )
353
354
if self .graphql_ide :
354
- return await self .render_graphql_ide (request , request_data )
355
- raise HTTPException (404 , "Not Found" )
355
+ if should_render_graphql_ide :
356
+ return await self .render_graphql_ide (request , request_data )
357
+ elif should_render_graphql_ide :
358
+ raise HTTPException (404 , "Not Found" ) # pragma: no cover
359
+
360
+ sub_response = await self .get_sub_response (request )
361
+ context = (
362
+ await self .get_context (request , response = sub_response )
363
+ if context is UNSET
364
+ else context
365
+ )
356
366
357
367
try :
358
368
result = await self .execute_operation (
359
369
request = request ,
360
370
request_data = request_data ,
361
371
context = context ,
362
372
root_value = root_value ,
373
+ allowed_operation_types = allowed_operation_types ,
363
374
)
364
375
except GraphQLValidationError as e :
365
376
result = ExecutionResult (data = None , errors = e .errors )
0 commit comments