Developer and Text Tools

How to Generate TypeScript Types from a GraphQL Schema in Seconds

Paste SDL or an introspection result and get TypeScript types, enums, argument types and exact query result types, without installing a code generator.

Saizul Amin
Saizul Amin19 Nov 2026 · 4 min read
How to Generate TypeScript Types from a GraphQL Schema in Seconds

How to Generate TypeScript Types from a GraphQL Schema in Seconds

GraphQL tells you the exact shape of every response, and TypeScript can enforce it, but only if the types exist. Large projects run a code generator at build time. For a script, a small app, a prototype or a review of someone else's API, installing and configuring that toolchain is often more work than the task. The free GraphQL Schema to TypeScript Types Generator parses the schema in your browser and writes the types immediately.

Step 1: get the schema

You need the schema in one of two forms.

  • SDL, the schema definition language, is the text with type, input, enum and union definitions that many servers keep in a schema.graphql file.
  • An introspection result is the JSON a GraphQL server returns for the standard introspection query. Most GraphQL IDEs can save it, and many APIs publish it.

Paste either into the schema box or open the file. The generator recognises JSON by its first character and converts it; it also shows the equivalent SDL, which you can download for documentation or diffing.

Step 2: decide how the types should look

The options mirror the choices most teams make in their code generator config.

  • Enums as string unions are the lightest choice and work well with JSON. TypeScript enums give a named value per member. Const objects combine both: a frozen object for runtime use and a type for checking.
  • A Scalars map collects ID, String, Int, Float, Boolean and your custom scalars in one place, so you can change DateTime from string to Date later without touching every type.
  • Maybe and InputMaybe helpers keep nullability readable; switch them off to see plain T | null.
  • Optional markers on nullable fields match how most clients treat missing data.
  • __typename fields help with unions and caches; readonly protects data from accidental mutation.

Custom scalars are listed one per line, such as DateTime: string or Money: number. Scalars you do not list fall back to unknown, string or any, whichever you choose.

Step 3: add the operations you use

Schema types describe everything the server can return; your app receives only what it asks for. Paste your queries, mutations, subscriptions and fragments into the operations box and the generator writes a result type and a variables type for each, following the selection exactly. Aliases become the property names, nested selections become nested objects, fragment spreads are merged in, and nullable fields stay nullable.

The part that saves the most time is abstract types. When a query selects on an interface or a union with inline fragments, such as search results that can be a user or a product, the result becomes a union of one object shape per possible type, each with a literal __typename. TypeScript then narrows the type as soon as your code checks __typename.

Step 4: fix what the generator reports

Because it reads both the schema and the operations, the generator can catch mistakes before your build does. It reports syntax errors with line and column, unknown types in the schema, interfaces that are not interfaces, union members that are not objects, fields that do not exist on a type, objects selected without subfields, scalars selected with subfields, unknown fragments and variables of unknown types. Each message names the line, so a typo such as displayNmae is a one-second fix.

A worked example

A shop schema has User, Order, OrderItem and Product types, a Node interface, a SearchResult union of User and Product, Role and OrderStatus enums, inputs for placing an order and the custom scalars DateTime and Money. With the default options the output starts with the Maybe helpers and a Scalars map where DateTime is string and Money is number. Role becomes a union of three string literals, the orders field gets a UserOrdersArgs type with first and status, and NewOrderInput has a required items list and an optional note. The Search query, which selects __typename with inline fragments on User and Product, becomes an array of two discriminated shapes, and the PlaceOrder mutation gets a variables type with a required input.

When to use a build-time generator instead

For a large codebase with hundreds of operations, a generator in the build pipeline keeps types in sync automatically and can also produce client hooks and resolver signatures, which this tool does not write. The two work well together: use the browser generator to explore an API, check a schema change in a pull request or produce types for a one-off script, and keep the pipeline for the main app.

Privacy and saving

Schemas often describe internal systems. Parsing happens in the page and the endpoint is never contacted. Save the project to keep the schema, operations and options, then copy the output or download a .ts or .d.ts file.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages