Registry / devops / graphql-compiler

graphql-compiler

JSON →
library1.7.0jsnpmunverified

graphql-compiler is a code-generation toolkit for GraphQL that transforms GraphQL queries and schemas into type-safe code for various target languages. Version 1.7.0 is the latest stable release, with infrequent updates. It differs from alternatives like graphql-codegen by focusing on compiler-level integrations (e.g., GraphQL Java, Python, or internal DSLs) rather than plugins. Peer dependency on graphql ^0.13.0 means it only works with older GraphQL.js, not modern versions. It supports ESM and CJS, but usage is limited due to the peerdep lock.

npm install graphql-compiler
INSTALL
IMPORT
SIG · GRAPHQL-COMPILER
G
graphql-compiler
devopsjavascriptv1.7.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.

compileQuery
import { compileQuery } from 'graphql-compiler'
const compileQuery = require('graphql-compiler').compileQuery
ESM-only since v1.0; CJS require may work but not recommended. Used for compiling a single query.
CompilerContext
import { CompilerContext } from 'graphql-compiler'
const CompilerContext = require('graphql-compiler').CompilerContext
Core class for managing compilation state. Must be instantiated with a GraphQL schema.
default
import graphqlCompiler from 'graphql-compiler'
const graphqlCompiler = require('graphql-compiler')
Default export is a namespace object containing all exports. ESM import is preferred.
IR
import type { IR } from 'graphql-compiler'
import { IR } from 'graphql-compiler'
TypeScript type import only; IR is not a runtime value.

Compiles a GraphQL query into a code representation using CompilerContext and compileQuery.

import { compileQuery, CompilerContext } from 'graphql-compiler'; import { buildSchema, printSchema } from 'graphql'; const schema = buildSchema(` type Query { hello: String } `); const context = new CompilerContext(schema); const query = ` query Greeting { hello } `; const compiled = compileQuery(context, query, { generateSourceMap: true }); console.log(compiled.source);
Debug
Known issues
breakinggraphql peer dependency is locked to ^0.13.0; does not work with graphql@15 or later.
fix
Use an older version of graphql or consider alternative code generators.
affects: >=1.0.0
gotchacompileQuery returns an object with 'source' property, not a function. Do not call it as a function.
fix
Access compiled.source to get the generated code string.
affects: all
deprecatedThe default export is deprecated in favor of named exports as of v1.5.0.
fix
Use named imports like import { compileQuery } from 'graphql-compiler' instead of default import.
affects: >=1.5.0
gotchaTypeScript type definitions may not be bundled; you may need to install @types/graphql-compiler separately.
fix
For TypeScript, install @types/graphql-compiler or use ts-ignore.
affects: <=1.6.0
Errors
Common errors & fixes
Cannot find module 'graphql-compiler'
Package not installed or missing from node_modules
fix
Run npm install graphql-compiler@1.7.0 graphql@0.13.0
Cannot read property 'source' of undefined
compileQuery returned undefined due to invalid query
fix
Ensure query is a valid GraphQL string and schema is built correctly.
Error: Cannot find module 'graphql/utilities/buildASTSchema'
Incompatible graphql version; requires graphql@0.13 specifically
fix
Install exact peer dependency: npm install graphql@0.13.0
TypeError: CompilerContext is not a constructor
Using default import instead of named import for CompilerContext
fix
Use import { CompilerContext } from 'graphql-compiler'
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for schema and query parsing; version must be ^0.13.0
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-compiler — npm install graphql-compiler · libregistry