My approach involves utilizing graphql-ws
for subscribing to GraphQL events. I rely on the Observable interface to listen to these events. Although I can use the error
callback to identify when a subscription fails to start, it is challenging to determine if it has successfully started.
When an event occurs, the next
function is triggered. However, I am interested in encapsulating the Observable
within a Promise
and await its commencement before proceeding with the subscription.
While awaiting resolution of the promise, I aim to display a progress bar. Although I can reject the promise using the error
, I am struggling to find a method to resolve
it once the server responds to the subscription request.
function toObservable(operation) {
return new Observable((observer) =>
client.subscribe(operation, {
next: (data) => observer.next(data),
error: (err) => observer.error(err),
complete: () => observer.complete(),
}),
);
}