@@ -11,13 +11,14 @@ import {
1111 OnParseHook ,
1212 OnResolverCalledHook ,
1313 OnSubscribeHook ,
14- OnSubscribeResultResult ,
1514 OnValidateHook ,
1615 Plugin ,
1716 SubscribeResultHook ,
1817 TypedSubscriptionArgs ,
1918 TypedExecutionArgs ,
2019 SubscribeFunction ,
20+ OnSubscribeResultResultOnNextHook ,
21+ OnSubscribeResultResultOnEndHook ,
2122} from '@envelop/types' ;
2223import isAsyncIterable from 'graphql/jsutils/isAsyncIterable' ;
2324import {
@@ -313,8 +314,8 @@ export function createEnvelopOrchestrator<PluginsContext = any>(plugins: Plugin[
313314 contextValue : context ,
314315 } ) ;
315316
316- const onNextHandler : Exclude < OnSubscribeResultResult [ 'onNext' ] , void > [ ] = [ ] ;
317- const onEndHandler : Exclude < OnSubscribeResultResult [ 'onEnd' ] , void > [ ] = [ ] ;
317+ const onNextHandler : OnSubscribeResultResultOnNextHook [ ] = [ ] ;
318+ const onEndHandler : OnSubscribeResultResultOnEndHook [ ] = [ ] ;
318319
319320 for ( const afterCb of afterCalls ) {
320321 const hookResult = afterCb ( {
@@ -333,22 +334,20 @@ export function createEnvelopOrchestrator<PluginsContext = any>(plugins: Plugin[
333334 }
334335 }
335336
336- if ( isAsyncIterable ( result ) ) {
337- if ( onNextHandler . length ) {
338- result = mapAsyncIterator ( result , async result => {
339- for ( const onNext of onNextHandler ) {
340- await onNext ( { result, setResult : newResult => ( result = newResult ) } ) ;
341- }
342- return result ;
343- } ) ;
344- }
345- if ( onEndHandler . length ) {
346- result = finalAsyncIterator ( result , ( ) => {
347- for ( const onEnd of onEndHandler ) {
348- onEnd ( ) ;
349- }
350- } ) ;
351- }
337+ if ( onNextHandler . length && isAsyncIterable ( result ) ) {
338+ result = mapAsyncIterator ( result , async result => {
339+ for ( const onNext of onNextHandler ) {
340+ await onNext ( { result, setResult : newResult => ( result = newResult ) } ) ;
341+ }
342+ return result ;
343+ } ) ;
344+ }
345+ if ( onEndHandler . length && isAsyncIterable ( result ) ) {
346+ result = finalAsyncIterator ( result , ( ) => {
347+ for ( const onEnd of onEndHandler ) {
348+ onEnd ( ) ;
349+ }
350+ } ) ;
352351 }
353352 return result ;
354353 } ) ;
0 commit comments