@@ -193,6 +193,22 @@ async function complete(document: DocumentNode, rootValue: unknown = {}) {
193
193
return result ;
194
194
}
195
195
196
+ async function completeAsync ( document : DocumentNode , numCalls : number ) {
197
+ const schema = new GraphQLSchema ( { query } ) ;
198
+
199
+ const result = await execute ( { schema, document, rootValue : { } } ) ;
200
+
201
+ invariant ( isAsyncIterable ( result ) ) ;
202
+
203
+ const iterator = result [ Symbol . asyncIterator ] ( ) ;
204
+
205
+ const promises = [ ] ;
206
+ for ( let i = 0 ; i < numCalls ; i ++ ) {
207
+ promises . push ( iterator . next ( ) ) ;
208
+ }
209
+ return Promise . all ( promises ) ;
210
+ }
211
+
196
212
describe ( 'Execute: stream directive' , ( ) => {
197
213
it ( 'Can stream a list field' , async ( ) => {
198
214
const document = parse ( '{ scalarList @stream(initialCount: 1) }' ) ;
@@ -613,6 +629,58 @@ describe('Execute: stream directive', () => {
613
629
} ,
614
630
} ) ;
615
631
} ) ;
632
+ it ( 'Can handle concurrent calls to .next() without waiting' , async ( ) => {
633
+ const document = parse ( `
634
+ query {
635
+ asyncIterableList @stream(initialCount: 2) {
636
+ name
637
+ id
638
+ }
639
+ }
640
+ ` ) ;
641
+ const result = await completeAsync ( document , 4 ) ;
642
+ expectJSON ( result ) . toDeepEqual ( [
643
+ {
644
+ done : false ,
645
+ value : {
646
+ data : {
647
+ asyncIterableList : [
648
+ {
649
+ name : 'Luke' ,
650
+ id : '1' ,
651
+ } ,
652
+ {
653
+ name : 'Han' ,
654
+ id : '2' ,
655
+ } ,
656
+ ] ,
657
+ } ,
658
+ hasNext : true ,
659
+ } ,
660
+ } ,
661
+ {
662
+ done : false ,
663
+ value : {
664
+ data : {
665
+ name : 'Leia' ,
666
+ id : '3' ,
667
+ } ,
668
+ path : [ 'asyncIterableList' , 2 ] ,
669
+ hasNext : true ,
670
+ } ,
671
+ } ,
672
+ {
673
+ done : false ,
674
+ value : {
675
+ hasNext : false ,
676
+ } ,
677
+ } ,
678
+ {
679
+ done : true ,
680
+ value : undefined ,
681
+ } ,
682
+ ] ) ;
683
+ } ) ;
616
684
it ( 'Handles error thrown in async iterable before initialCount is reached' , async ( ) => {
617
685
const document = parse ( `
618
686
query {
0 commit comments