Re:Ask HN: When should I use GraphQL
by I_am_tiberius on Tuesday May 28, 2024 @06:05PM
(#40506121)
Doesn't the fragment (property selection) feature of graphql only solve the frontend network load part? I mean, I doubt anyone creates an SQL query based on the graphql query properties, right? That means the network load between backend and db server is consistent, independent from which fields are selected via graphql.
Re:Ask HN: When should I use GraphQL
by satvikpendem on Tuesday May 28, 2024 @06:11PM
(#40506164)
You could use a backend framework that optimizes the SQL as well (I believe Hasura does this), or just have a string interpolated select statement in the SQL.
GraphQL is very useful, it removes whole classes of bugs. You can even use a Result/Either type where if you don't handle both the success and error cases, the GraphQL request won't even compile, so you can get type safety at both the client and the server while also not having to use purely TypeScript like with tRPC, allowing multiple clients like mobile and web. Pothos does this very well as an error extension [1], where, given the schema:
you can then query it with If you forget `... on Error` the query will simply fail. I should also add that most people use GraphQL incorrectly, to get the benefits of not over/underfetching, the Relay approach using fragments is the only viable way currently. Otherwise it's not too much better than REST. You define the exact data required for a specific React component in GraphQL fragments, then the Relay compiler will stitch those fragments together into one and only one request. This is a great (if long) overview on the problems Relay solves and why everyone else uses GraphQL incorrectly (then complain that GraphQL sucks) [2]. Hint, Apollo is not the way.[0] https://www.youtube.com/watch?v=yab6i9lrEv0
[1] https://pothos-graphql.dev/docs/plugins/errors
[2] https://alan.norbauer.com/articles/relay-style-graphql