4 ms·
> It can save you bandwidth. Get what you ask for and no more On the other hand, you tend to do "select * from FOO" and get more data from the db, because you
by vlod 4y ago
> It can save you bandwidth. Get what you ask for and no more
On the other hand, you tend to do "select * from FOO" and get more data from the db, because you don't know what the caller will ask for.
I don't think I've even seen a codebase filter the SQL based on the caller. I think I tried doing it once and it was a pita. (Please correct me if it's easy).
- coder543 4y agoThe typical approach that I've seen is to do "select * from FOO" for simple scalar fields that cost very little to retrieve from the database. If you have any fields that often contain large amounts of data, or any relations, you can provide a separate resolver for that field or relation, and then that resolver will only get invoked if the caller requested it. It's pretty straightforward, at least when using Apollo and TypeScript. (Obviously you would modify the original query to exclude such expensive fields so that you’re not duplicating work with the additional resolver.) I still don't think I would personally recommend GraphQL to most companies.