8

I am using react-query for api calls in my react native app. And backend is based on graphql. For query and mutation requests there is no problem. I simply use useMutation and useQuery to fetch data. My problem is that I should notify user of new notifications that comes from graphql subscription. And I don't know how to use it with react-query. I couldn't find any documentation in react-query docs. thanks for any help.

1 Answer 1

5

Since GraphQL subscriptions are usually based on WebSockets, the best approach is to open a connection to the socket in an effect. When you get data, you can use queryClient.setQueryData.

You can read more about the topic here:

https://react-query.tanstack.com/community/tkdodos-blog#7-using-websockets-with-react-query

Sign up to request clarification or add additional context in comments.

2 Comments

I study the link you provided but I really don't know where to add my subscription query?
> "Additionally, you can setup an app-wide useEffect that connects you to your WebSocket endpoint." So I would do it in a useEffect in your App component ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.