Socket
Socket
Sign inDemoInstall

dataloader

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dataloader

A data loading utility to reduce requests to a backend via batching and caching.


Version published
Weekly downloads
4.6M
decreased by-3.33%
Maintainers
2
Weekly downloads
 
Created

What is dataloader?

The dataloader npm package is a utility designed to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching. Primarily used in GraphQL environments, it helps in reducing the number of requests to a data source by batching multiple requests into a single one and caching the results to avoid redundant operations.

What are dataloader's main functionalities?

Batching

Batching is a core feature of DataLoader where it combines multiple individual requests for data into a single batch request. This reduces the overall number of requests sent to a data source. The code sample demonstrates how to create a DataLoader instance with a batch loading function and how to use it to load data.

const DataLoader = require('dataloader');

async function batchFunction(keys) {
  return await fetchSomeData(keys);
}

const loader = new DataLoader(keys => batchFunction(keys));

loader.load(1).then(result => console.log(result));
loader.load(2).then(result => console.log(result));

Caching

Caching is another important feature of DataLoader. It caches the results of the batch function to avoid redundant calls in future requests. The code sample shows how DataLoader uses an internal cache mechanism to store and retrieve results, thereby optimizing data fetching operations.

const DataLoader = require('dataloader');

let cache = {};
async function batchFunction(keys) {
  return keys.map(key => cache[key] || fetchAndCacheData(key));
}

const loader = new DataLoader(keys => batchFunction(keys), { cache: true });

loader.load(1).then(result => console.log(result));
loader.load(1).then(result => console.log(result)); // This call will use cached data

Other packages similar to dataloader

FAQs

Package last updated on 31 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc