What Is DataLoader?

DataLoader is a utility pattern commonly used with GraphQL to batch multiple requests for the same type of resource into a single operation.

Instead of immediately querying an author when a resolver asks for author ID 42, the resolver gives that ID to a DataLoader. During the same execution cycle, other resolvers can add IDs such as 15, 27, and 91. DataLoader then calls a batch function with all requested keys.

The batch function can fetch all authors with one database query and return the results in the exact order expected by the loader.