talira

DataLoader

Batching and caching utility for a Node.js app's data fetching layer

open sourceMITfree

DataLoader is an MIT JavaScript utility from the GraphQL project that sits in a Node.js service's data fetching layer: loads requested in the same tick are batched into one request to the database or web service, and each result is cached per request, so the same key is fetched once. It's a port of the Loader API Facebook developed in 2010, and it's most often used to avoid N+1 queries in a GraphQL server, though it works with any backend. It's also meant as a reference implementation for ports to other languages.

Problems it solves

  • stop N+1 database queries in my GraphQL resolvers
  • batch many lookups by id into one SQL query in Node.js
  • cache repeated loads of the same record within one request

Features

  • batches individual loads in one tick into a single backend request
  • per-request cache so each key is fetched once
  • works with any database or web service behind a batch function

Alternatives

The same job

These do what DataLoader does.

  1. Haxl A Haskell library that simplifies access to remote data, such as databases or web-based services

Compare DataLoader with the top 3