@@ -131,6 +131,21 @@ async function complete(document) {
131
131
return result ;
132
132
}
133
133
134
+ async function completeAsync ( document , numCalls ) {
135
+ const schema = new GraphQLSchema ( { query } ) ;
136
+
137
+ const result = await execute ( { schema, document, rootValue : { } } ) ;
138
+
139
+ if ( isAsyncIterable ( result ) ) {
140
+ const promises = [ ] ;
141
+ for ( let i = 0 ; i < numCalls ; i ++ ) {
142
+ promises . push ( result . next ( ) ) ;
143
+ }
144
+ return Promise . all ( promises ) ;
145
+ }
146
+ return result ;
147
+ }
148
+
134
149
describe ( 'Execute: stream directive' , ( ) => {
135
150
it ( 'Can stream a list field' , async ( ) => {
136
151
const document = parse ( '{ scalarList @stream(initialCount: 1) }' ) ;
@@ -398,22 +413,8 @@ describe('Execute: stream directive', () => {
398
413
}
399
414
}
400
415
` ) ;
401
- const schema = new GraphQLSchema ( { query } ) ;
402
-
403
- const result = await execute ( { schema, document, rootValue : { } } ) ;
404
-
405
- const results = [ ] ;
406
- if ( isAsyncIterable ( result ) ) {
407
- const asyncResults = await Promise . all ( [
408
- result . next ( ) ,
409
- result . next ( ) ,
410
- result . next ( ) ,
411
- result . next ( ) ,
412
- ] ) ;
413
- results . push ( ...asyncResults ) ;
414
- }
415
-
416
- expect ( results ) . to . deep . equal ( [
416
+ const result = await completeAsync ( document , 4 ) ;
417
+ expect ( result ) . to . deep . equal ( [
417
418
{
418
419
done : false ,
419
420
value : {
0 commit comments