@@ -139,9 +139,7 @@ export interface ExecutionResult<
139
139
> {
140
140
errors ?: ReadonlyArray < GraphQLError > ;
141
141
data ?: TData | null ;
142
- hasNext ?: boolean ;
143
142
extensions ?: TExtensions ;
144
- incremental ?: ReadonlyArray < IncrementalResult > ;
145
143
}
146
144
147
145
export interface FormattedExecutionResult <
@@ -155,23 +153,17 @@ export interface FormattedExecutionResult<
155
153
incremental ?: ReadonlyArray < IncrementalResult > ;
156
154
}
157
155
158
- export interface SubsequentExecutionResult < TExtensions = ObjMap < unknown > > {
156
+ export interface AsyncExecutionResult {
159
157
hasNext ?: boolean ;
160
- extensions ?: TExtensions ;
161
158
incremental ?: ReadonlyArray < IncrementalResult > ;
162
159
}
163
160
164
- export type AsyncExecutionResult = ExecutionResult | SubsequentExecutionResult ;
165
-
166
161
export interface IncrementalDeferResult <
167
162
TData = ObjMap < unknown > ,
168
163
TExtensions = ObjMap < unknown > ,
169
- > {
170
- errors ?: ReadonlyArray < GraphQLError > ;
171
- data ?: TData | null ;
164
+ > extends ExecutionResult < TData , TExtensions > {
172
165
path ?: ReadonlyArray < string | number > ;
173
166
label ?: string ;
174
- extensions ?: TExtensions ;
175
167
}
176
168
177
169
export interface IncrementalStreamResult <
@@ -1362,7 +1354,8 @@ export const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown> =
1362
1354
export function subscribe (
1363
1355
args : ExecutionArgs ,
1364
1356
) : PromiseOrValue <
1365
- AsyncGenerator < ExecutionResult , void , void > | ExecutionResult
1357
+ | AsyncGenerator < ExecutionResult | AsyncExecutionResult , void , void >
1358
+ | ExecutionResult
1366
1359
> {
1367
1360
// If a valid execution context cannot be created due to incorrect arguments,
1368
1361
// a "Response" with only errors is returned.
@@ -1384,11 +1377,17 @@ export function subscribe(
1384
1377
return mapSourceToResponse ( exeContext , resultOrStream ) ;
1385
1378
}
1386
1379
1380
+ // eslint-disable-next-line @typescript-eslint/require-await
1381
+ async function * singleElementAsyncIterable < T > ( element : T ) {
1382
+ yield element ;
1383
+ }
1384
+
1387
1385
function mapSourceToResponse (
1388
1386
exeContext : ExecutionContext ,
1389
1387
resultOrStream : ExecutionResult | AsyncIterable < unknown > ,
1390
1388
) : PromiseOrValue <
1391
- AsyncGenerator < ExecutionResult , void , void > | ExecutionResult
1389
+ | AsyncGenerator < ExecutionResult | AsyncExecutionResult , void , void >
1390
+ | ExecutionResult
1392
1391
> {
1393
1392
if ( ! isAsyncIterable ( resultOrStream ) ) {
1394
1393
return resultOrStream ;
@@ -1400,10 +1399,16 @@ function mapSourceToResponse(
1400
1399
// the GraphQL specification. The `execute` function provides the
1401
1400
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
1402
1401
// "ExecuteQuery" algorithm, for which `execute` is also used.
1403
- return flattenAsyncIterable < ExecutionResult , AsyncExecutionResult > (
1404
- mapAsyncIterable ( resultOrStream , ( payload : unknown ) =>
1405
- executeImpl ( buildPerEventExecutionContext ( exeContext , payload ) ) ,
1406
- ) ,
1402
+ return flattenAsyncIterable < ExecutionResult | AsyncExecutionResult > (
1403
+ mapAsyncIterable ( resultOrStream , async ( payload : unknown ) => {
1404
+ const result = await executeImpl (
1405
+ buildPerEventExecutionContext ( exeContext , payload ) ,
1406
+ ) ;
1407
+ if ( isAsyncIterable ( result ) ) {
1408
+ return result ;
1409
+ }
1410
+ return singleElementAsyncIterable ( result ) ;
1411
+ } ) ,
1407
1412
) ;
1408
1413
}
1409
1414
@@ -1874,8 +1879,8 @@ function yieldSubsequentPayloads(
1874
1879
_hasReturnedInitialResult = true ;
1875
1880
return Promise . resolve ( {
1876
1881
value : {
1877
- ...initialResult ,
1878
1882
hasNext : true ,
1883
+ incremental : [ initialResult ] ,
1879
1884
} ,
1880
1885
done : false ,
1881
1886
} ) ;
0 commit comments