@@ -438,6 +438,20 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
438
438
assert ( 'Status code' , res . status ) . toBe ( 400 ) ;
439
439
} ,
440
440
) ,
441
+ audit (
442
+ 'SHOULD not contain the data entry on JSON parsing failure when accepting application/graphql-response+json' ,
443
+ async ( ) => {
444
+ const res = await fetchFn ( opts . url , {
445
+ method : 'POST' ,
446
+ headers : {
447
+ 'content-type' : 'application/json' ,
448
+ accept : 'application/graphql-response+json' ,
449
+ } ,
450
+ body : '{ "not a JSON' ,
451
+ } ) ;
452
+ assert ( 'Data entry' , ( await res . json ( ) ) . data ) . toBe ( undefined ) ;
453
+ } ,
454
+ ) ,
441
455
audit (
442
456
'MUST use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json' ,
443
457
async ( ) => {
@@ -463,6 +477,18 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
463
477
assert ( 'Status code' , res . status ) . toBe ( 400 ) ;
464
478
} ,
465
479
) ,
480
+ audit (
481
+ 'SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json' ,
482
+ async ( ) => {
483
+ const url = new URL ( opts . url ) ;
484
+ url . searchParams . set ( 'qeury' /* typo */ , '{ __typename }' ) ;
485
+ const res = await fetchFn ( url . toString ( ) , {
486
+ method : 'GET' ,
487
+ headers : { accept : 'application/graphql-response+json' } ,
488
+ } ) ;
489
+ assert ( 'Data entry' , ( await res . json ( ) ) . data ) . toBe ( undefined ) ;
490
+ } ,
491
+ ) ,
466
492
audit (
467
493
'MUST use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json' ,
468
494
async ( ) => {
@@ -488,6 +514,18 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
488
514
assert ( 'Status code' , res . status ) . toBe ( 400 ) ;
489
515
} ,
490
516
) ,
517
+ audit (
518
+ 'SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json' ,
519
+ async ( ) => {
520
+ const url = new URL ( opts . url ) ;
521
+ url . searchParams . set ( 'query' , '{' ) ;
522
+ const res = await fetchFn ( url . toString ( ) , {
523
+ method : 'GET' ,
524
+ headers : { accept : 'application/graphql-response+json' } ,
525
+ } ) ;
526
+ assert ( 'Data entry' , ( await res . json ( ) ) . data ) . toBe ( undefined ) ;
527
+ } ,
528
+ ) ,
491
529
audit (
492
530
'MUST use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json' ,
493
531
async ( ) => {
@@ -513,6 +551,20 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
513
551
assert ( 'Status code' , res . status ) . toBe ( 400 ) ;
514
552
} ,
515
553
) ,
554
+ audit (
555
+ 'SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json' ,
556
+ async ( ) => {
557
+ const url = new URL ( opts . url ) ;
558
+ url . searchParams . set ( 'query' , '{ 8f31403dfe404bccbb0e835f2629c6a7 }' ) ; // making sure the field doesnt exist
559
+ const res = await fetchFn ( url . toString ( ) , {
560
+ method : 'GET' ,
561
+ headers : { accept : 'application/graphql-response+json' } ,
562
+ } ) ;
563
+ assert ( 'Data entry' , ( await res . json ( ) ) . data ) . toBe ( undefined ) ;
564
+ } ,
565
+ ) ,
566
+ // TODO: how to fail and have the data entry?
567
+ // audit('MUST use 2xx status code if response contains the data entry and it is not null when accepting application/graphql-response+json'),
516
568
// TODO: how to make an unauthorized request?
517
569
// https://graphql.github.io/graphql-over-http/draft/#sel-EANNNDTAAEVBAAqqc
518
570
// audit('SHOULD use 401 or 403 status codes when the request is not permitted')
0 commit comments