2 ms·
> How do I get all uploads of a user? I get the user by id (request 1) then all his videos by making one request per video (n requests). No big problem for the
by KronisLV 6y ago
> How do I get all uploads of a user? I get the user by id (request 1) then all his videos by making one request per video (n requests). No big problem for the database (it's all indexed) and sure, we can improve the performance, but for now the bottleneck here is the number of requests that goes over the network if we use REST. This doesn't work. You need to make a new endpoint or change an endpoint to make this work in a performant way.
The answer to this problem is resource expansion. Dylan Beattie actually has a nice and somewhat humorous presentation about how to address this with REST interfaces: https://youtu.be/g8E1B7rTZBI https://youtu.be/g8E1B7rTZBI
Here's the part that addresses such data access in particular with a social media site example (people who have photos, which have comments etc.): https://youtu.be/g8E1B7rTZBI?t=1807 https://youtu.be/g8E1B7rTZBI?t=1807
Sadly, approaches like that and even HATEOAS are not awfully widespread, mostly because of the added complexity and the support by frameworks simply not being quite there.
- valenterry 6y agoYeah sure. You can use resource expansion and also field targeting (to only get fields you need), add some typesystem on top of it, make sub-resource-expansion look a bit nicer by... I don't know, creating a small DSL for it. And then standardize documentation and tooling around it. Voila, now you have your own implementation of GraphQL that might even be better than the original one, who knows. Only one way to find out! Until then I will continue to use GraphQL wherever it works well. :)