@@ -151,19 +151,17 @@ export interface FormattedExecutionResult<
151
151
extensions ?: TExtensions ;
152
152
}
153
153
154
- export type ExperimentalExecuteIncrementallyResults <
154
+ export interface ExperimentalIncrementalExecutionResults <
155
155
TData = ObjMap < unknown > ,
156
156
TExtensions = ObjMap < unknown > ,
157
- > =
158
- | { singleResult : ExecutionResult < TData , TExtensions > }
159
- | {
160
- initialResult : InitialIncrementalExecutionResult < TData , TExtensions > ;
161
- subsequentResults : AsyncGenerator <
162
- SubsequentIncrementalExecutionResult < TData , TExtensions > ,
163
- void ,
164
- void
165
- > ;
166
- } ;
157
+ > {
158
+ initialResult : InitialIncrementalExecutionResult < TData , TExtensions > ;
159
+ subsequentResults : AsyncGenerator <
160
+ SubsequentIncrementalExecutionResult < TData , TExtensions > ,
161
+ void ,
162
+ void
163
+ > ;
164
+ }
167
165
168
166
export interface InitialIncrementalExecutionResult <
169
167
TData = ObjMap < unknown > ,
@@ -287,19 +285,19 @@ const UNEXPECTED_MULTIPLE_PAYLOADS =
287
285
export function execute ( args : ExecutionArgs ) : PromiseOrValue < ExecutionResult > {
288
286
const result = experimentalExecuteIncrementally ( args ) ;
289
287
if ( ! isPromise ( result ) ) {
290
- if ( 'singleResult ' in result ) {
291
- return result . singleResult ;
288
+ if ( 'initialResult ' in result ) {
289
+ throw new Error ( UNEXPECTED_MULTIPLE_PAYLOADS ) ;
292
290
}
293
- throw new Error ( UNEXPECTED_MULTIPLE_PAYLOADS ) ;
291
+ return result ;
294
292
}
295
293
296
294
return result . then ( ( incrementalResult ) => {
297
- if ( 'singleResult' in incrementalResult ) {
298
- return incrementalResult . singleResult ;
295
+ if ( 'initialResult' in incrementalResult ) {
296
+ return {
297
+ errors : [ new GraphQLError ( UNEXPECTED_MULTIPLE_PAYLOADS ) ] ,
298
+ } ;
299
299
}
300
- return {
301
- errors : [ new GraphQLError ( UNEXPECTED_MULTIPLE_PAYLOADS ) ] ,
302
- } ;
300
+ return incrementalResult ;
303
301
} ) ;
304
302
}
305
303
@@ -308,31 +306,31 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
308
306
* including `@defer` and `@stream` as proposed in
309
307
* https://github.com/graphql/graphql-spec/pull/742
310
308
*
311
- * This function returns a Promise of an ExperimentalExecuteIncrementallyResults
312
- * object. This object either contains a single ExecutionResult as
313
- * `singleResult`, or an `initialResult` and a stream of `subsequentResults`.
309
+ * This function returns a Promise of an ExperimentalIncrementalExecutionResults
310
+ * object. This object either consists of a single ExecutionResult, or an
311
+ * object containing an `initialResult` and a stream of `subsequentResults`.
314
312
*
315
313
* If the arguments to this function do not result in a legal execution context,
316
314
* a GraphQLError will be thrown immediately explaining the invalid input.
317
315
*/
318
316
export function experimentalExecuteIncrementally (
319
317
args : ExecutionArgs ,
320
- ) : PromiseOrValue < ExperimentalExecuteIncrementallyResults > {
318
+ ) : PromiseOrValue < ExecutionResult | ExperimentalIncrementalExecutionResults > {
321
319
// If a valid execution context cannot be created due to incorrect arguments,
322
320
// a "Response" with only errors is returned.
323
321
const exeContext = buildExecutionContext ( args ) ;
324
322
325
323
// Return early errors if execution context failed.
326
324
if ( ! ( 'schema' in exeContext ) ) {
327
- return { singleResult : { errors : exeContext } } ;
325
+ return { errors : exeContext } ;
328
326
}
329
327
330
328
return executeImpl ( exeContext ) ;
331
329
}
332
330
333
331
function executeImpl (
334
332
exeContext : ExecutionContext ,
335
- ) : PromiseOrValue < ExperimentalExecuteIncrementallyResults > {
333
+ ) : PromiseOrValue < ExecutionResult | ExperimentalIncrementalExecutionResults > {
336
334
// Return a Promise that will eventually resolve to the data described by
337
335
// The "Response" section of the GraphQL specification.
338
336
//
@@ -359,11 +357,11 @@ function executeImpl(
359
357
subsequentResults : yieldSubsequentPayloads ( exeContext ) ,
360
358
} ;
361
359
}
362
- return { singleResult : initialResult } ;
360
+ return initialResult ;
363
361
} ,
364
362
( error ) => {
365
363
exeContext . errors . push ( error ) ;
366
- return { singleResult : buildResponse ( null , exeContext . errors ) } ;
364
+ return buildResponse ( null , exeContext . errors ) ;
367
365
} ,
368
366
) ;
369
367
}
@@ -377,10 +375,10 @@ function executeImpl(
377
375
subsequentResults : yieldSubsequentPayloads ( exeContext ) ,
378
376
} ;
379
377
}
380
- return { singleResult : initialResult } ;
378
+ return initialResult ;
381
379
} catch ( error ) {
382
380
exeContext . errors . push ( error ) ;
383
- return { singleResult : buildResponse ( null , exeContext . errors ) } ;
381
+ return buildResponse ( null , exeContext . errors ) ;
384
382
}
385
383
}
386
384
@@ -397,7 +395,7 @@ export function executeSync(args: ExecutionArgs): ExecutionResult {
397
395
throw new Error ( 'GraphQL execution failed to complete synchronously.' ) ;
398
396
}
399
397
400
- return result . singleResult ;
398
+ return result ;
401
399
}
402
400
403
401
/**
@@ -1586,7 +1584,9 @@ export function experimentalSubscribeIncrementally(
1586
1584
}
1587
1585
1588
1586
async function * ensureAsyncIterable (
1589
- someExecutionResult : ExperimentalExecuteIncrementallyResults ,
1587
+ someExecutionResult :
1588
+ | ExecutionResult
1589
+ | ExperimentalIncrementalExecutionResults ,
1590
1590
) : AsyncGenerator <
1591
1591
| ExecutionResult
1592
1592
| InitialIncrementalExecutionResult
@@ -1598,7 +1598,7 @@ async function* ensureAsyncIterable(
1598
1598
yield someExecutionResult . initialResult ;
1599
1599
yield * someExecutionResult . subsequentResults ;
1600
1600
} else {
1601
- yield someExecutionResult . singleResult ;
1601
+ yield someExecutionResult ;
1602
1602
}
1603
1603
}
1604
1604
0 commit comments