by duckfruit · 8y ago · 0 comments
How GraphQL[1] Replaces[2] Redux
[1] Or any well designed back end API[2] For some narrow, often simple applications. And even in those cases it usually doesn't replace redux as much as it augments it.
Not really. You can design specific REST endpoints to return the data in the format you want.
Wat.
Frontenders can write their frontend code in whatever they see fit. REST is a contract on data and format of the data between frontend and backend.
> Also, your backend guys are tied up constantly doing stupid endpoint changes, and both teams are wasting time messing around with extra effort to allow one side to be deployed before the other, instead of working on actual functionality work.
Well, if your teams are dysfunctional, then of course, that's what you will end up having.
Now tell me:
- what will you do when your glorious ad hoc GraphQL query ands up bringing the database to its knees?
- what will happen when your glorious GraphQL schema doesn't have all the data the frontend needs?
We control what is returned in data from our REST API by merely specifying the fields you want as a parameter. If there are use cases that would require multiple tables to be joined, those are created ahead of time as views with appropriate triggers for updates and then endpoints are created for accessing that view through RESTful methods. This has always worked just fine.
Introducing state management doesn't come for free, of course. That is an extra layer of complexity that you have to reason and maintain. And if your app doesn't need any client side caching or you don't envision a need to have shared state between your components maybe you don't need to have something like Redux. But I feel like the use cases for those sort of apps tend to be pretty narrow.
edit: Another commenter mentioned a good point that gets to the heart of your question better than my rambling -- You are still managing state in your app - just with Apollo instead of Redux.
So yes, you can replace Redux with something different. There are pros and cons to it, but it's not required or even fundamental to implementing GraphQL in a React app
There are some new features in Apollo for handling client side state but I'm sticking to Redux for now (for client side state, I am using Apollo for some data fetching).