@@ -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
132135/**
@@ -208,6 +211,11 @@ export interface ExecutionArgs {
208211 fieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ;
209212 typeResolver ?: Maybe < GraphQLTypeResolver < any , any > > ;
210213 subscribeFieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ;
214+ perEventExecutor ?: Maybe <
215+ (
216+ validatedExecutionArgs : ValidatedExecutionArgs ,
217+ ) => PromiseOrValue < ExecutionResult >
218+ > ;
211219 /** Additional execution options. */
212220 options ?: {
213221 /** Set the maximum number of errors allowed for coercing (defaults to 50). */
@@ -235,7 +243,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
235243 return { errors : validatedExecutionArgs } ;
236244 }
237245
238- return executeOperation ( validatedExecutionArgs ) ;
246+ return executeQueryOrMutationOrSubscriptionEvent ( validatedExecutionArgs ) ;
239247}
240248
241249/**
@@ -253,7 +261,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
253261 * at which point we still log the error and null the parent field, which
254262 * in this case is the entire response.
255263 */
256- function executeOperation (
264+ function executeQueryOrMutationOrSubscriptionEvent (
257265 validatedExecutionArgs : ValidatedExecutionArgs ,
258266) : PromiseOrValue < ExecutionResult > {
259267 const exeContext : ExecutionContext = {
@@ -352,6 +360,7 @@ export function validateExecutionArgs(
352360 fieldResolver,
353361 typeResolver,
354362 subscribeFieldResolver,
363+ perEventExecutor,
355364 options,
356365 } = args ;
357366
@@ -425,6 +434,7 @@ export function validateExecutionArgs(
425434 fieldResolver : fieldResolver ?? defaultFieldResolver ,
426435 typeResolver : typeResolver ?? defaultTypeResolver ,
427436 subscribeFieldResolver : subscribeFieldResolver ?? defaultFieldResolver ,
437+ perEventExecutor : perEventExecutor ?? executeSubscriptionEvent ,
428438 } ;
429439}
430440
@@ -1419,18 +1429,22 @@ function mapSourceToResponse(
14191429 // For each payload yielded from a subscription, map it over the normal
14201430 // GraphQL `execute` function, with `payload` as the rootValue.
14211431 // This implements the "MapSourceToResponseEvent" algorithm described in
1422- // the GraphQL specification. The `execute` function provides the
1423- // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
1424- // "ExecuteQuery" algorithm, for which `execute` is also used.
1432+ // the GraphQL specification..
14251433 return mapAsyncIterable ( resultOrStream , ( payload : unknown ) => {
14261434 const perEventExecutionArgs : ValidatedExecutionArgs = {
14271435 ...validatedExecutionArgs ,
14281436 rootValue : payload ,
14291437 } ;
1430- return executeOperation ( perEventExecutionArgs ) ;
1438+ return validatedExecutionArgs . perEventExecutor ( perEventExecutionArgs ) ;
14311439 } ) ;
14321440}
14331441
1442+ export function executeSubscriptionEvent (
1443+ validatedExecutionArgs : ValidatedExecutionArgs ,
1444+ ) : PromiseOrValue < ExecutionResult > {
1445+ return executeQueryOrMutationOrSubscriptionEvent ( validatedExecutionArgs ) ;
1446+ }
1447+
14341448/**
14351449 * Implements the "CreateSourceEventStream" algorithm described in the
14361450 * GraphQL specification, resolving the subscription source event stream.
0 commit comments