5 ms·
REST works, but it forces you to use a single endpoint at a time. For example, let's say you have have two endpoints /albums/1/ and /users/2/ and want to query
by true_religion 7y ago
REST works, but it forces you to use a single endpoint at a time.
For example, let's say you have have two endpoints /albums/1/ and /users/2/ and want to query them both at the same time.
They're unrelated data, so following REST best practices would make them separate endpoints.
With GraphQL, they're seperate resolvers but you can write
{
albums { get(id: 1) { .... } }
users { get(id: 2) { .... } }
}
And combine them those two calls into a single query. Maybe this is also possible via REST, but I haven't seen it.
- Aeolun 7y agoOh! This is interesting. I didn’t know I could do this too. That’s a bit nicer even than only the combining of nested calls that I was aware of.
- toast0 7y agoIf the endpoints are unrelated and you know them both before querying either, you can certainly query them concurrently from nearly any client language. GraphQL can do it, but I don't think that's a big strength, compared to the dependent queries it can do. Using the results from one query to drive a further query without going back to the client will save a bunch of time if the client is far from the server.
- true_religion 7y agoSure you can make two queries concurrently, but does the server know you are doing that? With GeaphQL the server sees both queries at once, and can potentially optimize over that once someone notices that in their logs. And it expresses itself as a single network connection. I do agree though with your point about dependent queries, though I have only used GraphQL for internal apis so my experience doesn’t include that sort of problem.