Registry /
serialization / apollo-codegen-typescript
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
generate
✓ // Direct programmatic import is not recommended as this package is abandoned.
// Most users interacted via the Apollo CLI. If you absolutely must, it would be:
// import { generate } from 'apollo-codegen-typescript';
✗ const generate = require('apollo-codegen-typescript');
This package was primarily an internal module for the Apollo CLI. Direct programmatic use by end-users was uncommon and is highly discouraged due to its abandoned status. Apollo recommends `GraphQL Code Generator` instead.
Demonstrates the historical usage of the `apollo client:codegen` CLI command to generate TypeScript types from a GraphQL schema and operations, highlighting its deprecation.
/*
This quickstart demonstrates the historical usage of Apollo Codegen via the Apollo CLI.
This command and the underlying tooling are now deprecated and abandoned.
Recommended alternative: GraphQL Code Generator (https://www.graphql-code-generator.com/)
*/
// 1. Install the (now deprecated) Apollo CLI globally or locally
// npm install -g apollo@2 # Or use npx for one-off execution
// 2. Define your GraphQL schema (e.g., schema.graphql or introspect from a URL)
// For demonstration, let's create a dummy schema.graphql
// You would typically replace this with your actual schema.
// echo 'type Query { hello: String }' > schema.graphql
// 3. Define your GraphQL operations (e.g., in a .tsx or .graphql file)
// For this example, let's assume you have a query in src/MyComponent.tsx:
// import { gql } from '@apollo/client';
// const HELLO_QUERY = gql`query HelloQuery { hello }`;
// 4. Run the deprecated codegen command to generate TypeScript types
// This command assumes a schema.graphql file and operations in src/**/*.tsx
// It will output types to 'types' directory and a global types file.
npx apollo codegen:generate \
--localSchemaFile=schema.graphql \
--target=typescript \
--includes=src/**/*.tsx \
--tagName=gql \
--addTypename \
--globalTypesFile=src/types/global-types.ts \
types
console.log("If successful, TypeScript types for your GraphQL operations would be generated.");
console.log("Remember, this tool is deprecated. Migrate to GraphQL Code Generator.");
apollo --version
Debug
Known issues
breakingThe `apollo client:codegen` command, which was the primary way to use this module, has been officially deprecated. The entire `apollo-tooling` repository is in maintenance mode and slated for full deprecation.fixMigrate your code generation workflow to `GraphQL Code Generator`. This requires reconfiguring your project to use `graphql-code-generator` CLI and its plugins (e.g., `@graphql-codegen/cli`, `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations`).
affects: >=0.40.9 (and all versions of apollo-tooling)
gotchaThis package is no longer actively maintained. Security vulnerabilities and bug fixes are unlikely to be addressed. Using it in production environments is risky due to potential unpatched issues.fixTransition to actively maintained alternatives like `GraphQL Code Generator` to ensure security patches and ongoing support.
affects: >=0.40.9
gotchaCompatibility issues may arise with newer versions of Node.js, TypeScript, or the `graphql` library due to lack of updates. The package's last release (0.40.9) is from around 2020.fixUse `GraphQL Code Generator`, which is actively maintained and regularly updated to support the latest versions of GraphQL, TypeScript, and Node.js.
affects: >=0.40.9
Errors
Common errors & fixes
Error: Command 'codegen' is deprecated.
Attempting to use the `apollo codegen:generate` command from a recent or deprecated version of the Apollo CLI.
fixUpdate your `package.json` scripts to use `graphql-code-generator` CLI instead. Consult the GraphQL Code Generator documentation for migration guides.
Cannot find module 'apollo-codegen-typescript'
This package is an internal module of `apollo-tooling` and not intended for direct installation or import by most applications. It's likely you're trying to use it in a way it wasn't designed for, or it's simply not installed as a dependency.
fixAvoid direct imports. If you need GraphQL type generation, use `GraphQL Code Generator` and install its relevant packages (e.g., `@graphql-codegen/cli`).
TypeError: Cannot read property 'kind' of undefined
This error often occurs when the `apollo-codegen-typescript` module, or the `apollo` CLI, encounters an invalid or unexpected GraphQL schema or operation definition that it cannot parse, especially with newer GraphQL features it doesn't support.
fixEnsure your GraphQL schema and operation documents are valid. More importantly, migrate to `GraphQL Code Generator` to benefit from modern GraphQL spec support and active maintenance.
Audit
Dependencies
graphqlrequiredCore dependency for GraphQL schema parsing and type definition.
typescriptrequiredRequired to generate TypeScript output.