Registry / devops / graphql-codegen-core

graphql-codegen-core

JSON →
library0.18.2jsnpmunverified

Core package for GraphQL Code Generator (v0.18.2), a tool that generates TypeScript/Flow types, React hooks, and other code from GraphQL schemas and operations. Stable release; moderate release cadence. Differentiator: plugin-based architecture supporting multiple frameworks (Apollo, URQL, etc.) and languages, with customizable outputs for resolvers, client-side operations, and introspection. Compared to alternatives (e.g., Apollo CLI), it offers broader plugin ecosystem and plugin-specific granularity.

npm install graphql-codegen-core
INSTALL
IMPORT
SIG · GRAPHQL-CODEGEN-CO
G
graphql-codegen-core
devopsjavascriptv0.18.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.

generate
import { generate } from 'graphql-codegen-core';
const generate = require('graphql-codegen-core');
ESM default import is typical; CJS require works but may cause issues with dynamic imports in plugins.
CodegenContext
import { CodegenContext } from 'graphql-codegen-core';
import CodegenContext from 'graphql-codegen-core';
TypeScript type: exported as named export, not default.
Types
import { Types } from 'graphql-codegen-core';
import { Types } from 'graphql-codegen-core/src/types';
Types namespace is a named export; don't use deep imports.

Generates TypeScript types from a GraphQL schema using the typescript plugin.

import { generate } from 'graphql-codegen-core'; import { buildSchema } from 'graphql'; const schema = buildSchema(` type Query { hello: String } `); const docs = []; async function main() { const output = await generate({ schema: schema, documents: docs, filename: 'types.ts', plugins: [ { 'typescript': {} } ], pluginMap: { 'typescript': await import('@graphql-codegen/typescript') } }); console.log(output[0].content); } main().catch(console.error);
Debug
Known issues
breakingv0.18 changed the generate function signature: now takes a single config object instead of multiple arguments.
fix
Use `generate({ schema, documents, filename, plugins, pluginMap })` instead of `generate(schema, documents, plugins)`.
affects: >=0.18.0
deprecatedThe `require('graphql-codegen-core')` CJS import is discouraged; ESM is preferred and will be required in future releases.
fix
Use ES module import syntax: `import { generate } from 'graphql-codegen-core'`.
affects: >=0.18.0
gotchaPlugin map must be explicitly provided; plugins from `@graphql-codegen/*` are not auto-loaded.
fix
Always pass a `pluginMap` object with resolved plugin modules (e.g., `{typescript: await import('@graphql-codegen/typescript')}`).
affects: >=0.10.0
breakingIn v0.16, the `generate` function required `filename` property, but in v0.15 it was optional.
fix
Always include `filename` in the config object; it is now mandatory.
affects: >=0.16.0
Errors
Common errors & fixes
Cannot find module '@graphql-codegen/typescript'
Missing dependency for the plugin.
fix
Install the plugin: `npm install -D @graphql-codegen/typescript`
Error: Schema must be a `GraphQLSchema` object or a string.
Passing invalid schema type (e.g., undefined, or an object without introspection).
fix
Ensure schema is built with `buildSchema` or from an introspection result. Example: `buildSchema(fs.readFileSync('schema.graphql', 'utf8'))`
Error: The "path" argument must be of type string.
`filename` property is not a string or is missing.
fix
Provide a valid string to `filename` in the generate config object.
Upgrade
Version history
0.18.2latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency: required at runtime for schema and document processing.
Agent activity
14 hits · last 30 days
node
12
Resources
graphql-codegen-core — npm install graphql-codegen-core · libregistry