Better documentation around AppSync Subscription reconnection logic
Is your feature request related to a problem? Please describe. There is no documentation for how to resubscribe an AppSync subscription if connection failure is happening
Describe the solution you'd like Ideally, I do not want to handle this myself and just let the framework handle the reconnection.
Describe alternatives you've considered Write code that handles the exponential backoff
Additional context This is how I tried to do it, but I do not get a successful reconnect. Obviously there is no backoff implemented yet..
useEffect(() => {
let subscription;
const observable = API.graphql(
graphqlOperation(onCreateChild, {
owner: user.sub
})
);
const subscriptionSettings = {
error: e => {
subscription.unsubscribe();
subscription = null;
subscription = observable.subscribe(subscriptionSettings);
console.log("onCreateChild", JSON.stringify(e));
},
next: childData => {
console.log(childData)
}
};
subscription = observable.subscribe(subscriptionSettings);
return () => {
if (subscription) {
console.log("unsubscribe");
subscription.unsubscribe();
}
};
}, [user.sub]);
What is the best way to handle this?
I just stumbled upon this issue as well and wondering how can I do the same. I need the onCreate Subscription to update the information for the auto-refresh functionality that is needed in my app.
This is my first GraphQL subscription with AppSync/Amplify and I'll be disappointed if this doesn't work as expected. I certainly do not expect to write code to maintain web socket connections.
Is any workaround available until this is identified as an issue or a fix is available?
By the way, I'm using the GraphQL client and not the SDK.
Hey @ahansson89 👋 apologies for the delay here. Since this issue speaks to the documentation specifically, I'm going to transfer it to the docs repo so that we can add examples that help to re-establish connections for GraphQL subscriptions.
Hi we've added the documentation here: https://docs.amplify.aws/lib/graphqlapi/subscribe-data/q/platform/js/#connection-issues-and-automated-reconnection