Registry / devops / graphql-fetch-optimizer

graphql-fetch-optimizer

JSON →
library1.0.11jsnpmunverified

Drop-in replacement for nodejs fetch that optimizes GraphQL requests by automatically handling pagination for root-level fields with `first: "auto"`. Version 1.0.11, maintained infrequently. Unlike generic fetch wrappers, it specifically merges paginated results transparently, supports sequential fetch mode (useful for underpowered CMS backends), and includes debug capabilities. Works only with schemas providing `nodes` and `pageInfo { hasNextPage, endCursor }`.

npm install graphql-fetch-optimizer
INSTALL
IMPORT
SIG · GRAPHQL-FETCH-OPTI
G
graphql-fetch-optimizer
devopsjavascriptv1.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createPatchedFetch
import { createPatchedFetch } from 'graphql-fetch-optimizer'
const { createPatchedFetch } = require('graphql-fetch-optimizer')
Package is ESM-only; CJS require will error.
fetchRootPaginatedFields
import { fetchRootPaginatedFields } from 'graphql-fetch-optimizer/paginate.js'
import { fetchRootPaginatedFields } from 'graphql-fetch-optimizer'
This is a separate export from a subpath; must include '/paginate.js'.
default import
import gqlFetch from 'graphql-fetch-optimizer'
const gqlFetch = require('graphql-fetch-optimizer')
Default export is not provided; only named exports. This pattern will break.

Patches fetch to automatically paginate GraphQL root fields marked with first: 'auto'.

import { createPatchedFetch } from 'graphql-fetch-optimizer' const patchedFetch = createPatchedFetch(fetch) const query = `{ menus(first: "auto") { nodes { id label } pageInfo { hasNextPage endCursor } } }` const res = await patchedFetch('https://api.example.com/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query }) }) const json = await res.json() console.log(json.data.menus.nodes)
Debug
Known issues
gotcha$varUsage is used in a context where it may not be defined
fix
Define $varUsage variable before using it.
affects: >=1.0.0
gotchaOnly root-level fields with first: 'auto' are paginated
fix
Ensure your query uses first: 'auto' on root fields; nested pagination is not supported.
affects: >=1.0.0
breakingPackage is ESM-only since v1.0.0; CommonJS require will fail
fix
Use import instead of require, or ensure your project is configured for ESM.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package
fix
Change to import syntax or set { "type": "module" } in package.json.
Cannot find module 'graphql-fetch-optimizer/paginate'
Missing '.js' extension in import path
fix
Use 'graphql-fetch-optimizer/paginate.js' instead of 'graphql-fetch-optimizer/paginate'.
TypeError: createPatchedFetch is not a function
Default import when only named export exists
fix
Use import { createPatchedFetch } from 'graphql-fetch-optimizer'.
Upgrade
Version history
1.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
graphql-fetch-optimizer — npm install graphql-fetch-optimizer · libregistry