Comment by nisalperi

Comment by nisalperi 2 days ago

3 replies

My hot take is that if you’re using GraphQL without Relay, you’re probably not using it to its full potential. I’ve used both Relay and Apollo Client on production, and the difference is stark when the app grows!

rbalicki 2 days ago

1000%. There's almost no reason to use GraphQL unless you take advantage of data masking + fragment colocation.

  • tcoff91 2 days ago

    I have that with URQL+gql.tada.

    What else does relay give me that URQL does not?

    • rbalicki a day ago

      I may be wrong on the details, but with URQL:

      - you don't have a normalized cache. You may not want one! But if you find yourself annoyed that modifying one entity in one location doesn't automatically cause another view into that same entity to update, it's due to a lack of a normalized cache. And this is a more frequent problem than folks admit. You might go from a detail view to an edit view, modify a few things, then press the back button. You can't reuse cached data without a normalized cache, or without custom logic to keep these items in sync. At scale, it doesn't work.

      - Since you don't have a normalized cache, you presumably just refetch instead of updating items in the cache. So you will presumably re-render an entire page in response to changes. Relay will just re-render components whose data has actually changed. In https://quoraengineering.quora.com/Choosing-Quora-s-GraphQL-..., the engineer at Quora points out that as one paginates, one can get hundreds of components on the screen. And each pagination slows the performance of the page, if you're re-rendering the entire page from root.

      - Fragments are great. You really want data masking, and not just at the type level. If you stop selecting some data in some component, it may affect the behavior of other components, if they do something like Object.stringify or JSON.keys. But admittedly, type-level data masking + colocation is substantially better than nothing.

      - Relay will also generate queries for you. For example, pagination queries, or refetch queries (where you refetch part of a tree with different variables.)

      There are lots of great reasons to adopt Relay!

      And if you don't like the complexity of Relay, check out isograph (https://isograph.dev), which (hopefully) has better DevEx and a much lower barrier to entry.

      https://www.youtube.com/watch?v=lhVGdErZuN4 goes into more detail about the advantages of Relay