Search code examples
reactjsreduxgraphqlapollo

What is the best practice when using apollo graphql and React Redux


My app uses apollo graphql but I also think I need Redux.

For example, say I have a todo app.

I fetch my "saved" todos from backend server using graphql. Then I also have new todos being inputted into the app but not yet "saved". How or where do I store the "unsaved" todos, I may at some point later on decide to send these "unsaved" todos to the backend using graphql to be saved or alternatively I will just discard them.

I have heard somewhere that you should not mix apollo graphql and redux but I suspect this means not calling apollo graphql client and then taking that fetch data and storing it in redux.

While there user is add more todos is it okay to store that data in a redux store or is there another way?

The app is more complex than a todo app but wanted to use that as an example.

Is it okay to use apollo graphql for some data and then redux for other seperate data?


Solution

  • maintainer of Redux and Apollo Client here ;)

    It's true that you should not mix that data too much in general, but it's perfectly fine to have an Apollo Client and a Redux store side by side - for different kinds of data.

    Always make sure where data has it's source and keep it as close to that, unless you have a good reason. That also means, that a form could be local state, while other data is Redux state, and data from your API lives in the Apollo Client.