{
hero {
name
friends {
name
friends {
name
}
}
}
}
But some clients might only need this: {
hero {
name
}
}
This is a small example, but it's pretty clear that "always including all fields and nested relationships in every REST API response" is not a viable solution.(GraphQL examples based on the schema used in the official documentation: https://graphql.org/learn/queries/)
one part of the page makes a request and the rest of the page gets to use the data because now it’s in the local object cache.
I get what this article is saying but there is a lot more to graphQL than reducing network RT. It’s about replacing statically defined REST API responses.
As a prior commenter wrote, it’s making the backend more flexible when the front end devs change their mind.
For most web apps the overhead of adding a new endpoint is small so the benefit of GraphQL is also small, but if you're Facebook then GraphQL makes a huge amount of sense.
All the data you needed was there, but every request caused a lot of memory usage and lots of database queries. GraphQL allows you to just ask for the fields you need without necessarily incurring the cost of returning anything else.