GraphQL vs REST
Debates on whether GraphQL solves REST API issues like N+1 queries, over-fetching, and multiple requests, including discussions on performance, optimization, caching, and tools like DataLoader.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Wasn't the whole point of GraphQL in mitigating this?
The author is missing a few important notions:- graphQL server is storage-agnostic. It allows you to mix databases, APIs, anything, into one cohesive queryable model. It acts as a hub for several data sources. Consumers don’t need to care- queries are easily composable, reusable, and can be aggregated for batching, deduplication and optimisation (can be done with a query planner, but is way more complex)- it’s safe enough for queries to be sent directly from the client on user devices
Didn't GraphQL solve this issue already anyway?
Isn't this what GraphQL was designed to solve?
Big missing con for GraphQL here — optimization. Doing the right thing in simple cases is easy; in more complex cases you’re looking at having to do custom operations based on query introspection which is an even bigger pain in the ass than using REST in the first place UNLESS all of your data is in one database OR if you’re using it as a middleman between your clients and other backend services, you have a single read-through cache like Facebook which allows you to basically act as if everythin
What? GraphQL is purpose built to solve that in 1 Query. Not doing it in 1 query is on you not the protocol.In practice with REST the frontend engineer didn't want to wait and tried to use the existing REST endpoints, did N+1 API HTTPS calls and then joined them client side in javascript.
If it's actually a REST API then it's going to take multiple queries. Certainly you can put an non REST API in front of it to reduce the queries. Every site does it and every site does it in a different way. GraphQL is built to solve this exact problem in a standard way.
Does GraphQL actually provide performance advantages right now? From what I've read about it, it seems like it suffers from a bit of an N+1 queries problem if you don't do a lot of custom optimization, which seemed like considerably more work than a REST API.
I just use GraphQL and freeze the queries at compile time so only known queries can be used. That stops worries about misuse from the frontend.On the backend, for performance we have two choices:1. Over-fetch. It's relatively cheap doing that from a cache. Most queries don't use too many different variations.2. Optimize what data we fetch based on the node's children in the GraphQL query received. I don't think people do this often enough but... GraphQL gives you the
I understand the GraphQL has fallen out of favour somewhat, but wasn’t it intended to solve for this?