GraphQL Schema to TypeScript

Converts GraphQL SDL (types, inputs, interfaces, enums, unions, scalars and descriptions) into TypeScript interfaces and types. Nullable output fields become "T | null" and nullable inputs optional.

Use the tool

Why this tool exists

Code generators for GraphQL are powerful but need a config file, a build step and often a running server. When you only want the types for a quick script, a front-end mock or a code review, that is heavy. Paste the schema here and get TypeScript out. Interfaces are inlined into the types that implement them, enums can be emitted as TypeScript enums or string unions, and descriptions are kept as comments. Query and Mutation root types are skipped unless you ask for them, and field arguments are ignored, so this produces data shapes, not operation types. For a production project you probably still want a full codegen tool. Your schema is processed in your browser.

How to use it

  1. Paste your GraphQL SDL into the input box.
  2. Tick the options to include Query, Mutation and Subscription types, or to emit TypeScript enums.
  3. Copy the generated TypeScript into your project.

Frequently asked questions

How are nullable fields typed?

Output fields that can be null become "T | null". Nullable input fields become optional properties. Non-null fields are required.

What happens to interfaces and unions?

Interface fields are inlined into each implementing type, and unions become TypeScript union types of the member types.

Are field arguments or operations typed?

No. Arguments are ignored, and Query, Mutation and Subscription roots are skipped by default. The tool outputs the shapes of data, not variables for operations.

What do custom scalars become?

Custom scalars have no known representation, so they are typed as string by default. Replace them with your own types where needed.