Registry / storage / graphql-crunch

graphql-crunch

JSON →
library2.2.0jsnpmunverified

Version 2.2.0. Normalizes GraphQL responses by flattening the object hierarchy into an array and deduplicating repeated values, reducing raw payload size (e.g., 76% reduction on Banter.fm) and improving JSON parse speed on mobile. Supports any GraphQL client (Apollo, Relay, etc.) via lossless crunch/uncrunch functions. Ships TypeScript types. Actively maintained.

npm install graphql-crunch
INSTALL
IMPORT
SIG · GRAPHQL-CRUNCH
G
graphql-crunch
storagejavascriptv2.2.0
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.

crunch
import { crunch } from 'graphql-crunch'
const crunch = require('graphql-crunch')
ESM-only; default export does not exist.
uncrunch
import { uncrunch } from 'graphql-crunch'
const uncrunch = require('graphql-crunch').uncrunch
ESM-only; use named import.
CrunchOptions
import type { CrunchOptions } from 'graphql-crunch'
import { CrunchOptions } from 'graphql-crunch'
Type import only; not a runtime value.

Demonstrates crunching and lossless uncrunching of a GraphQL response object.

import { crunch, uncrunch } from 'graphql-crunch'; const original = { data: { allPeople: { people: [ { name: 'Luke Skywalker', gender: 'male' }, { name: 'Leia Organa', gender: 'female' } ] } } }; const crunched = crunch(original); console.log(JSON.stringify(crunched)); // Output: flattened array with references const restored = uncrunch(crunched); console.log(JSON.stringify(restored)); // Matches original exactly
Debug
Known issues
gotchaThe crunched output is not valid JSON for direct API response unless the consumer uses uncrunch on the client.
fix
Always call uncrunch on the client to restore the original object.
affects: >=1.0.0
deprecatedDefault export was removed in v2.0.0; use named exports instead.
fix
Replace `import graphqlCrunch from 'graphql-crunch'` with `import { crunch, uncrunch } from 'graphql-crunch'`.
affects: >=2.0.0
gotchaObjects with circular references will throw an error during crunch.
fix
Ensure the input object has no circular dependencies or use a custom replacer to remove cycles.
affects: >=1.0.0
breakingNode.js v10 and older are no longer supported in v2.0.0.
fix
Upgrade Node.js to v12 or later.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-crunch'
Package not installed or wrong import path in CommonJS.
fix
Install via `npm install graphql-crunch` and use ESM import `import { crunch } from 'graphql-crunch'`.
TypeError: (0 , graphql_crunch.crunch) is not a function
Using default import in v2 when no default export exists.
fix
Use named import: `import { crunch } from 'graphql-crunch'`.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
22
Resources
graphql-crunch — npm install graphql-crunch · libregistry