3 ms·
My understanding of the advantage of GraphQL is that it allows you to load a structure like user { groups(first: 10) { posts(first 1) {
by strken 7y ago
My understanding of the advantage of GraphQL is that it allows you to load a structure like
user {
groups(first: 10) {
posts(first 1) {
content
author {
name
address {
state
}
}
}
}
}
and have all the round-trips take place within a datacentre, instead of needing to query
/user
/user/12/groups?limit=10
/groups/34/posts?limit=1
/posts/56
/users/78
/users/78/address
and without having to write a separate
/top_posts_view
endpoint.
I don't understand from the description "a thoughtfully designed REST API built according to HATEOAS" what your proposal to solve this problem is.
- JoachimSchipper 7y agoA quick search suggests that GraphQL should usually cause one client -> server -> SQL-server query - i.e. only one network round trip. No?
- strken 7y agoI've only used it to aggregate backend services rather than as an SQL query builder, and this is also how it's used at Facebook. I'd have concerns about writing business logic in resolvers. If I was using it with a single SQL db I'd probably write a separate non-GraphQL layer for business logic and keep the resolvers thin.
- vmasto 7y agoCan you expound on the concerns?
- biggestdecision 7y agoClient-API round trips matter, because the latency is very high. API-DB latency will be much lower, so the number of round trips there is less important. GraphQL allows you to query any nested structure in one Client-API round trip, but there may be many API-DB round trips per query.
- jeremyjh 7y agoIt is better to have the resolver aggregate data, than to have multiple calls from the client to do it. The earliest uses of GraphQL was as a service aggregater. I'd be curious to know where you are seeing this "advice".