logoalt Hacker News

collingreen • today at 2:22 AM • 1 reply • view on HN

I haven't ever succumbed to graphql but this is what I see as the value -- with this approach you can have your components declare the data they need and automatically get that composed and delivered magically (from the front end perspective). It never felt worth it on any project I've worked on but if you aren't doing this part then it seems like a lot of pain for almost no benefit.


Replies

tcoff91 • today at 8:39 AM

The main benefit in my experience is normalized caching and optimistic state. You execute a mutation, you receive back the updated entity, the normalized cache rerenders all the components that are selecting the updated fields on that entity and your whole app’s UI just stays in sync. I haven’t used Relay but URQL is nice.

But yes, declaring component data needs via fragments is great and then you build the query document by combining the fragments so you only fetch what your UI needs. You can really make your app perform well on high-latency mobile networks by reducing the amount of round trips. You don’t need GraphQL to do that per se but it helps.