Comments (8)
Also error message shows "Connection closed", where subscription events are no longer received. Any idea how to re-connect? Currently use useSubscription
and subscribeToMore
.
I believe Amplify Graphql client manages reconnects, not sure if that applies to this sdk also
https://docs.amplify.aws/lib/graphqlapi/subscribe-data/q/platform/js/#using-amplify-graphql-client
On simulator less prone to the subscription closing. But on real device with an .ipa installed, locking the screen / idle for a period of time the subscription does not resusbcribe
from aws-mobile-appsync-sdk-js.
I am also encountering this issue @juanch0x and looks like there's no update for a long time with this SDK. Is there any workaround that you did from your end?
from aws-mobile-appsync-sdk-js.
We found the subscriptions using aws-appsync-subscription-link
on web to be too unreliable to use in production. They seem to work just enough to be dangerous, but we kept hitting this issue as well as #684.
I wanted to stick with Apollo, so I ended up replacing our subscriptions with essentially:
const apolloClient = useApolloClient();
useEffect(() => {
const newRoutineSubscription = API.graphql(
graphqlOperation(SubscribeToNewRoutineBySession, { sessionId })
).subscribe({
next: ({ provider, value }) => {
const routine = value.data.subscribeToNewRoutineBySession;
apolloClient.writeFragment({
id: cacheIdForNode(routine),
fragment: NewRoutineFragment,
fragmentName: 'NewRoutineFragment',
data: routine,
});
},
error: (error) => {
// do something sensible
},
});
return () => newRoutineSubscription.unsubscribe();
}, [sessionId, apolloClient]);
One big caveat is that you'll need to add __typename
s explicitly to your fragments, otherwise the Apollo cache won't know how to handle the subscription data if they're not provided (Apollo adds these automatically when you use useQuery
).
Hope that helps somebody!
from aws-mobile-appsync-sdk-js.
We found the subscriptions using
aws-appsync-subscription-link
on web to be too unreliable to use in production. They seem to work just enough to be dangerous, but we kept hitting this issue as well as #684.I wanted to stick with Apollo, so I ended up replacing our subscriptions with essentially:
const apolloClient = useApolloClient(); useEffect(() => { const newRoutineSubscription = API.graphql( graphqlOperation(SubscribeToNewRoutineBySession, { sessionId }) ).subscribe({ next: ({ provider, value }) => { const routine = value.data.subscribeToNewRoutineBySession; apolloClient.writeFragment({ id: cacheIdForNode(routine), fragment: NewRoutineFragment, fragmentName: 'NewRoutineFragment', data: routine, }); }, error: (error) => { // do something sensible }, }); return () => newRoutineSubscription.unsubscribe(); }, [sessionId, apolloClient]);One big caveat is that you'll need to add
__typename
s explicitly to your fragments, otherwise the Apollo cache won't know how to handle the subscription data if they're not provided (Apollo adds these automatically when you useuseQuery
).Hope that helps somebody!
@n8downs, are you also using apollo client? If you are using apollo client as well, did you change the configuration and did you remove aws-appsync-subscription-link. On your given code, how can you use subscription? I mean, are you still using createSubscriptionHandshakeLink?
from aws-mobile-appsync-sdk-js.
I am also encountering this issue @juanch0x and looks like there's no update for a long time with this SDK. Is there any workaround that you did from your end?
Sadly, the only workaround that I found was disconnect the "subscribeToMore" when the app is moved to background or lost internet connection, and subscribe it again and fetch the info from the query when the app comes to foreground or get internet connection again
from aws-mobile-appsync-sdk-js.
I am also encountering this issue @juanch0x and looks like there's no update for a long time with this SDK. Is there any workaround that you did from your end?
Sadly, the only workaround that I found was disconnect the "subscribeToMore" when the app is moved to background or lost internet connection, and subscribe it again and fetch the info from the query when the app comes to foreground or get internet connection again
Does it mean you're reloading the app?
from aws-mobile-appsync-sdk-js.
@n8downs, are you also using apollo client? If you are using apollo client as well, did you change the configuration and did you remove aws-appsync-subscription-link. On your given code, how can you use subscription? I mean, are you still using createSubscriptionHandshakeLink?
Yes, we're using apollo client, and yes, we removed the aws-appsync-subscription-link
entirely from our codebase.
from aws-mobile-appsync-sdk-js.
@n8downs did you find that the Apollo client has a method for re-connecting a subscription websocket? Could you provide any code snippet of how your fixed this re-connect issue in GraphQL subscriptions?
from aws-mobile-appsync-sdk-js.
Related Issues (20)
- Getting apollo-link Type error on build HOT 2
- Type 'CredentialsGetter | undefined' is not assignable to type 'CredentialsGetter' with createAppSyncLink
- TypeError: Cannot read properties of null (reading 'match') HOT 2
- aws-appsync-react not installing in React 18 HOT 3
- Buffer is now only available as a polyfill on the new vite builds. Module "buffer" has been externalized for browser compatibility HOT 1
- Getting "The request signature we calculated does not match the signature you provided." when creating subscriptions using aws-appsync-subscription-link and apollo client v3 HOT 5
- undefined Unable to resolve module stream from
- Spread operator does not work with util.appendError HOT 1
- npm install fails with typescript error
- deepdish:connect errors with token expiry.
- Error: Unable to resolve module AccessibilityInfo
- Vanilla AWS SDK v3 + Apollo V3 query guide
- Managing Reconnection Attempts for AWS AppSync Subscription with Apollo
- useSubscription does not conform to Apollo HOT 2
- buildMutation not working properly with header
- Passing a header into AWSAppSyncClient?
- Console showing error
- Refused to set unsafe header "host" with IAM auth link
- Module size optimization for production HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-mobile-appsync-sdk-js.