Apollo Codegen TypeScript Generator

0.40.9 · abandoned · verified Sun Apr 19

Apollo Codegen TypeScript Generator is an internal module of the now-deprecated `apollographql/apollo-tooling` monorepo. Its primary function was to facilitate the generation of TypeScript types from GraphQL schemas and operation documents, predominantly via the `apollo client:codegen` CLI command. The package's last version, 0.40.9, was released around 2020. This package, and the `apollo` CLI commands it powered, are no longer actively maintained. Apollo has officially deprecated `apollo client:codegen`, directing users to adopt `GraphQL Code Generator` for type generation. This shift marks the end of its release cadence and dedicated support. Its key differentiator was its deep integration within the Apollo CLI ecosystem, providing a streamlined, opinionated approach to type generation for Apollo Client users. However, this opinionated nature also meant less flexibility compared to more customizable alternatives like `GraphQL Code Generator`.

Common errors

Warnings

Install

Imports

Quickstart

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.");

view raw JSON →