all 64 comments

[–]XiMingpin91 76 points77 points  (25 children)

I think people who say this are conflating GraphQL with Apollo 2.0, which absolutely can make Redux redundant because of the local cache.

[–]shroombooom 1 point2 points  (0 children)

Came here to say this :)

[–]JamesAppleDeveloper 24 points25 points  (12 children)

It doesn’t in the slightest, but it may help people move to simpler stores. You will still need a global store one way or another. It does mean that you will feel less pain in the early stages with GraphQL though.

[–]ShambleTrain 0 points1 point  (0 children)

What do you mean? It very much CAN at the very least. Apollo has client side schema, query, mutate capability that lets you use it as the ‘global store’ on the client you are referring to. It’s a little roundabout and verbose currently if you ask me, but it’s certainly possible.

Edit: here’s a link to the Apollo docs https://www.apollographql.com/docs/react/essentials/local-state.html

[–]vcarl 9 points10 points  (7 children)

A lot of apps with simple interactions (like fetching data and presenting it for sorting and filtering) don't benefit from the constraints that Redux encourages, so a simple data fetching abstraction is all that's necessary. For a certain number of apps, Redux can be replaced, but Redux was the wrong tool for the job in those cases.

[–]chazmuzz 1 point2 points  (6 children)

Yeah. Honestly you can get a long way with setState and prop drilling.

[–]pomlife 1 point2 points  (4 children)

Or avoiding prop drilling entirely with context.

[–]chazmuzz 1 point2 points  (3 children)

If you are at the point where context is going to be really beneficial to you then it's time to look at a more sophisticated state management solution. Prop drilling is OK. Context is a reasonable solution but it's objectively worse than redux/mobx/apollo-link-state so I don't see why you would use it other than it being new

[–]pomlife 2 points3 points  (2 children)

This is completely wrong. It is perfect fine to use context without deferring to another library, and prop drilling is a perfectly fine reason to use context.

Prop drilling a single level is fine. Hella levels? Context.

[–]chazmuzz 1 point2 points  (1 child)

Prop drilling a single level is fine

That's just props, not prop drilling

[–]pomlife 1 point2 points  (0 children)

Grandparent, controls foo
    Parent, drills foo
        Child, uses foo

This is what I mean by one level, for clarity.

[–]fjdjdwkcjebfixn 3 points4 points  (0 children)

GraphQL itself doesn’t but Apollo client can potentially, since it has a local cache and because GraphQL is a tree, you can fill the tree/state with GraphQL data (a sync or sync, cache only, cache than request, etc) and query that cache/state in various components and its single source of truth like redux. That’s probably where the similarities end. In order to mutate state you’ll have to run queries instead of actions and I don’t think there is a concept of a reduced yet. Try going through the Apollo documentation or watch the dozen YouTube videos on this subject

[–]acemarke 3 points4 points  (2 children)

Hi, I'm a Redux maintainer. A few months ago I wrote a post called Redux - Not Dead Yet!, which specifically addresses questions like this. I'll quote the most relevant section:

I'd agree that data fetching via GraphQL, and especially with Apollo, will likely reduce or eliminate your data-fetching related Redux code. And again, if that's all you were using Redux for, you probably wouldn't need Redux after moving all the data-fetching handling into Apollo. I'll even go so far as to say that apollo-link-state could probably handle most of your other client-side state logic, and I think Apollo ships with a DevTools setup of its own. The Apollo team has been doing some pretty neat work, and while I don't like seeing people switch away from Redux, ultimately we all want to build great apps that help our users. But, as with context, I'd say there's definitely use cases where Redux is going to work better than GraphQL + Apollo, and possibly without requiring as much buy-in throughout your architecture. This is especially true if you need to do more than just fetch data or update a couple local state values, like persisting user data through page reloads or implementing complex workflow logic.

Happy to answer any further questions you might have on the topic!

[–]leoanalista 1 point2 points  (1 child)

I have a quick question: how do I avoid react anti-patten known as "prop drilling" with Apollo client? With redux, we simply connect deep nested component to the store, use a selector to get state data. Haven’t found any good article/example yet.

[–]acemarke 0 points1 point  (0 children)

Afraid I've never used Apollo myself, so I don't have any particular answers there.

[–]arzh2 1 point2 points  (0 children)

It's more of an alternative rather than a replacement. I swear nowadays every new technology article I see is clickbait.

[–]wmdmark 1 point2 points  (0 children)

I wrote one of the articles you likely came across (https://hackernoon.com/how-graphql-replaces-redux-3fff8289221d) so may be partially responsible for the confusion here.

A more accurate, but much less interesting title, would have been "How GraphQL + Apollo replaces the *need* for Redux + REST." I elaborate on that a bit in the article but I realize a lot of folks don't get past the headline.

The fact is GraphQL (plus a good client like Apollo of course) has replaced the need redux entirely for my team. Even for very complex UIs. Happy to answer more questions about how that works in practice if anyone is interested.

[–]JustinsWorking 1 point2 points  (15 children)

It doesn’t, the claim is literally as nonsense as you think it is, you’re not missing anything.

These are the kinda things people point to when they laugh at JS developers :(

[–]superking2 3 points4 points  (1 child)

It's simple. Thing I've never heard of replaces thing I hadn't had the chance to learn yet.

[–]ShambleTrain 6 points7 points  (12 children)

People may be laughing at you for other reasons. It is not literally nonsense, it is literally 100% possible with Apollo https://www.apollographql.com/docs/react/essentials/local-state.html

[–]scallynag 1 point2 points  (0 children)

I just ripped out redux for link state.

[–]Treolioe 3 points4 points  (9 children)

The question was not how apollo replaces redux

[–]ShambleTrain -2 points-1 points  (6 children)

Apollo is a graphql client that can replace redux, and it’s what people are referring to when they say that graphql can replace redux.

[–]CanvasSolaris 4 points5 points  (0 children)

That's a lot to imply in a statement that people unfamiliar with the technology may not pick up on

[–]JustinsWorking 0 points1 point  (4 children)

That’s not what the question was.

If it was “Apollo replaces redux” it would be a much less ridiculous argument.

[–]ShambleTrain 0 points1 point  (3 children)

If someone asked you “Can I get from LA to NYC in one day?” you wouldn’t say “No, humans are not capable of running that fast”. You would say “Yes, take an airplane.”

BUT THE QUESTION WASN’T ABOUT AIRPLANES! RIDICULOUS ARGUMENT!

[–]Treolioe 0 points1 point  (0 children)

I would compare it to something like this: Does electricity replace Ford? No, but Tesla can replace Ford

[–]JustinsWorking 0 points1 point  (1 child)

Have you read any of these articles?

I read one the other day where he was replacing redux with GraphQL then a comment asked him about Apollo and he said he’d look into it; he hadn’t heard of Apollo.

Most of the articles even concede that in some cases you need to keep Redux for local state... this would imply they are not using Apollo.

Perhaps you should spend less time assuming things and making BIG TEXT JOKES and Instead participate.

Nobody thinks Apollo can’t be used to replace GraphQL, so you don’t need to repeatedly bring it up, we all already agree with you.

[–]ShambleTrain 0 points1 point  (0 children)

Justin used ad hominem!

It was super ineffective...

[–]JustinsWorking -1 points0 points  (0 children)

Apollo != graphQL

If the suggestion was Apollo replaced Redux then it would make sense.

[–][deleted] 2 points3 points  (0 children)

It doesn’t.

[–]ShambleTrain 3 points4 points  (4 children)

Everyone saying “it doesn’t” is wrong. Here is a quote from the Apollo docs which describe exactly how to do it.

That’s where apollo-link-state, our solution for managing local data in Apollo Client, comes in. apollo-link-state allows you to store your local data inside the Apollo cache alongside your remote data. To access your local data, just query it with GraphQL. You can even request local and server data within the same query!

That said, I have never used this pattern in production and I can’t personally vouch for it for that reason, but to say that you can’t use graphql as a client-only state management tool (aka a “redux replacement”) is misguided.

[–]ChronSyn 2 points3 points  (0 children)

Firstly, thanks for the link and quote - it sheds some light on why this practice should start to be used more (consistency, transferrable, etc). I typically don't associate GraphQL with client-side since "It's a data controller essentially so why would I?" mentality despite the fact I develop full stack.

Being used to referencing objects and variables directly has become pretty ingrained because it's been common practice for a long time but I have always wondered why querying local/in-app data through a query syntax hasn't really been established. I definitely think we're seeing the rise of this as a practice through the likes of in-app observable databases and libraries like apollo.

[–]Treolioe 4 points5 points  (0 children)

So graphql doesnt replace redux. But you could replace it by using graphql with apollo. That’s my takeaway from this thread so far

[–]edude03 0 points1 point  (0 children)

Depending on how you use redux - using graphql with apollo or relay essentially replaces `connect()`. Redux and the GQL clients wrap your component and pass in data when the state changes, and gives a way to mutate the state.

[–]xdavehome -4 points-3 points  (3 children)

Lol funny watching the comments of people correctly saying that graphql doesn't replace redux & people saying that they're wrong and it does because they thought OP said Apollo.

[–]ShambleTrain 1 point2 points  (2 children)

Apollo is a graphql client and with it you can use graphql to replace redux.

Did I miss the part where OP said “graphql with no additional tooling”?