November 07, 2022
This dataloader sits between the application layer, e.g. a GraphQL resolver, and the datasource, providing an abstraction to the latter where a single request can represent a batch of multiples.
Why does it matter?
Having a dataloader:
- avoids redundant fetching of data, as subsequent requests with the same parameters will use the cached result.
- avoids leaking datasource-specific logic, as it abstracts away their interface. One may be dealing with a database, a third-party service, or any other.