Registry / devops / graphql-query-compress

graphql-query-compress

JSON →
library1.2.4jsnpmunverified

A lightweight utility (v1.2.4, last updated in 2019, no active release cadence) that compresses GraphQL query strings by removing unnecessary whitespace and comments. Key differentiator: minimal dependency, focuses solely on string compression without parsing the GraphQL AST, making it fast and suitable for reducing payload size over network. Ships built-in TypeScript declarations. Not to be confused with graphql-compress or graphql-query-complexity.

npm install graphql-query-compress
INSTALL
IMPORT
SIG · GRAPHQL-QUERY-COMP
G
graphql-query-compress
devopsjavascriptv1.2.4
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.

compress (default)
import compress from 'graphql-query-compress'
const { compress } = require('graphql-query-compress')
The package exports a default function. Named export does not exist. In CommonJS, use `const compress = require('graphql-query-compress').default` or enable esModuleInterop.
compress (CommonJS default)
const compress = require('graphql-query-compress').default
const compress = require('graphql-query-compress')
Without esModuleInterop, require returns an object with a default property. The direct require gives an object, not the function.
TypeScript import
import compress from 'graphql-query-compress'
import * as compress from 'graphql-query-compress'
TypeScript with esModuleInterop should use default import. Namespace import will give an object with default property.

Compresses a multiline GraphQL query string by removing whitespace and comments using the default export.

import compress from 'graphql-query-compress'; let query = `{ Accounts { id realname username } }`; query = compress(query); console.log(query); // Output: {Accounts{id realname username}}
Debug
Known issues
gotchaPackage was last updated in 2019 and may not support newer GraphQL syntax like `extend` or `@deprecated` comments? Work with most standard queries.
fix
Test with your query format; if it fails, consider using graphql-query-rewriter or a full parser like graphql-js's stripIgnoredCharacters.
affects: <=1.2.4
gotchaThe compress function removes all whitespace outside strings, including newlines, which may make debugging harder. It does not compress inside string literals.
fix
Use only for production network requests; keep original query for development.
affects: >=1.0.0
gotchaNo handling of GraphQL variables or fragments differently; it simply removes whitespace uniformly.
fix
Pre-parse or post-process if special handling is needed.
affects: >=1.0.0
deprecatedNo new releases since 2019; consider using `stripIgnoredCharacters` from graphql-js v15+ which is actively maintained.
fix
Migrate to `import { stripIgnoredCharacters } from 'graphql'` if using graphql-js.
affects: >=1.2.4
Errors
Common errors & fixes
TypeError: compress is not a function
Using require without accessing .default
fix
Use `const compress = require('graphql-query-compress').default` or enable esModuleInterop and use import.
Uncaught TypeError: compress is not a function
Importing as namespace instead of default
fix
Use `import compress from 'graphql-query-compress'` in ESM or TypeScript with esModuleInterop.
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
graphql-query-compress — npm install graphql-query-compress · libregistry