@@ -127,6 +127,9 @@ export interface ValidatedExecutionArgs {
127127 fieldResolver : GraphQLFieldResolver < any , any > ;
128128 typeResolver : GraphQLTypeResolver < any , any > ;
129129 subscribeFieldResolver : GraphQLFieldResolver < any , any > ;
130+ perEventExecutor : (
131+ validatedExecutionArgs : ValidatedExecutionArgs ,
132+ ) => PromiseOrValue < ExecutionResult > ;
130133}
131134
132135export interface ExecutionContext {
@@ -169,6 +172,11 @@ export interface ExecutionArgs {
169172 fieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ;
170173 typeResolver ?: Maybe < GraphQLTypeResolver < any , any > > ;
171174 subscribeFieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ;
175+ perEventExecutor ?: Maybe <
176+ (
177+ validatedExecutionArgs : ValidatedExecutionArgs ,
178+ ) => PromiseOrValue < ExecutionResult >
179+ > ;
172180 /** Additional execution options. */
173181 options ?: {
174182 /** Set the maximum number of errors allowed for coercing (defaults to 50). */
@@ -196,7 +204,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
196204 return { errors : validatedExecutionArgs } ;
197205 }
198206
199- return executeOperation ( validatedExecutionArgs ) ;
207+ return executeQueryOrMutationOrSubscriptionEvent ( validatedExecutionArgs ) ;
200208}
201209
202210/**
@@ -214,7 +222,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
214222 * at which point we still log the error and null the parent field, which
215223 * in this case is the entire response.
216224 */
217- function executeOperation (
225+ function executeQueryOrMutationOrSubscriptionEvent (
218226 validatedExecutionArgs : ValidatedExecutionArgs ,
219227) : PromiseOrValue < ExecutionResult > {
220228 const exeContext : ExecutionContext = {
@@ -313,6 +321,7 @@ export function validateExecutionArgs(
313321 fieldResolver,
314322 typeResolver,
315323 subscribeFieldResolver,
324+ perEventExecutor,
316325 options,
317326 } = args ;
318327
@@ -386,6 +395,7 @@ export function validateExecutionArgs(
386395 fieldResolver : fieldResolver ?? defaultFieldResolver ,
387396 typeResolver : typeResolver ?? defaultTypeResolver ,
388397 subscribeFieldResolver : subscribeFieldResolver ?? defaultFieldResolver ,
398+ perEventExecutor : perEventExecutor ?? executeSubscriptionEvent ,
389399 } ;
390400}
391401
@@ -1388,21 +1398,22 @@ function mapSourceToResponse(
13881398 // For each payload yielded from a subscription, map it over the normal
13891399 // GraphQL `execute` function, with `payload` as the rootValue.
13901400 // This implements the "MapSourceToResponseEvent" algorithm described in
1391- // the GraphQL specification. The `execute` function provides the
1392- // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
1393- // "ExecuteQuery" algorithm, for which `execute` is also used.
1401+ // the GraphQL specification..
13941402 return mapAsyncIterable ( resultOrStream , ( payload : unknown ) => {
13951403 const perEventExecutionArgs : ValidatedExecutionArgs = {
13961404 ...validatedExecutionArgs ,
13971405 rootValue : payload ,
13981406 } ;
1399- // typecast to ExecutionResult, not possible to return
1400- // ExperimentalIncrementalExecutionResults when
1401- // exeContext.operation is 'subscription'.
1402- return executeOperation ( perEventExecutionArgs ) as ExecutionResult ;
1407+ return validatedExecutionArgs . perEventExecutor ( perEventExecutionArgs ) ;
14031408 } ) ;
14041409}
14051410
1411+ export function executeSubscriptionEvent (
1412+ validatedExecutionArgs : ValidatedExecutionArgs ,
1413+ ) : PromiseOrValue < ExecutionResult > {
1414+ return executeQueryOrMutationOrSubscriptionEvent ( validatedExecutionArgs ) ;
1415+ }
1416+
14061417/**
14071418 * Implements the "CreateSourceEventStream" algorithm described in the
14081419 * GraphQL specification, resolving the subscription source event stream.
0 commit comments