Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rootValue: rootValue || this._rootValue,
schema: this._schema,
subscribeFieldResolver: subscribeFieldResolver || this._subscribeFieldResolver,
};
try {
const subscribeResult = await this._subscribe(subscribeArgs);
if (isAsyncIterable(subscribeResult)) {
forAwaitEach(subscribeResult, async ({ data, errors }: ExecutionResult) => {
const resolvedResult = await subscriberResolver({ data, errors });
this._eventEmitter.emit(hash, resolvedResult);
});
}
const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, hash);
return eventAsyncIterator.getIterator();
} catch (error) {
return Promise.reject(error);
}
}
}
): Promise> {
if (!this._isSocketOpen()) {
return Promise.reject(new Error("@graphql-box/websocket-manager expected the websocket to be open."));
}
try {
this._websocket.send(
JSON.stringify({
context: WebsocketManager._getMessageContext(context),
subscription: request,
subscriptionID: hash,
}),
);
this._subscriptions.set(hash, subscriberResolver);
const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, hash);
return eventAsyncIterator.getIterator();
} catch (error) {
return Promise.reject(error);
}
}
private async _subscribe(
request: string,
options: RequestOptions,
context: RequestContext,
): Promise> {
try {
this._worker.postMessage({
context: WorkerClient._getMessageContext(context),
method: SUBSCRIBE,
options,
request,
type: GRAPHQL_BOX,
});
const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, context.boxID);
return eventAsyncIterator.getIterator();
} catch (error) {
return Promise.reject(error);
}
}
}