@@ -2,6 +2,9 @@ import { expect } from 'chai';
2
2
import { describe , it } from 'mocha' ;
3
3
4
4
import { parse } from '../../language/parser' ;
5
+ import { GraphQLList , GraphQLObjectType } from '../../type/definition' ;
6
+ import { GraphQLString } from '../../type/scalars' ;
7
+ import { GraphQLSchema } from '../../type/schema' ;
5
8
6
9
import { buildSchema } from '../../utilities/buildASTSchema' ;
7
10
@@ -73,6 +76,38 @@ describe('Execute: Accepts async iterables as list value', () => {
73
76
} ) ;
74
77
}
75
78
79
+ function completeObjectList ( resolve ) {
80
+ const schema = new GraphQLSchema ( {
81
+ query : new GraphQLObjectType ( {
82
+ name : 'Query' ,
83
+ fields : {
84
+ listField : {
85
+ resolve : async function * listField ( ) {
86
+ yield await { index : 0 } ;
87
+ yield await { index : 1 } ;
88
+ yield await { index : 2 } ;
89
+ } ,
90
+ type : new GraphQLList (
91
+ new GraphQLObjectType ( {
92
+ name : 'ObjectWrapper' ,
93
+ fields : {
94
+ index : {
95
+ type : GraphQLString ,
96
+ resolve,
97
+ } ,
98
+ } ,
99
+ } ) ,
100
+ ) ,
101
+ } ,
102
+ } ,
103
+ } ) ,
104
+ } ) ;
105
+ return execute ( {
106
+ schema,
107
+ document : parse ( '{ listField { index } }' ) ,
108
+ } ) ;
109
+ }
110
+
76
111
it ( 'Accepts an AsyncGenerator function as a List value' , async ( ) => {
77
112
async function * listField ( ) {
78
113
yield await 'two' ;
@@ -121,6 +156,34 @@ describe('Execute: Accepts async iterables as list value', () => {
121
156
] ,
122
157
} ) ;
123
158
} ) ;
159
+
160
+ it ( 'Handles promises from `completeValue` in AsyncIterables' , async ( ) => {
161
+ expect (
162
+ await completeObjectList ( ( { index } ) => Promise . resolve ( index ) ) ,
163
+ ) . to . deep . equal ( {
164
+ data : { listField : [ { index : '0' } , { index : '1' } , { index : '2' } ] } ,
165
+ } ) ;
166
+ } ) ;
167
+
168
+ it ( 'Handles rejected promises from `completeValue` in AsyncIterables' , async ( ) => {
169
+ expect (
170
+ await completeObjectList ( ( { index } ) => {
171
+ if ( index === 2 ) {
172
+ return Promise . reject ( new Error ( 'bad' ) ) ;
173
+ }
174
+ return Promise . resolve ( index ) ;
175
+ } ) ,
176
+ ) . to . deep . equal ( {
177
+ data : { listField : [ { index : '0' } , { index : '1' } , { index : null } ] } ,
178
+ errors : [
179
+ {
180
+ message : 'bad' ,
181
+ locations : [ { line : 1 , column : 15 } ] ,
182
+ path : [ 'listField' , 2 , 'index' ] ,
183
+ } ,
184
+ ] ,
185
+ } ) ;
186
+ } ) ;
124
187
} ) ;
125
188
126
189
describe ( 'Execute: Handles list nullability' , ( ) => {
0 commit comments