We implement arbitrary query caching and batching using DataLoader to allow greedy data fetching with automatic DB query optimization.
You may see some minimal Typescript syntax to provide some context in the example code. Do not be alarmed.
GraphQL promises a lot of cool features like the ability to batch and cache queries, save on data transmission, query for data anywhere and only request exactly what you need from the server, and all sorts of optimizations. But it merely
enables these features through its use of strong typing of the API schema—they do not come for free. It’s up to us to implement the optimizations by utilizing the metadata.
Continue reading “Use DataLoader to Batch And Cache Arbitrary MongoDB Queries in GraphQL Resolvers”