-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useSubscription has no way to re-connect after error #11304
Comments
Hi @objectiveSee 👋🏻 there are several different protocols that can handle GraphQL subscriptions, some of which are handled by modules we officially support. AWS AppSync packages are provided by a third party, however. The core Apollo Client API itself is not opinionated about how to handle Websockets connections, so I recommend looking at the |
@bignimbus do you have any perspective on this from Apollo's standpoint? I am curious how Apollo client handles re-connecting the underlying socket(s) that support the subscription. Does any link you have in mind handle this or is there additional code needed to support reconnecting? I am looking for alternatives in case AppSync doesn't work. It appear that the topic of re-connecting subscriptions is not discussed a lot. |
We'd like to make the experience around reconnecting more clear for users while accounting for the fact that different protocols/libraries will expose different and sometimes not completely analogous interfaces. Expect to see some improvements to the developer experience along these lines in future releases, but we have no concrete plans yet. |
The action could be simply be a "hard refresh" and restart the subscription, independent of the underlying protocol or library. Just like const { reconnect } = useSubscription(
onUserUpdatedSubscription,
{
variables: { id: userId },
onError: (error: ApolloError) => {
if (error === 'something specific') {
reconnect()
}
}
}
); Maybe it should be called |
I think what I would like to achieve is what the To quote the docs:
So More background info on my use caseWhat I'm implementing is a Subscription not based on WebSockets, but HTTP multipart requests, like documented here. This is handled nicely by Apollo Client, but I have to implemented this manually in my NextJS backend. Maybe I'll open source it someday. The thing is, when hosting on Vercel, the HTTP request will timeout after a maximum of 5 minutes on the Pro plan. If this happens, I'll need to resubscribe. I still have to determine if this errors or completes the subscription, but I would then like to simply resubscribe using a new HTTP request. Once I've figured this all out I'll make sure to update here. |
Thank you for the response @jamiter. I agree that adding a reconnect property to the hook would be really helpful. What would it take to get this added into the Apollo library? In the meantime, I wrote a custom hook that handles the reconnect logic through the skip hack that I mentioned. I added the ability to automatically reconnect as well as exposing a reconnect function. Here is the code for anyone who is interested. Separately, I am dealing with an issue where the websocket implementation that I am using does not support the onComplete callback which is causing its own issues 🤯
|
Sadly I just recreate instance of apollo client for reconnect. |
This will be added in 3.11 with #11927 |
Version 3.11 has been released with this feature. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I am testing my app when the internet is bad. My subscription fails and I get an error, but there is no function exported by the subscription hook that let's me retry the connection. Similar to the refetch property in
useQuery
. Currently, I am unable to have my application reconnect the subscription once it has failed. This seems to be a pretty major oversight in how subscriptions work, so hoping that there's a workaround.Is there some way to trigger a re-subscription attempt?
I am using:
The text was updated successfully, but these errors were encountered: