5 ms·
> A REST endpoint will execute a highly specialised query that will hit all the right database indices and will return just the dataset required in one roundtri
by Chyzwar 8y ago
> A REST endpoint will execute a highly specialised query that will hit all the right database indices and will return just the dataset required in one roundtrip to the database.
Each time you need to have a new highly specialized query you create REST resource. That why I prefer to be honest and just make RPC call.
> Meanwhile with GraphQL your server will have execute what's essentially `SELECT <all>` three times (otherwise your "dataloader" won't be able to cache data for more complex queries) and do all the filtering and joins in-memory in-code.
That fine, because easy cache invalidation is worth it. You will find that REST complex endpoints will take cache the same data multiple times.
> Hahahha wat? The client has no access to data. The only thing it does is send a query request to the server. The server will parse the query. The server will request data from the database (multiple times). The server will end up joining, filtering out, caching, figuring out proper auth access to, etc. etc. to data.
I said data access, not data. The benefit of GraphQL materializes when you have multiple client application that targets same backend data store. You describe your data schema and clients can figure out what data they need.
> Yup. You only muddle your code with those queries (the code needs to find a way to compose/filter out/etc. etc. etc. the data for the ad-hoc queries from the client). And you only do multiple redundant and expensive trips to the database (what happens when the DB is sharded, and some data required for the query lies in a different shard? What happens when connections are slow/interrupted? etc. etc.)
You have cache. Having only one copy of user in the cache is super important. GraphQL is not creating expensive queries. With GraphQL it is easier to shard your DB because you will have less joins.
> No it won't. Dataloader only caches some data during one request. On the next request you will do the same: expensive multiple roundtrips to the database.
Dataloader supports any Cache backend. In production, you will use something like Redis. Whole point dataloader is to cache between requests. Its supports cache invalidation as well.
> Oh. By the way. Remember how you dismissed ORM? Well, your dataloaders and data resolvers (and whatever other new lingo GraphQL came up with) is nothing but a very limited and inefficient ORM.
No, they are query interface. They expose DSL for accessing data. Mapping is something that can be done in Relay.
- dmitriid 8y ago> Each time you need to have a new highly specialized query you create REST resource. I love it how you meander. First you where complaining about ORM creating complex queries. When I countered with the simple fact that you don't need ORM, and "complex queries" are highly specialised efficient queries that take full advantage of DB capabilities, you immediately go off on a tangent talking about RPCs. :-\ > That fine, because easy cache invalidation is worth it. No it's not fine. Because instead of retrieving a simple single highly optimised dataset in one go you do multiple inefficient roundtrips to the database. > I said data access, not data. access. /ˈaksɛs/ 2. obtain or retrieve (computer data or a file). All data access happens on the server through inefficient database queries and in-memory juggling of data. Clients have no access to data, they send queries. > Whole point dataloader is to cache between requests. Dataloader (in it's original form and specification) doesn't cache between requests. DataLoader provides a memoization cache for all loads which occur in a single request to your application. DataLoader caching does not replace Redis, Memcache, or any other shared application-level cache. DataLoader is first and foremost a data loading mechanism, and its cache only serves the purpose of not repeatedly loading the same data in the context of a single request to your Application. If any other Dataloader implementation implements caching between requests, they are just reinvent the wheel. > No, they are query interface. They expose DSL for accessing data. ORM is a DSL at it's core. And that's what "dataloaders" and "resolvers" in essence are: ORMs. To quote from Apollo: In order to respond to queries, a schema needs to have resolve functions for all fields. const resolverMap = { Query: { author(obj, args, context, info) { return find(authors, { id: args.id }); }, }, Author: { posts(author) { return filter(posts, { authorId: author.id }); }, }, }; Oh look. A wild ORM appears! Oh look how it quickly devolves into multiple DB roundtrips for any non-trivial query.