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