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

hacheql

v1.0.2

Published

A library for HTTP caching with GraphQL

Readme

Welcome to HacheQL · License badge PRs Welcome

HacheQL is a JavaScript library that brings HTTP caching to your GraphQL API.

Features

  • Automatically creates and caches persisted GraphQL queries.
  • Integrates with any server running on Node.js.
  • Includes specialized support for servers written with Express.js.
  • Supports caching with Redis or in the server's local memory.

Check out our demo site to see what HacheQL can do.

Getting Started

HacheQL sends GraphQL requests in a way that makes the response HTTP cacheable, so subsequent requests for the same data can be fulfilled from a cache in the browser or on a proxy server.

HacheQL works by hashing the contents of GraphQL queries and caching key-value pairs of the form <hashed query>: <full query> on the server side.

Let's get the server set up first.

Server-side HacheQL

HacheQL works with any Node.js server, but it includes specialized support for servers written in Express.js. If your project uses Express, see the next section, titled 'Server-side HacheQL - with Express.'

If you use vanilla Node or a different Node framework, you're in the right place.

  1. Install HacheQL with npm.
npm install hacheql
  1. Import nodeHacheQL in files that handle GraphQL requests.
import { nodeHacheQL } from 'hacheql/server';
  1. Call nodeHacheQL as the first step in handling GraphQL requests.
server.on('request', async (req, res) => {
  if (request.url === '/graphql') {
    try {
      const query = await nodeHacheQL(req, res, { redis: redisClient }); 
      const data = await database.query(query);
      res.end(data);
    } catch (error) {
      /* error handling logic */
    }
  }
});

See the Documentation for more detail on how to use this function.

That's all for the server! See Client-side HacheQL for the next steps.

Server-side HacheQL - with Express

If your project uses Express, this section is for you. If not, see the previous section, titled 'Server-side HacheQL.'

  1. Install HacheQL with npm.
npm install hacheql
  1. Import expressHacheQL and httpCache in files that handle GraphQL requests.
import { expressHacheQL, httpCache } from 'hacheql/server';
  1. Use expressHacheQL as the first piece of middleware in routes that handle GraphQL requests.

If you want to cache using Redis, pass expressHacheQL an object with a property redis whose value is a reference to your Redis client.

app.use('/graphql', expressHacheQL({ redis: <redisClient> }), /* other middleware */);

If you aren't using Redis, don't pass any arguments to expressHacheQL and it will automatically use the server's memory for caching.

app.use('/graphql', expressHacheQL(), /* other middleware */);
  1. Use httpCache prior to sending a response.
app.use(
  '/graphql',
  expressHacheQL(),
  httpCache(),
  graphqlHTTP({ schema, graphiql: true,}),
);
  1. expressHacheQL relies on Express's built-in express.json() method for parsing JSON-encoded request bodies. If you don't have it set up yet, add the following toward the top of your main server file:
app.use(express.json())

That's all for the server! Let's set up the client.

Client-side HacheQL

HacheQL's client side is the same whether or not your server uses Express, and it's very simple to set up.

Note: It's possible to implement HacheQL on the client-side gradually. You can set it up for some GraphQL routes and not for others, and everything will still work.

  1. Import hacheQL in files that send requests to a GraphQL API.
import { hacheQL } from 'hacheql';
  1. HacheQL is designed to make it easy to switch over from the Fetch API. All you have to do is replace the word fetch with the word hacheQL. The arguments to the function remain exactly the same.

For example, here's how you might send a GraphQL request using the Fetch API:

    fetch('/graphql', {
      method: 'POST',
      headers: { 'Content-Type': 'application/graphql' },
      body: '{ hero { name } }'
    })
    .then(/* code */)

And here's what that same request looks like using HacheQL:

    hacheQL('/graphql', {
      method: 'POST',
      headers: { 'Content-Type': 'application/graphql' },
      body: '{ hero { name } }'
    })
    .then(/* code */)

Simply replace fetch with hacheQL wherever the client-side code queries the GraphQL API, and you're done! You've set up HTTP caching for your GraphQL requests.

Other Stuff

Check out the Documentation for more sample usage, technical details, and ways to customize behavior.

If you'd like to contribute, read our Contributing Guide.

License

HacheQL is MIT Licensed.