I use graphql-ws
to subscribe to GraphQL events. I use Observable interface to listen to the events. using error
callback we can detect that subscription is failed to start, But there is no way to detect that it’s successfully started
next
happens when we get an event, But I would like to wrap the Observable
with a Promise
and await for it to start subscription
And while the promise is not resolved, I want to show a progress bar. I can reject the promise in the error
but I couldn’t find anyway to resolve
it when server returns response 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(),
}),
);
}