@@ -345,7 +345,9 @@ async def run(
345345 except KeyError as e :
346346 raise HTTPException (400 , "File(s) missing in form data" ) from e
347347
348- if request_data .variables is not None and not isinstance (request_data .variables , dict ):
348+ if request_data .variables is not None and not isinstance (
349+ request_data .variables , dict
350+ ):
349351 raise HTTPException (400 , "Variables must be a JSON object" )
350352
351353 allowed_operation_types = operation_type_from_http (request_adapter .method )
@@ -359,6 +361,7 @@ async def run(
359361 if self .graphql_ide and self .should_render_graphql_ide (request_adapter ):
360362 return await self .render_graphql_ide (request , request_data )
361363
364+ is_strict = request_data .protocol == "http-strict"
362365 try :
363366 result = await self .execute_operation (
364367 request = request ,
@@ -368,6 +371,9 @@ async def run(
368371 allowed_operation_types = allowed_operation_types ,
369372 )
370373 except GraphQLValidationError as e :
374+ if is_strict :
375+ sub_response .status_code = 400 # type: ignore
376+ # sub_response.headers["content-type"] = "application/graphql-response+json"
371377 result = ExecutionResult (data = None , errors = e .errors )
372378 except HTTPException :
373379 raise
@@ -391,7 +397,9 @@ async def run(
391397 },
392398 )
393399
394- response_data = await self .process_result (request = request , result = result )
400+ response_data = await self .process_result (
401+ request = request , result = result , strict = is_strict
402+ )
395403
396404 if result .errors :
397405 self ._handle_errors (result .errors , response_data )
@@ -549,7 +557,9 @@ async def get_graphql_request_data(
549557 request : Union [AsyncHTTPRequestAdapter , WebSocketRequest ],
550558 context : Context ,
551559 data : dict [str , Any ],
552- protocol : Literal ["http" , "multipart-subscription" , "subscription" ],
560+ protocol : Literal [
561+ "http" , "http-strict" , "multipart-subscription" , "subscription"
562+ ],
553563 ) -> GraphQLRequestData :
554564 return GraphQLRequestData (
555565 query = data .get ("query" ),
@@ -567,12 +577,15 @@ async def parse_http_body(
567577 ) -> GraphQLRequestData :
568578 headers = {key .lower (): value for key , value in request .headers .items ()}
569579 content_type , _ = parse_content_type (request .content_type or "" )
570- accept = headers .get ("accept" , "" )
580+ accept = headers .get ("accept" , "" ) or headers . get ( "http-accept" , "" )
571581
572- protocol : Literal ["http" , "multipart-subscription" ] = "http"
582+ accept_type = parse_content_type (accept )
583+ protocol : Literal ["http" , "http-strict" , "multipart-subscription" ] = "http"
573584
574- if self ._is_multipart_subscriptions (* parse_content_type ( accept ) ):
585+ if self ._is_multipart_subscriptions (* accept_type ):
575586 protocol = "multipart-subscription"
587+ elif "application/graphql-response+json" in accept_type :
588+ protocol = "http-strict"
576589
577590 if request .method == "GET" :
578591 data = self .parse_query_params (request .query_params )
@@ -586,9 +599,9 @@ async def parse_http_body(
586599 return await self .get_graphql_request_data (request , context , data , protocol )
587600
588601 async def process_result (
589- self , request : Request , result : ExecutionResult
602+ self , request : Request , result : ExecutionResult , strict : bool = False
590603 ) -> GraphQLHTTPResponse :
591- return process_result (result )
604+ return process_result (result , strict )
592605
593606 async def on_ws_connect (
594607 self , context : Context
0 commit comments