@@ -507,6 +507,12 @@ export function createHandler<
507
507
) {
508
508
throw new Error ( 'Invalid variables' ) ;
509
509
}
510
+ if (
511
+ partParams . operationName != null &&
512
+ typeof partParams . operationName !== 'string'
513
+ ) {
514
+ throw new Error ( 'Invalid operationName' ) ;
515
+ }
510
516
if (
511
517
partParams . extensions != null &&
512
518
( typeof partParams . extensions !== 'object' ||
@@ -518,7 +524,7 @@ export function createHandler<
518
524
// request parameters are checked and now complete
519
525
params = partParams as RequestParams ;
520
526
} catch ( err ) {
521
- return makeResponse ( new GraphQLError ( err . message ) , acceptedMediaType ) ;
527
+ return makeResponse ( err , acceptedMediaType ) ;
522
528
}
523
529
524
530
let args : OperationArgs < Context > ;
@@ -707,9 +713,26 @@ export function makeResponse(
707
713
resultOrErrors :
708
714
| Readonly < ExecutionResult >
709
715
| Readonly < GraphQLError [ ] >
710
- | Readonly < GraphQLError > ,
716
+ | Readonly < GraphQLError >
717
+ | Readonly < Error > ,
711
718
acceptedMediaType : AcceptableMediaType ,
712
719
) : Response {
720
+ if (
721
+ resultOrErrors instanceof Error &&
722
+ // because GraphQLError extends the Error class
723
+ ! ( resultOrErrors instanceof GraphQLError )
724
+ ) {
725
+ return [
726
+ JSON . stringify ( { errors : [ resultOrErrors ] } ) ,
727
+ {
728
+ status : 400 ,
729
+ statusText : 'Bad Request' ,
730
+ headers : {
731
+ 'content-type' : 'application/json; charset=utf-8' ,
732
+ } ,
733
+ } ,
734
+ ] ;
735
+ }
713
736
const errors = isGraphQLError ( resultOrErrors )
714
737
? [ resultOrErrors ]
715
738
: areGraphQLErrors ( resultOrErrors )
0 commit comments