Skip to content

Commit 80a60f4

Browse files
committed
consolidate
1 parent 7187e32 commit 80a60f4

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

src/execution/execute.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,13 +2099,6 @@ export function subscribe(
20992099
return mapSourceToResponse(validatedExecutionArgs, resultOrStream);
21002100
}
21012101

2102-
/**
2103-
*
2104-
* For each payload yielded from a subscription, map it over the normal
2105-
* GraphQL `execute` function, with `payload` as the rootValue.
2106-
* This implements the "MapSourceToResponseEvent" algorithm described in
2107-
* the GraphQL specification..
2108-
*/
21092102
function mapSourceToResponse(
21102103
validatedExecutionArgs: ValidatedExecutionArgs,
21112104
resultOrStream: ExecutionResult | AsyncIterable<unknown>,
@@ -2115,28 +2108,25 @@ function mapSourceToResponse(
21152108
}
21162109

21172110
const abortSignal = validatedExecutionArgs.abortSignal;
2118-
if (abortSignal) {
2119-
const promiseCanceller = new PromiseCanceller(abortSignal);
2120-
return mapAsyncIterable(
2121-
promiseCanceller?.cancellableIterable(resultOrStream),
2122-
(payload: unknown) => {
2123-
const perEventExecutionArgs: ValidatedExecutionArgs = {
2124-
...validatedExecutionArgs,
2125-
rootValue: payload,
2126-
};
2127-
return validatedExecutionArgs.perEventExecutor(perEventExecutionArgs);
2128-
},
2129-
() => promiseCanceller.disconnect(),
2130-
);
2131-
}
21322111

2133-
return mapAsyncIterable(resultOrStream, (payload: unknown) => {
2134-
const perEventExecutionArgs: ValidatedExecutionArgs = {
2135-
...validatedExecutionArgs,
2136-
rootValue: payload,
2137-
};
2138-
return validatedExecutionArgs.perEventExecutor(perEventExecutionArgs);
2139-
});
2112+
const promiseCanceller = abortSignal
2113+
? new PromiseCanceller(abortSignal)
2114+
: undefined;
2115+
// For each payload yielded from a subscription, map it over the normal
2116+
// GraphQL `execute` function, with `payload` as the rootValue.
2117+
// This implements the "MapSourceToResponseEvent" algorithm described in
2118+
// the GraphQL specification..
2119+
return mapAsyncIterable(
2120+
promiseCanceller?.cancellableIterable(resultOrStream) ?? resultOrStream,
2121+
(payload: unknown) => {
2122+
const perEventExecutionArgs: ValidatedExecutionArgs = {
2123+
...validatedExecutionArgs,
2124+
rootValue: payload,
2125+
};
2126+
return validatedExecutionArgs.perEventExecutor(perEventExecutionArgs);
2127+
},
2128+
() => promiseCanceller?.disconnect(),
2129+
);
21402130
}
21412131

21422132
export function executeSubscriptionEvent(

0 commit comments

Comments
 (0)