@@ -345,7 +345,9 @@ async def run(
345
345
except KeyError as e :
346
346
raise HTTPException (400 , "File(s) missing in form data" ) from e
347
347
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
+ ):
349
351
raise HTTPException (400 , "Variables must be a JSON object" )
350
352
351
353
allowed_operation_types = operation_type_from_http (request_adapter .method )
@@ -359,6 +361,7 @@ async def run(
359
361
if self .graphql_ide and self .should_render_graphql_ide (request_adapter ):
360
362
return await self .render_graphql_ide (request , request_data )
361
363
364
+ is_strict = request_data .protocol == "http-strict"
362
365
try :
363
366
result = await self .execute_operation (
364
367
request = request ,
@@ -368,6 +371,9 @@ async def run(
368
371
allowed_operation_types = allowed_operation_types ,
369
372
)
370
373
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"
371
377
result = ExecutionResult (data = None , errors = e .errors )
372
378
except HTTPException :
373
379
raise
@@ -391,7 +397,9 @@ async def run(
391
397
},
392
398
)
393
399
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
+ )
395
403
396
404
if result .errors :
397
405
self ._handle_errors (result .errors , response_data )
@@ -549,7 +557,9 @@ async def get_graphql_request_data(
549
557
request : Union [AsyncHTTPRequestAdapter , WebSocketRequest ],
550
558
context : Context ,
551
559
data : dict [str , Any ],
552
- protocol : Literal ["http" , "multipart-subscription" , "subscription" ],
560
+ protocol : Literal [
561
+ "http" , "http-strict" , "multipart-subscription" , "subscription"
562
+ ],
553
563
) -> GraphQLRequestData :
554
564
return GraphQLRequestData (
555
565
query = data .get ("query" ),
@@ -567,12 +577,15 @@ async def parse_http_body(
567
577
) -> GraphQLRequestData :
568
578
headers = {key .lower (): value for key , value in request .headers .items ()}
569
579
content_type , _ = parse_content_type (request .content_type or "" )
570
- accept = headers .get ("accept" , "" )
580
+ accept = headers .get ("accept" , "" ) or headers . get ( "http-accept" , "" )
571
581
572
- protocol : Literal ["http" , "multipart-subscription" ] = "http"
582
+ accept_type = parse_content_type (accept )
583
+ protocol : Literal ["http" , "http-strict" , "multipart-subscription" ] = "http"
573
584
574
- if self ._is_multipart_subscriptions (* parse_content_type ( accept ) ):
585
+ if self ._is_multipart_subscriptions (* accept_type ):
575
586
protocol = "multipart-subscription"
587
+ elif "application/graphql-response+json" in accept_type :
588
+ protocol = "http-strict"
576
589
577
590
if request .method == "GET" :
578
591
data = self .parse_query_params (request .query_params )
@@ -586,9 +599,9 @@ async def parse_http_body(
586
599
return await self .get_graphql_request_data (request , context , data , protocol )
587
600
588
601
async def process_result (
589
- self , request : Request , result : ExecutionResult
602
+ self , request : Request , result : ExecutionResult , strict : bool = False
590
603
) -> GraphQLHTTPResponse :
591
- return process_result (result )
604
+ return process_result (result , strict )
592
605
593
606
async def on_ws_connect (
594
607
self , context : Context
0 commit comments