@@ -612,7 +612,7 @@ describe('Execute: Handles basic execution tasks', () => {
612
612
expect ( result ) . to . deep . equal ( { data : { second : 'b' } } ) ;
613
613
} ) ;
614
614
615
- it ( 'throws if no operation is provided' , ( ) => {
615
+ it ( 'provides error if no operation is provided' , async ( ) => {
616
616
const doc = 'fragment Example on Type { a }' ;
617
617
const data = { a : 'b' } ;
618
618
const ast = parse ( doc ) ;
@@ -625,12 +625,19 @@ describe('Execute: Handles basic execution tasks', () => {
625
625
} )
626
626
} ) ;
627
627
628
- expect ( ( ) => execute ( schema , ast , data ) ) . to . throw (
629
- 'Must provide an operation.'
630
- ) ;
628
+ const result = await execute ( schema , ast , data ) ;
629
+ expect ( result ) . to . deep . equal ( {
630
+ errors : [
631
+ {
632
+ message : 'Must provide an operation.' ,
633
+ locations : undefined ,
634
+ path : undefined ,
635
+ }
636
+ ]
637
+ } ) ;
631
638
} ) ;
632
639
633
- it ( 'throws if no operation name is provided with multiple operations' , ( ) => {
640
+ it ( 'throws if no op name is provided with multiple operations' , async ( ) => {
634
641
const doc = 'query Example { a } query OtherExample { a }' ;
635
642
const data = { a : 'b' } ;
636
643
const ast = parse ( doc ) ;
@@ -643,14 +650,21 @@ describe('Execute: Handles basic execution tasks', () => {
643
650
} )
644
651
} ) ;
645
652
646
- expect ( ( ) => execute ( schema , ast , data ) ) . to . throw (
647
- 'Must provide operation name if query contains multiple operations.'
648
- ) ;
653
+ const result = await execute ( schema , ast , data ) ;
654
+ expect ( result ) . to . deep . equal ( {
655
+ errors : [
656
+ {
657
+ message : 'Must provide operation name if query contains ' +
658
+ 'multiple operations.' ,
659
+ locations : undefined ,
660
+ path : undefined ,
661
+ }
662
+ ]
663
+ } ) ;
649
664
} ) ;
650
665
651
- it ( 'throws if unknown operation name is provided' , ( ) => {
666
+ it ( 'throws if unknown operation name is provided' , async ( ) => {
652
667
const doc = 'query Example { a } query OtherExample { a }' ;
653
- const data = { a : 'b' } ;
654
668
const ast = parse ( doc ) ;
655
669
const schema = new GraphQLSchema ( {
656
670
query : new GraphQLObjectType ( {
@@ -661,11 +675,20 @@ describe('Execute: Handles basic execution tasks', () => {
661
675
} )
662
676
} ) ;
663
677
664
- expect ( ( ) =>
665
- execute ( schema , ast , data , null , null , 'UnknownExample' )
666
- ) . to . throw (
667
- 'Unknown operation named "UnknownExample".'
668
- ) ;
678
+ const result = await execute ( {
679
+ schema,
680
+ document : ast ,
681
+ operationName : 'UnknownExample'
682
+ } ) ;
683
+ expect ( result ) . to . deep . equal ( {
684
+ errors : [
685
+ {
686
+ message : 'Unknown operation named "UnknownExample".' ,
687
+ locations : undefined ,
688
+ path : undefined ,
689
+ }
690
+ ]
691
+ } ) ;
669
692
} ) ;
670
693
671
694
it ( 'uses the query schema for queries' , async ( ) => {
@@ -960,17 +983,16 @@ describe('Execute: Handles basic execution tasks', () => {
960
983
} )
961
984
} ) ;
962
985
963
- let caughtError ;
964
- try {
965
- await execute ( schema , query ) ;
966
- } catch ( error ) {
967
- caughtError = error ;
968
- }
969
-
970
- expect ( caughtError ) . to . jsonEqual ( {
971
- message :
972
- 'GraphQL cannot execute a request containing a ObjectTypeDefinition.' ,
973
- locations : [ { line : 4 , column : 7 } ]
986
+ const result = await execute ( schema , query ) ;
987
+ expect ( result ) . to . deep . equal ( {
988
+ errors : [
989
+ {
990
+ message : 'GraphQL cannot execute a request containing a ' +
991
+ 'ObjectTypeDefinition.' ,
992
+ locations : [ { line : 4 , column : 7 } ] ,
993
+ path : undefined ,
994
+ }
995
+ ]
974
996
} ) ;
975
997
} ) ;
976
998
0 commit comments