- Dataloader is a utility often used in GraphQL to batch and cache requests, which helps in reducing the number of database queries and improving performance.
- By batching multiple requests into a single query, it effectively addresses the n+1 problem.
示例
const DataLoader = require('dataloader');
const userLoader = new DataLoader(keys => myBatchGetUsers(keys));
在一个事件循环中执行多次以下代码:
userLoader.load('key');
将会把多个传入的参数放在数组中调用批处理函数