Registry / devops / graphql-min

graphql-min

JSON →
library1.0.1jsnpmunverified

A Babel plugin that minifies GraphQL queries written as tagged template literals at build time. Current version 1.0.1 removes unnecessary whitespace from gql template strings, transforming them into compact queries. The tool is simple and focused, with no runtime overhead since minification occurs during compilation. It is an alternative to other GraphQL minifiers like graphql-minify or custom babel transforms, but is extremely lightweight and easy to set up via .babelrc. The package is maintained with a low release cadence.

npm install graphql-min
INSTALL
IMPORT
SIG · GRAPHQL-MIN
G
graphql-min
devopsjavascriptv1.0.1
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.

gql
import gql from 'graphql-min'
import { gql } from 'graphql-min'
Default export; named import will fail.
gql
const gql = require('graphql-min').default
const gql = require('graphql-min')
CommonJS users must use .default because package uses ESM.
Babel plugin
"plugins": ["graphql-min/babel"]
"plugins": ["graphql-min"]
The plugin path must include '/babel' subpath.

Shows Babel configuration and a tagged template literal that gets minified at build time.

// .babelrc { "plugins": ["graphql-min/babel"] } // source.js import gql from 'graphql-min'; const query = gql` { foo { bar { baz } } } `; console.log(query); // Output: {foo{bar{baz}}}
Debug
Known issues
gotchaThe gql tag only works when Babel plugin is configured. Without the plugin, gql returns the original string unchanged (no minification).
fix
Ensure .babelrc includes 'graphql-min/babel' in plugins array.
affects: >=0.0.0
gotchaCommonJS require('graphql-min') returns an object with a default property, not the gql function directly.
fix
Use require('graphql-min').default instead.
affects: >=1.0.0
deprecatedNo deprecated patterns known, but the package is very simple and may lack advanced features like variable preservation.
fix
N/A
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Can't resolve 'graphql-min/babel'
Babel plugin path includes '/babel' but the package may not be installed correctly or resolvable.
fix
Install graphql-min with npm i graphql-min and ensure node_modules is accessible.
TypeError: (0 , _graphqlMin.default) is not a function
Using CommonJS require incorrectly (without .default).
fix
Change const gql = require('graphql-min') to const gql = require('graphql-min').default.
SyntaxError: Unexpected token, expected ","
Attempting to use named import { gql } which is not exported.
fix
Use default import: import gql from 'graphql-min'.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@babel/coreoptionalRequired at build time for Babel plugin transformation
Agent activity
4 hits · last 30 days
node
4
Resources
graphql-min — npm install graphql-min · libregistry