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

graphql-fetch-optimizer

v1.0.8

Published

Drop-in replacement for `fetch` that optimizes GraphQL requests

Readme

graphql-fetch-optimizer

graphql-fetch-optimizer is a drop-in replacement for nodejs fetch that optimizes GraphQL requests before they are executed

It lets you write queries without worrying about complex optims and it transparently improves how they're executed.

Features include automatic pagination, make all queries sequential (useful with Eleventy SSG), debug mode and more to come if you get involved too

Installation

npm install --save graphql-fetch-optimizer

Basic usage

In your build entry point (e.g. .eleventy.mjs or any JS file):

import { createPatchedFetch } from 'graphql-fetch-optimizer'
const patchedFetch = createPatchedFetch(fetch)

Then use the patchedFetch() function normally in your code.

Example

import { createPatchedFetch } from 'graphql-fetch-optimizer'
const patchedFetch = createPatchedFetch(fetch)
const res = await patchedFetch('https://cms.example.com/graphql', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: `{
      menus(first: "auto") {
        nodes { id label }
        pageInfo { hasNextPage endCursor }
      }
    }`
  })
})

const json = await res.json()
console.log(json.data.menus.nodes)

If the menus field contains more than one page of results, the optimizer will fetch all of them and return a merged result.

Mock mode

You can mock all calls to fetch in your code base:

import { createPatchedFetch } from 'graphql-fetch-optimizer'
globalThis.fetch = createPatchedFetch(globalThis.fetch)

API

Options for createPatchedFetch

| Option | Type | Default | Description | |----------------|-----------|-------------|-----------------------------------------------------------------------------| | sequential | boolean | false | If true, paginated root fields are fetched one after another instead of in parallel. Useful for underpowered CMS backends. | | autoKeyword | string | auto | The value used in first: ... arguments to trigger pagination. |

The returned function is a fully-compatible fetch replacement. You can assign it to global.fetch or use it directly.

Limitations

  • Only root-level fields with first: "auto" are paginated
  • Your schema must return nodes[] and pageInfo { hasNextPage, endCursor }
  • Nested pagination is not supported

Advanced usage

Use the core pagination logic manually:

import { fetchRootPaginatedFields } from 'graphql-fetch-optimizer/paginate.js'

const result = await fetchRootPaginatedFields(query, cursorVars, (query, variables) =>
  fetch('https://cms.example.com/graphql', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ query, variables })
  }).then(res => res.json())
)

Future ideas

This package is built to evolve as a general-purpose query optimizer. Possible additions:

  • Remove unused fragments
  • Warn on large or slow responses
  • Print query stats or execution plan
  • Add a minimum delay between calls

Project origin

Originally created for Silex no-code static site builder that generates GraphQL queries automatically from a no-code interface

It can also be used in any static generator that fetches GraphQL content at build time