React-native AWS amplify graphQl Subscription

React-native AWS amplify graphQl Subscription


0

In my react native project, I am using graphQl subscription with aws-amplify.

The problem is it’s not getting notified/called when the backend sends a notification.

The backend developer told me, that from their side notification is sending correctly.

Now from the Front end side setup is also properly done because one other subscription is working fine. while for not working subscription, when I change query add some query params that are not correct then while opening screen it gives me an error. So by this can we say that there is no issue from the front end?

Or, what may be the actual possible problem?

FE implementation:

import { API, graphqlOperation } from "aws-amplify";

const subscriptionCreated = useRef(null);


const handleSubscriptionCreated = (): void => {
subscriptionCreated.current = API.graphql(
  graphqlOperation(onNotifyDataCreated, { userId }),
).subscribe({
  next: (data) => {
    console.log(data)
  },
  // eslint-disable-next-line @typescript-eslint/no-empty-function
  error: (e) => {console.log(e)},
});
};

useEffect(() => {
  if (userId) {
    handleSubscriptionCreated();
    return () => subscriptionCreated.current?.unsubscribe();
  }
}, [userId]);

in the above code, if I change anything in onNotifyDataCreated then it gives me an error as soon as the screen opens.
I also added a log return return () => subscriptionCreated.current?.unsubscribe();, this is also getting called only once when I go back from the current screen.


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *