Registry / devops / gqlmin

gqlmin

JSON →
library0.3.2jsnpmunverified

gqlmin is a lightweight (<1 kB, ~3.4 kB gzip with dependency) GraphQL query minifier that removes insignificant whitespace and comments from GraphQL queries. Version 0.3.2 is current, stable, and maintained. It offers both a runtime ESM API and a CLI for build-time use. Unlike alternatives that bundle validation, gqlmin prioritizes minimal size and performance, assuming queries are pre-validated. It's ideal for reducing payload size in large GraphQL apps or optimizing GET requests for caching.

npm install gqlmin
INSTALL
IMPORT
SIG · GQLMIN
G
gqlmin
devopsjavascriptv0.3.2
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.

default
import gqlmin from 'gqlmin'
const gqlmin = require('gqlmin')
ESM-only; CJS require will fail. Use dynamic import() in CommonJS environments.
gqlmin
import gqlmin from 'gqlmin'
const gqlmin = require('gqlmin').default
There is no named export; only a default export. Do not destructure.
Type declarations
import gqlmin from 'gqlmin'
TypeScript types are bundled; no separate @types/ package needed.

Minifies a GraphQL query by stripping whitespace and comments, using the default import from gqlmin.

import gqlmin from 'gqlmin'; const query = ` query allProducts { products { name price image { medium large } } } `; const minified = gqlmin(query); console.log(minified); // query allProducts{products{name price image{medium large}}}
Debug
Known issues
breakinggqlmin is ESM-only and cannot be required via CommonJS require().
fix
Use dynamic import(): const gqlmin = await import('gqlmin');
affects: >=0.1.0
gotchagqlmin does not validate GraphQL; malformed queries may produce incorrect output silently.
fix
Validate queries with a GraphQL validator before minifying.
affects: all
gotchaMinifies even if query is a fragment or contains comments; comments are removed, not preserved.
fix
Ensure comments are not needed after minification.
affects: all
gotchaThe library bundles Moo tokenizer as a dependency, adding ~3.4 kB gzip; tree-shaking may not remove it.
fix
Consider if the size overhead is acceptable for your use case.
affects: all
gotchaCLI usage via npx may have different behavior on Windows due to path handling.
fix
Use forward slashes or escape paths appropriately.
affects: all
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/gqlmin/index.js from /path/to/app.js not supported.
Trying to require() the ESM-only package in a CommonJS environment.
fix
Use dynamic import: const gqlmin = await import('gqlmin');
Uncaught TypeError: gqlmin is not a function
Using a named import (e.g., import { gqlmin } from 'gqlmin') instead of default import.
fix
Use: import gqlmin from 'gqlmin';
SyntaxError: Unexpected identifier at position X in the minified output.
Input GraphQL query is malformed; gqlmin does not validate and produces incorrect output.
fix
Pre-validate the GraphQL query with a parser like graphql's parse() before minifying.
Cannot find module 'moo' or 'moo' not found.
Moo dependency missing, possibly due to flat node_modules or incorrect install.
fix
Run: npm install gqlmin (will install moo as a dependency).
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
moorequiredTokenizer dependency for parsing GraphQL queries
Agent activity
6 hits · last 30 days
node
6
Resources
packagegqlmin
gqlmin — npm install gqlmin · libregistry