@@ -572,9 +572,11 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
572
572
return async ( params , contextExtension ) => {
573
573
const context = await contextFactory ( contextExtension ) ;
574
574
575
+ let result : AsyncIterableIteratorOrValue < ExecutionResult > | null = null ;
576
+
575
577
const doneFns : OnPerformDoneHook [ ] = [ ] ;
576
578
for ( const onPerform of beforeCallbacks . perform ) {
577
- const result = await onPerform ( {
579
+ const after = await onPerform ( {
578
580
context,
579
581
extendContext : extension => {
580
582
Object . assign ( context , extension ) ;
@@ -583,38 +585,47 @@ export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>
583
585
setParams : newParams => {
584
586
params = newParams ;
585
587
} ,
588
+ setResult : earlyResult => {
589
+ result = earlyResult ;
590
+ } ,
586
591
} ) ;
587
592
588
- result ?. onPerformDone && doneFns . push ( result . onPerformDone ) ;
593
+ after ?. onPerformDone && doneFns . push ( after . onPerformDone ) ;
589
594
}
590
595
591
- let document ;
592
- try {
593
- document = parse ( params . query ) ;
594
- } catch ( err ) {
595
- return { errors : [ err ] } ;
596
- }
596
+ if ( ! result ) {
597
+ let document ;
598
+ try {
599
+ document = parse ( params . query ) ;
600
+ } catch ( err ) {
601
+ return { errors : [ err ] } ;
602
+ }
603
+
604
+ const validationErrors = validate ( schema , document ) ;
605
+ if ( validationErrors . length ) {
606
+ return { errors : validationErrors } ;
607
+ }
597
608
598
- const validationErrors = validate ( schema , document ) ;
599
- if ( validationErrors . length ) {
600
- return { errors : validationErrors } ;
609
+ if ( isSubscriptionOperation ( document , params . operationName ) ) {
610
+ result = await customSubscribe ( {
611
+ document,
612
+ schema,
613
+ variableValues : params . variables ,
614
+ contextValue : context ,
615
+ } ) ;
616
+ } else {
617
+ result = await customExecute ( {
618
+ document,
619
+ schema,
620
+ variableValues : params . variables ,
621
+ contextValue : context ,
622
+ } ) ;
623
+ }
601
624
}
602
625
603
- let result ;
604
- if ( isSubscriptionOperation ( document , params . operationName ) ) {
605
- result = await customSubscribe ( {
606
- document,
607
- schema,
608
- variableValues : params . variables ,
609
- contextValue : context ,
610
- } ) ;
611
- } else {
612
- result = await customExecute ( {
613
- document,
614
- schema,
615
- variableValues : params . variables ,
616
- contextValue : context ,
617
- } ) ;
626
+ if ( ! result ) {
627
+ // should never happen
628
+ throw new Error ( 'Result not available' ) ;
618
629
}
619
630
620
631
for ( const doneFn of doneFns ) {
0 commit comments