close
Skip to main content

GraphQL to TypeScript

GraphQL schemas describe types directly. The job is mapping SDL types to TypeScript and matching your client operations to the right subset. This guide compares the main tools and shows the workflow we recommend for production codebases.

Tooling landscape

Tool Approach Best for
GraphQL Code Generator Codegen at build time Apollo, urql, plain fetch — the broadest plugin ecosystem.
gql.tada Type-level inference from inline strings No codegen step; types fall out of template literals automatically.
Houdini Framework-integrated client + codegen SvelteKit and Solid Start projects.
Relay Compiler + runtime, Facebook-grade Big React apps where fragment-level data colocation matters.

Mapping SDL types to TypeScript

schema.graphql
type User {
  id: ID!
  name: String!
  email: String
  posts: [Post!]!
}

type Post {
  id: ID!
  title: String!
}
schema.ts (generated)
export interface User {
  id: string;
  name: string;
  email: string | null;
  posts: Post[];
}

export interface Post {
  id: string;
  title: string;
}

Notice the patterns: ! in SDL becomes non-nullable in TS, bare types become | null, and lists become arrays. Custom scalars (DateTime, JSON) need a mapping config.

Recommended workflow

  1. Install @graphql-codegen/cli and the typescript plugins.
  2. Create a codegen.ts pointing at your schema and operations.
  3. Generate operation-specific types alongside the schema types so each query gets a precise return type.
  4. Wire up codegen --watch during development, run once in CI.
  5. For runtime validation of mutation inputs, generate Zod schemas alongside — or feed the generated types through our TypeScript → Zod converter.

Related tools

Migrate the rest of your client

GraphQL types describe queries. JavaScriptConverter handles the JavaScript that calls them.