Registry / testing / parse-graphql

parse-graphql

JSON →
library1.0.0jsnpmunverified

A lightweight standalone parser for GraphQL queries, extracting the parse function from the full graphql library (which is 1.8MB) into a 70KB unminified package. Version 1.0.0 is stable with no recent updates; it throws GraphQLError on syntax errors and is ideal when you only need parsing without the full GraphQL ecosystem. It ships as CommonJS with no dependencies, but lacks TypeScript types and ESM support.

npm install parse-graphql
INSTALL
IMPORT
SIG · PARSE-GRAPHQL
P
parse-graphql
testingjavascriptv1.0.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.

parse
import { parse } from 'parse-graphql'
const parse = require('parse-graphql')
CommonJS requires destructuring: const { parse } = require('parse-graphql'). Direct require returns an object.
parse
const { parse } = require('parse-graphql')
const parse = require('parse-graphql').parse
Avoid chaining .parse after require; destructure or use const { parse } = require(...).
default import
import { parse } from 'parse-graphql'
import parse from 'parse-graphql'
There is no default export; only named export `parse`. ESM import must use braces.

Demonstrates parsing a simple GraphQL query into an AST document using the `parse` function.

import { parse } from 'parse-graphql'; const query = ` { user { name id } } `; const document = parse(query); console.log(JSON.stringify(document, null, 2)); // Output: {"kind":"Document","definitions":[...]}
Debug
Known issues
gotchaPackage does not include TypeScript type definitions.
fix
Create a `index.d.ts` declaration file manually or use `@types/parse-graphql` (unavailable). Consider using the full `graphql` package for TypeScript support.
affects: >=1.0.0
gotchaNo ESM build; package is CommonJS only. Cannot use `import` in Node without bundler or experimental flags.
fix
Use dynamic import: `const { parse } = await import('parse-graphql')` or transpile with bundler. Alternatively, set `"type": "module"` in package.json and use `.cjs` extension for CommonJS.
affects: >=1.0.0
deprecatedThe full `graphql` package is actively maintained with more features (validation, execution, etc.). This package is a minimal subset and may lag behind.
fix
For new projects, consider using `graphql` directly (import { parse } from 'graphql') if bundle size is not critical. For size-sensitive environments, this package is still fine.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: parse is not a function
Using default import instead of named import: `import parse from 'parse-graphql'`
fix
Use named import: `import { parse } from 'parse-graphql'`
SyntaxError: Unexpected token 'export'
Using ES module import syntax in a CommonJS file without proper configuration.
fix
Either rename file to `.mjs` or set `"type": "module"` in package.json, or transpile with Babel/TypeScript.
Cannot find module 'parse-graphql'
Package not installed, or typo in import path.
fix
Install: `npm install parse-graphql` and verify import path: `import { parse } from 'parse-graphql'`
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
parse-graphql — npm install parse-graphql · libregistry