React / General

Will GraphQL replace Redux?

Will GraphQL replace Redux?

React / General · March 1, 2018 at 2:35pm
I read there's no need for Redux while there's Graphql. GraphQL is really cool but will it replace Redux in the short-term, or long-term future? I mean 3-6y

March 1, 2018 at 2:37pm

We barely use Redux anymore now that we're using GraphQL

  • reply
  • like

We went from tons of stuff in Redux to almost nothing

like-fill
10
  • reply
  • like
🤷‍♂️
  • reply
  • like

Now with apollo-link-state (https://www.apollographql.com/docs/link/links/state.html) you can even use GraphQL for the things you use Redux for!

like-fill
11
  • reply
  • like

I don't know how popular that will be, but it's an option

like-fill
7
  • reply
  • like

That's a strong argument!

  • reply
  • like

to almost nothing? is there something left?

  • reply
  • like

You can use redux for UI stat

  • reply
  • like

There is something left, which is the current user data

like-fill
5
  • reply
  • like

GraphQL is a query language while Redux is a library for state management. Two completely different things. You may say that Apollo client will replace Redux, which might be true, but even that's is inaccurate today, because Apollo uses Redux under the hood. However, since I'm using Apollo and GraphQL and haven't wrote a single reducer (yet). There're several hooks to update state after mutation/query/subscription and writing a custom reducer is the last choice.

like-fill
13
  • reply
  • like

Apollo Client doesn't use Redux under the hood anymore since v2

like-fill
9
  • reply
  • like

Ah, sorry, I missed this change!

  • reply
  • like

While graohql is a query language for you data

  • reply
  • like

indeed, apollo-link-state is a better option than redux for domain logic state, as for UI needs, I believe https://github.com/renatorib/react-powerplug covers most of them

like-fill
2
  • reply
  • like

It will, but probably only for people who are using GraphQL for other APIs as well unless "moving the api gateway to the client side" becomes more popular... Now that I think about it that could easily be it's own talk.

like-fill
2
  • reply
  • like

This feels like a weird statement. A query protocol replacing a front end state management lib. We will always need both of those things. Optimistic updates Can’t be done without state management. Offline first. The question needs rewording. Maybe “Is it worth managing our own state now that Apollo or Relay do it so well?” For our application the answer to that question is yes, we do optimistic updates and server sent events that need reconciling on the front end. If either Apollo or Relay can handles SSEs our the box please fill me in.

like-fill
5
  • reply
  • like

March 5, 2018 at 4:21pm

FWIW, we also have lost the need for any type state management library since replacing our REST APIs with GraphQL endpoints. The state management our UI does need now (not much) works great with vanilla React state.

  • reply
  • like

Any articles on this? I'm very confused.

  • reply
  • like

Hi James, here's one article anyway: https://dev-blog.apollodata.com/reducing-our-redux-code-with-react-apollo-5091b9de9c2a

From our experience, most of our state management code was all trying to merge state from our API server and manage the asynchronous nature of all that. Once we switched to GraphQL, those issues were gone and we no longer had to manage business state in a store at all.w Hope that helps!

like-fill
5
  • reply
  • like

March 6, 2018 at 6:35am

@mxstbr how are you managing the routing? is that graphql? i wonder if you could use a component or the context API to replace that piece of redux 🤔

  • reply
  • like

March 6, 2018 at 4:52pm

not all applications can use graphql, especially those that really don't have a backend. could also use graphql queries directly and cache the response data in redux - sometimes the existing cache strategies with apollo or urql aren't enough. redux isn't going anywhere

  • reply
  • like

If you ask me - redux is here to stay. As @cjhowe7 said many apps don't use any backend per se. And you have to have state in check :D

like-fill
2
  • reply
  • like

Can anyone explain to me how a query language and a state management library are comparable? Perhaps any links? I'm in the process of learning Redux, and have GraphQL in my sights as well. So learning when to use one as opposed to the other would be great info :)

  • reply
  • like

They aren't. The GraphQL query language is completely independent from the GraphQL *client library*. The thing is, a lot of GraphQL client libraries include a caching mechanism to manage the data that is pulled from a GraphQL backend. So the "state management" part is really just some GraphQL clients managing cached GraphQL data. This is completely optional though, and you can use GraphQL without it, potentially with Redux.

like-fill
2
  • reply
  • like
Your message here...

*bold*_italic_`code````codeblock```