@@ -77,6 +77,8 @@ export interface HandlerOptions<RawRequest = unknown> {
77
77
/**
78
78
* A custom GraphQL validate function allowing you to apply your
79
79
* own validation rules.
80
+ *
81
+ * Will not be used when implementing a custom `onSubscribe`.
80
82
*/
81
83
validate ?: typeof graphqlValidate ;
82
84
/**
@@ -104,6 +106,8 @@ export interface HandlerOptions<RawRequest = unknown> {
104
106
* trying to build one internally. In this case, you are responsible for providing
105
107
* a ready set of arguments which will be directly plugged in the operation execution.
106
108
*
109
+ * You *must* validate the `ExecutionArgs` yourself if returning them.
110
+ *
107
111
* If you return an array of `GraphQLError` from the callback, they will be reported
108
112
* to the client while complying with the spec.
109
113
*
@@ -485,6 +489,30 @@ export function createHandler<RawRequest = unknown>(
485
489
schema,
486
490
} ;
487
491
}
492
+
493
+ const validationErrs = validate ( args . schema , args . document ) ;
494
+ if ( validationErrs . length ) {
495
+ return [
496
+ JSON . stringify ( { errors : validationErrs } ) ,
497
+ {
498
+ ...( acceptedMediaType === 'application/json'
499
+ ? {
500
+ status : 200 ,
501
+ statusText : 'OK' ,
502
+ }
503
+ : {
504
+ status : 400 ,
505
+ statusText : 'Bad Request' ,
506
+ } ) ,
507
+ headers : {
508
+ 'content-type' :
509
+ acceptedMediaType === 'application/json'
510
+ ? 'application/json; charset=utf-8'
511
+ : 'application/graphql+json; charset=utf-8' ,
512
+ } ,
513
+ } ,
514
+ ] ;
515
+ }
488
516
}
489
517
490
518
let operation : OperationTypeNode ;
@@ -542,30 +570,6 @@ export function createHandler<RawRequest = unknown>(
542
570
args . contextValue = maybeResOrContext ;
543
571
}
544
572
545
- const validationErrs = validate ( args . schema , args . document ) ;
546
- if ( validationErrs . length ) {
547
- return [
548
- JSON . stringify ( { errors : validationErrs } ) ,
549
- {
550
- ...( acceptedMediaType === 'application/json'
551
- ? {
552
- status : 200 ,
553
- statusText : 'OK' ,
554
- }
555
- : {
556
- status : 400 ,
557
- statusText : 'Bad Request' ,
558
- } ) ,
559
- headers : {
560
- 'content-type' :
561
- acceptedMediaType === 'application/json'
562
- ? 'application/json; charset=utf-8'
563
- : 'application/graphql+json; charset=utf-8' ,
564
- } ,
565
- } ,
566
- ] ;
567
- }
568
-
569
573
let result = await execute ( args ) ;
570
574
const maybeResOrResult = await onOperation ?.( req , args , result ) ;
571
575
if ( isResponse ( maybeResOrResult ) ) return maybeResOrResult ;
0 commit comments