graphql-js
graphql-js copied to clipboard
Detect subscription successfully started
I think it's not a question, it's a lack of feature which is necessary so please don't close this issue without any reply
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(),
}),
);
}
I have also asked this question at https://stackoverflow.com/questions/77666947/apollo-graphql-detect-subscription-started and https://github.com/enisdenjo/graphql-ws/issues/526