@@ -190,6 +190,22 @@ async function complete(
190
190
return result ;
191
191
}
192
192
193
+ async function completeAsync ( document : DocumentNode , numCalls : number ) {
194
+ const schema = new GraphQLSchema ( { query, enableDeferStream : true } ) ;
195
+
196
+ const result = await execute ( { schema, document, rootValue : { } } ) ;
197
+
198
+ invariant ( isAsyncIterable ( result ) ) ;
199
+
200
+ const iterator = result [ Symbol . asyncIterator ] ( ) ;
201
+
202
+ const promises = [ ] ;
203
+ for ( let i = 0 ; i < numCalls ; i ++ ) {
204
+ promises . push ( iterator . next ( ) ) ;
205
+ }
206
+ return Promise . all ( promises ) ;
207
+ }
208
+
193
209
describe ( 'Execute: stream directive' , ( ) => {
194
210
it ( 'Should ignore @stream if not enabled' , async ( ) => {
195
211
const document = parse ( '{ scalarList @stream(initialCount: 1) }' ) ;
@@ -597,6 +613,58 @@ describe('Execute: stream directive', () => {
597
613
} ,
598
614
} ) ;
599
615
} ) ;
616
+ it ( 'Can handle concurrent calls to .next() without waiting' , async ( ) => {
617
+ const document = parse ( `
618
+ query {
619
+ asyncIterableList @stream(initialCount: 2) {
620
+ name
621
+ id
622
+ }
623
+ }
624
+ ` ) ;
625
+ const result = await completeAsync ( document , 4 ) ;
626
+ expectJSON ( result ) . toDeepEqual ( [
627
+ {
628
+ done : false ,
629
+ value : {
630
+ data : {
631
+ asyncIterableList : [
632
+ {
633
+ name : 'Luke' ,
634
+ id : '1' ,
635
+ } ,
636
+ {
637
+ name : 'Han' ,
638
+ id : '2' ,
639
+ } ,
640
+ ] ,
641
+ } ,
642
+ hasNext : true ,
643
+ } ,
644
+ } ,
645
+ {
646
+ done : false ,
647
+ value : {
648
+ data : {
649
+ name : 'Leia' ,
650
+ id : '3' ,
651
+ } ,
652
+ path : [ 'asyncIterableList' , 2 ] ,
653
+ hasNext : true ,
654
+ } ,
655
+ } ,
656
+ {
657
+ done : false ,
658
+ value : {
659
+ hasNext : false ,
660
+ } ,
661
+ } ,
662
+ {
663
+ done : true ,
664
+ value : undefined ,
665
+ } ,
666
+ ] ) ;
667
+ } ) ;
600
668
it ( 'Handles error thrown in async iterable before initialCount is reached' , async ( ) => {
601
669
const document = parse ( `
602
670
query {
0 commit comments