Giter Club home page Giter Club logo

Comments (8)

dylan-westbury avatar dylan-westbury commented on May 24, 2024 1

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.

pepemiso16 avatar pepemiso16 commented on May 24, 2024 1

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.

n8downs avatar n8downs commented on May 24, 2024

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 __typenames 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.

pepemiso16 avatar pepemiso16 commented on May 24, 2024

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 __typenames 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!

@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.

juanch0x avatar juanch0x commented on May 24, 2024

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.

pepemiso16 avatar pepemiso16 commented on May 24, 2024

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 avatar n8downs commented on May 24, 2024

@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.

objectiveSee avatar objectiveSee commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.