GraphQL Codegen Compiler (legacy v0.x)
raw JSON → 0.13.0 verified Fri May 01 auth: no javascript deprecated
This package is the legacy compiler engine for GraphQL Code Generator v0.x, used to process GraphQL schemas and generate TypeScript types, React hooks, or other artifacts. The current stable version is 0.13.0, which is part of the now-deprecated v0.x line. It was replaced by `@graphql-codegen/cli` and `@graphql-codegen/plugin-helpers` in GraphQL Code Generator v1+, which introduced a new plugin-based architecture. This compiler is not compatible with v1+ plugins and should not be used in new projects. Key differentiator: it is a monolithic compiler that takes a schema and outputs code through a single pipeline, unlike the modular v1+ system that uses independent plugins.
Common errors
error TypeError: compiler.compile is not a function ↓
cause Default import does not include the compile function; likely used `const { compile } = require('graphql-codegen-compiler')` which returns the default class, not an object.
fix
Use
const GraphQLCodegenCompiler = require('graphql-codegen-compiler'); then call new GraphQLCodegenCompiler().compile(...). error Error: Cannot find module 'graphql-codegen-compiler' ↓
cause Package is not installed, or installed but Node.js cannot resolve it (e.g., ESM package required import).
fix
Run
npm install graphql-codegen-compiler graphql@14 and use import syntax (ESM) or const X = require('graphql-codegen-compiler').default (CJS fallback). error TypeError: schema is not a valid GraphQL schema ↓
cause Passed a schema string or document node instead of a GraphQLSchema object.
fix
Use
buildSchema() from 'graphql' to convert your schema definition to a GraphQLSchema object before passing to compile. Warnings
deprecated graphql-codegen-compiler is deprecated. Use @graphql-codegen/cli and @graphql-codegen/plugin-helpers instead. ↓
fix Migrate to GraphQL Code Generator v1+ using `@graphql-codegen/cli` and the appropriate plugins (e.g., `@graphql-codegen/typescript`).
breaking The 'compile' method signature changed between minor versions; 'plugins' option is now required. ↓
fix Always provide an array for the 'plugins' option, even if empty.
gotcha This package does not support GraphQL v15+ validation rules correctly; use graphql@14 for consistent behavior. ↓
fix Pin graphql@14 as a dependency when using this compiler.
Install
npm install graphql-codegen-compiler yarn add graphql-codegen-compiler pnpm add graphql-codegen-compiler Imports
- default (GraphQLCodegenCompiler) wrong
const { GraphQLCodegenCompiler } = require('graphql-codegen-compiler');correctimport GraphQLCodegenCompiler from 'graphql-codegen-compiler'; - CompilerOptions wrong
import { CompilerOptions } from 'graphql-codegen-compiler';correctimport type { CompilerOptions } from 'graphql-codegen-compiler'; - compile wrong
import GraphQLCodegenCompiler, { compile } from 'graphql-codegen-compiler';correctimport { compile } from 'graphql-codegen-compiler';
Quickstart
import GraphQLCodegenCompiler from 'graphql-codegen-compiler';
import { buildSchema } from 'graphql';
const schema = buildSchema(`
type Query {
hello: String
}
`);
const compiler = new GraphQLCodegenCompiler();
const result = compiler.compile(schema, {
output: 'typescript',
plugins: [],
documents: '',
config: { namingConvention: 'keep' }
});
console.log(result);