@@ -244,6 +244,22 @@ async function complete(document: DocumentNode, rootValue: unknown = {}) {
244
244
return result ;
245
245
}
246
246
247
+ async function completeAsync ( document : DocumentNode , numCalls : number ) {
248
+ const schema = new GraphQLSchema ( { query } ) ;
249
+
250
+ const result = await execute ( { schema, document, rootValue : { } } ) ;
251
+
252
+ assert ( isAsyncIterable ( result ) ) ;
253
+
254
+ const iterator = result [ Symbol . asyncIterator ] ( ) ;
255
+
256
+ const promises = [ ] ;
257
+ for ( let i = 0 ; i < numCalls ; i ++ ) {
258
+ promises . push ( iterator . next ( ) ) ;
259
+ }
260
+ return Promise . all ( promises ) ;
261
+ }
262
+
247
263
describe ( 'Execute: stream directive' , ( ) => {
248
264
it ( 'Can stream a list field' , async ( ) => {
249
265
const document = parse ( '{ scalarList @stream(initialCount: 1) }' ) ;
@@ -684,6 +700,60 @@ describe('Execute: stream directive', () => {
684
700
} ,
685
701
} ) ;
686
702
} ) ;
703
+ it ( 'Can handle concurrent calls to .next() without waiting' , async ( ) => {
704
+ const document = parse ( `
705
+ query {
706
+ asyncIterableList @stream(initialCount: 2) {
707
+ name
708
+ id
709
+ }
710
+ }
711
+ ` ) ;
712
+ const result = await completeAsync ( document , 4 ) ;
713
+ expectJSON ( result ) . toDeepEqual ( [
714
+ {
715
+ done : false ,
716
+ value : {
717
+ data : {
718
+ asyncIterableList : [
719
+ {
720
+ name : 'Luke' ,
721
+ id : '1' ,
722
+ } ,
723
+ {
724
+ name : 'Han' ,
725
+ id : '2' ,
726
+ } ,
727
+ ] ,
728
+ } ,
729
+ hasNext : true ,
730
+ } ,
731
+ } ,
732
+ {
733
+ done : false ,
734
+ value : {
735
+ data : [
736
+ {
737
+ name : 'Leia' ,
738
+ id : '3' ,
739
+ } ,
740
+ ] ,
741
+ path : [ 'asyncIterableList' , 2 ] ,
742
+ hasNext : true ,
743
+ } ,
744
+ } ,
745
+ {
746
+ done : false ,
747
+ value : {
748
+ hasNext : false ,
749
+ } ,
750
+ } ,
751
+ {
752
+ done : true ,
753
+ value : undefined ,
754
+ } ,
755
+ ] ) ;
756
+ } ) ;
687
757
it ( 'Handles error thrown in async iterable before initialCount is reached' , async ( ) => {
688
758
const document = parse ( `
689
759
query {
0 commit comments