-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question]: Subscriptions don't close and don't receive data #95
Comments
This doesn't seem like the correct solution but it is now properly closing subscriptions. Can someone confirm or provide a correct solution?
|
This is the solution we're using, I clipped out our authentication and error handling. I haven't used Observables enough to say if it is equivalent to the solution you are using.
|
@AnotherHermit Thanks for the example of how you're handling it. It worked for me as well. I did have some issues with the typings that said that This is basically what I'm thinking about. function getSubscribeFn(client: SubscriptionClient) {
return (operation: ConcreteBatch, variables: Variables) => {
const query = operation.text
if (!query) return
const request = client.request({
query,
variables,
operationName: operation.name,
})
return {
subscribe: observer => {
const subscription = request.subscribe(observer)
observer.start(subscription)
},
dispose: () => {
client.unsubscribeAll()
client.close()
},
}
}
} |
I've followed an article and ended up with this: import { execute } from 'apollo-link';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import { WebSocketLink } from 'apollo-link-ws';
const subscriptionClient = new SubscriptionClient('ws://localhost:4000/graphql', {
lazy: true,
reconnect: true,
});
const webSocketLink = new WebSocketLink(subscriptionClient);
const subscribeFn = (operation, variables) =>
execute(webSocketLink, {
query: operation.text,
variables,
}); Haven't deployed to production yet, but it seems to work well. |
I'm running into issues using
subscriptions-transport-ws
with this. The subscriptions never close and don't seem to be getting data.It would be nice to export a
subscribeFn
to properly handle subscriptions.It could easily just accept a
SubscriptionClient
instance.The text was updated successfully, but these errors were encountered: