npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cachiql

v1.0.1

Published

Batching and caching solution for Graphql

Readme

Alt text

About CachiQL

Twitter GitHub Stars GitHub license npm bundle size

CachiQL is an ultra-lightweight library designed to batch and cache graphql-js queries to reduce calls to databases. Additionally, CachiQL is written in Javascript for use in Node.js.

Note that batching and caching multiple data requests is not novel to Javascript and Node.js. Additionally, the inspiration behind CachiQL is to deeply understand the implementation of DataLoader, which was created by Lee Byron at Facebook to solve the common N +1 issue of a naive GraphQL server. Our team’s purpose is not to replace DataLoader but rather, to help others understand the rationale behind DataLoader and create a simplified and lightweight NPM package.

Installation


Install the CachiQL package using npm.

npm install --save cachiql

Now in order to use CachiQL, create a new instance of CachiQL. Each instance is created for each request using a web server, such as express.

Although CachiQL does not require any dependencies, this package requires a global Javascript run-time environment with ES6 Promise.

How to Use CachiQL


Batch processing is the cornerstone of the functionality of the CachiQL package. Because GraphQL standardizes resolvers with a depth-first-search execution query, the issue of N+1 arises. Simply put, the server then executes multiple and unnecessary trips to the database, over-fetching to waste computing resources and bandwidth.

const cachiql = require(‘cachiql’);

const schema = new GraphQLSchema({
  query: RootQueryType
});

app.use(
  '/graphql',
  graphqlHTTP({
    schema: schema,
    graphiql: true,
    context: {
      authorLoader: new Cachiql(AuthorLoader),
      bookLoader: new Cachiql(BookLoader),
      cachedData: []
    }
  })
);

Batching


The CachiQL class constructor includes a batch loader that takes in an array of keys and returns a promise for each key which eventually resolves to the return array of values or the promise is rejected.

A loader enables a load of individual values before executing the batch with all the included keys.


const batchAuthors = async (ids) => {
  try {
    const authors = await Author.find({ _id: { $in: ids } });
    return authors;
  } catch (err) {
    throw new Error('There was an error getting the Authors');
  }
};

module.exports = batchAuthors;

const batchBooks = async (ids) => {
  try {
    const books = await Book.find({ _id: { $in: ids } });
    return books;
  } catch (err) {
    throw new Error('There was an error getting the Books');
  }
};

module.exports = batchBooks;

Caching


CachiQL includes a memoized cache for the loads. Additionally, CachiQL further parses through the array of keys, removing duplicates. Finally, note that you can use application-level caches such as Redis. The idea behind CachiQL’s memoized cache is just not to repeat the same data in each request.

CachiQL and GraphQL


The utility of CachiQL is to eliminate the depth-first search structure of GraphQL standard resolvers. In other words, CachiQL aims to solve the N+1 issue that a GraphQL server creates when new database requests are issued as fields are resolved.

In the example provided, using a GraphQL standard resolver, querying a database containing 16 books by three different authors means that submitting a singular deeply nested query issues 16 trips for the information. However, using CachiQL creates more efficiency by only making two round trips to the backend.

NOTE: The array of values needs to be the same length as the array of keys.