@@ -438,6 +438,11 @@ export function buildExecutionContext<TData = any, TVariables = any, TContext =
438
438
return [
439
439
createGraphQLError (
440
440
'Must provide operation name if query contains multiple operations.' ,
441
+ {
442
+ extensions : {
443
+ code : 'OPERATION_RESOLUTION_FAILURE' ,
444
+ } ,
445
+ } ,
441
446
) ,
442
447
] ;
443
448
}
@@ -453,9 +458,21 @@ export function buildExecutionContext<TData = any, TVariables = any, TContext =
453
458
454
459
if ( operation == null ) {
455
460
if ( operationName != null ) {
456
- return [ createGraphQLError ( `Unknown operation named "${ operationName } ".` ) ] ;
461
+ return [
462
+ createGraphQLError ( `Unknown operation named "${ operationName } ".` , {
463
+ extensions : {
464
+ code : 'OPERATION_RESOLUTION_FAILURE' ,
465
+ } ,
466
+ } ) ,
467
+ ] ;
457
468
}
458
- return [ createGraphQLError ( 'Must provide an operation.' ) ] ;
469
+ return [
470
+ createGraphQLError ( 'Must provide an operation.' , {
471
+ extensions : {
472
+ code : 'OPERATION_RESOLUTION_FAILURE' ,
473
+ } ,
474
+ } ) ,
475
+ ] ;
459
476
}
460
477
461
478
// FIXME: https://github.com/graphql/graphql-js/issues/2203
@@ -1532,19 +1549,15 @@ export function subscribe<TData = any, TVariables = any, TContext = any>(
1532
1549
1533
1550
// Return early errors if execution context failed.
1534
1551
if ( ! ( 'schema' in exeContext ) ) {
1552
+ for ( const error of exeContext ) {
1553
+ // @ts -expect-error - We are intentionally modifying the errors
1554
+ const extensions = ( error . extensions ||= { } ) ;
1555
+ const httpExtensions = ( extensions [ 'http' ] ||= { } ) ;
1556
+ httpExtensions . status = 400 ;
1557
+ error . extensions [ 'code' ] = 'BAD_USER_INPUT' ;
1558
+ }
1535
1559
return {
1536
- errors : exeContext . map ( e => {
1537
- Object . defineProperty ( e , 'extensions' , {
1538
- value : {
1539
- ...e . extensions ,
1540
- http : {
1541
- ...( e . extensions ?. [ 'http' ] || { } ) ,
1542
- status : 400 ,
1543
- } ,
1544
- } ,
1545
- } ) ;
1546
- return e ;
1547
- } ) ,
1560
+ errors : exeContext ,
1548
1561
} ;
1549
1562
}
1550
1563
0 commit comments