Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In GraphQL we have one endpoint with two different queries. So the same problem can happen if someone queries naively. But, they can also write one nested query that says "give me user for id X and for each video id, give me the video data". It will be one request from frontend to backend, but still multiple selects to the database, unless we use some "smart" GraphQL framework that does magic for us.

In reality, you'd more likely have an endpoint like `/videos/user/12` or `/users/12/videos`, which would provide all videos for a user, but we'll put that aside for the sake of an example.

Hmm, so I think you're saying that there would still be separate queries, but you're "batching" them, such that client sends multiple queries simultaneously to the backend, and then the backend is responsible for executing them? With HTTP/2 (which supports request multiplexing), you get a similar result using REST endpoints.

> Yeah, seems you edited your post. When I read it, there was 100% a question-mark in it. ;)

I'm not entirely sure if you're kidding, but I assure you I didn't edit my post.



> In reality, you'd more likely have an endpoint like `/videos/user/12` or `/users/12/videos`

Sure and then you do the same with images and friends. And all of those have tags. Friends are also users so they also have videos and images... which have tags. Friends can also have friends of course... it can even be circular!

I wanted to keep my example simple, but here you go...

> Hmm, so I think you're saying that there would still be separate queries, but you're "batching" them, such that client sends multiple queries simultaneously to the backend

Sorry, I used the same term for two different things. Nothing happens in parallel. Frontend sends one request (not one query...) to the backend which contains two graphql queries (one of them a nested query). It is all one http request and one response. No batching here, you can send this request using curl or postman.

HTTP/2 does not help here, because the second query is dependent on the first one (hence a subquery). Because you need to know the video ids first. Sometimes HTTP/2 helps, but not in this case.

> I'm not entirely sure if you're kidding, but I assure you I didn't edit my post.

Not kidding at all - maybe I mixed it up?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: