From f28863cec6b57ea159be0a1fc7d6afa07459dffc Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Sun, 31 Dec 2023 09:38:24 +0530 Subject: [PATCH] Update execute.ts issue-:#4001 --- src/execution/execute.ts | 44 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/execution/execute.ts b/src/execution/execute.ts index baf6b41ea1..5e6c8dd95d 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -1781,18 +1781,48 @@ export function createSourceEventStream( function createSourceEventStreamImpl( exeContext: ExecutionContext, ): PromiseOrValue | ExecutionResult> { - try { - const eventStream = executeSubscription(exeContext); - if (isPromise(eventStream)) { - return eventStream.then(undefined, (error) => ({ errors: [error] })); +try { + + const eventStream = executeSubscription(exeContext); + + if (isPromise(eventStream)) { + // Handle promise errors + return eventStream.then( + data => ({ data }), + error => ({ errors: [error] }) + ); + } + + const wrappedStream = { + async *[Symbol.asyncIterator]() { + try { + yield* eventStream; + } catch (error) { + yield { errors: [error] }; + } } + }; - return eventStream; - } catch (error) { - return { errors: [error] }; + return wrappedStream; + +} catch (error) { + // Handle sync errors + return { errors: [error] }; +} + +function resolve(payload) { + if (payload.errors) { + throw payload.errors[0]; + } else { + return payload.data; } } +const stream = executeSubscription(); +mapAsyncIterable(stream, resolve); + +} + function executeSubscription( exeContext: ExecutionContext, ): PromiseOrValue> {