@@ -205,14 +205,10 @@ async def execute_operation(
205205 request_data : GraphQLRequestData ,
206206 context : Context ,
207207 root_value : Optional [RootValue ],
208+ allowed_operation_types : set [OperationType ],
208209 ) -> ExecutionResult :
209210 request_adapter = self .request_adapter_class (request )
210211
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-
216212 assert self .schema
217213
218214 if request_data .protocol == "multipart-subscription" :
@@ -331,12 +327,6 @@ async def run(
331327 request = cast ("Request" , request )
332328
333329 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- )
340330
341331 if not self .is_request_allowed (request_adapter ):
342332 raise HTTPException (405 , "GraphQL only supports GET and POST requests." )
@@ -349,17 +339,38 @@ async def run(
349339 except KeyError as e :
350340 raise HTTPException (400 , "File(s) missing in form data" ) from e
351341
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 )
353354 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+ )
356366
357367 try :
358368 result = await self .execute_operation (
359369 request = request ,
360370 request_data = request_data ,
361371 context = context ,
362372 root_value = root_value ,
373+ allowed_operation_types = allowed_operation_types ,
363374 )
364375 except GraphQLValidationError as e :
365376 result = ExecutionResult (data = None , errors = e .errors )
0 commit comments