DevTools Logo

GraphQL SDL to TypeScript

GraphQL SDL to TypeScript

Paste a schema and get interfaces, enums, unions and inputs — every mapping rule visible.

Runs in your browser
Try an example

GraphQL schema

26 line(s)
Scalar mappings
Options

types.ts

3 interfaces · 1 enums · 1 unions

2 types · 1 inputs · 1 enums · 1 scalars

Examples

Nullable fields

Input
type Person { id: ID!, name: String }
Output
interface Person { id: string; name: string | null; }

GraphQL nullability maps directly to TypeScript unions.

Const enum

Input
enum Role { ADMIN USER }
Output
type Role = 'ADMIN' | 'USER'; const RoleEnum = { ADMIN: 'ADMIN', USER: 'USER' } as const;

Use the const object for exhaustive lookup tables.

Inputs

Input
input Filter { limit: Int = 10 }
Output
interface Filter { limit?: number; }

Nullable and defaulted input fields are optional in generated variable types.

About this tool

GraphQL SDL to TypeScript compiles a pasted schema into a types.ts file without a codegen config, package install or build step. Object types and inputs become interfaces, enums become string unions with optional const objects, and unions and interfaces get their own type aliases.

The nullability matrix is handled explicitly: String! becomes string, String becomes string | null, and each of the four list/NonNull combinations gets the matching Array<T> shape. Field arguments are emitted as separate Args interfaces with optional defaults.

Custom scalars are mapped through an editable table (DateTime, JSON, Long, Upload and more), and options add name prefixes, __typename discriminants, exported declarations and @deprecated JSDoc. Parse errors show line and column, while unresolved references are reported instead of hidden.

What this tool does not do

  • The parser covers common type-system definitions; exotic directive definitions, schema extension edge cases and executable documents are out of scope.
  • Semantic schema validation (interface field compatibility, directive usage, reserved names) is not performed; the emitter reports unresolved type references only.
  • The tool does not generate resolvers, operation result types or client hooks; it emits declaration-only TypeScript.
  • Names that collide with TypeScript keywords get an underscore suffix, which does not rename any external code that uses the original name.

How to use this tool

  1. Paste SDL

    Start with the kitchen-sink example or paste any schema containing types, inputs, enums, unions, interfaces, scalars and schema blocks.

  2. Map scalars

    Edit the scalar table to turn custom scalars into string, number, unknown or any TypeScript type your project uses.

  3. Choose options

    Add a prefix or suffix to avoid collisions, enable discriminants for tagged unions, or turn off const enum objects and exports.

  4. Review diagnostics

    Fix positioned parse errors in the SDL pane and check the unresolved-reference list for types outside the pasted snippet.

  5. Copy types.ts

    Copy the generated source or download it directly into your project.

Use cases

Third-party APIs

Paste a vendor's public SDL and get types for a quick integration.

Teaching mapping rules

Show how nullability, lists and enums translate into TypeScript.

Sharing types

Give non-GraphQL consumers a plain types.ts file derived from the schema.

Ad-hoc codegen

Skip a codegen project when you only need types for a small snippet.

SDL to TypeScript mapping

SDLTypeScript
String!string
Stringstring | null
[String!]!Array<string>
[String]!Array<string | null>
enum Role { ADMIN }type Role = 'ADMIN'; + RoleEnum
field(arg: Int = 5)interface XFieldArgs { arg?: number }
union A = B | Ctype A = B | C

Interfaces implementers extend the base interface; in tagged mode a helper XUnion type narrows polymorphic fields.

Common mistakes

Mistake:Expecting full graphql-js schema validation.

Fix:This is a zero-dependency SDL subset scanner; run graphql-js validation in your build pipeline for semantic checks.

Mistake:Treating unresolved references as generated types.

Fix:Review the unresolved-reference warning and paste the missing definitions or map the scalar.

Mistake:Using a scalar name without adding a mapping.

Fix:Add a row in the scalar table; unmapped scalars fall back to unknown on purpose.

Mistake:Forgetting that nullable input fields are emitted as optional.

Fix:That matches codegen defaults; use ! in SDL when a variable must be present.

Frequently asked questions

Does it need a config file or an npm install?

No. Paste SDL into the left pane and the TypeScript appears on the right. Everything runs in the browser with no build step, so it works for ad-hoc schemas and vendor snippets.

How are custom scalars mapped?

Use the scalar mapping table. Built-ins default to string, number and boolean, and common customs such as DateTime, JSON, Long and Upload have editable rows. An unmapped custom scalar is emitted as unknown and listed as a warning.

How are interfaces and unions emitted?

Implementing object types extend the base interface, and a helper XUnion type lists the implementers. Unions become type aliases; with discriminants enabled each member is intersected with a literal __typename so TypeScript can narrow it.

Are nullable fields handled correctly?

Yes. Non-null fields map to T, nullable fields to T | null, and the four list/NonNull combinations map to Array<T>, Array<T | null> and their nullable forms. Nullable input fields and fields with defaults are optional properties.

Can it generate resolvers types?

Not yet. The tool emits declaration-only types: interfaces, aliases, const enum objects and argument interfaces. Resolver signatures, operation result types and client hooks remain in graphql-codegen territory.

What happens when the schema references a missing type?

Generation continues, the unknown reference is emitted as unknown, and the unresolved-reference warning lists the names. Paste the missing definitions or map the scalar to get a complete result.

Is my schema uploaded anywhere?

No. Parsing and emission happen entirely in your browser tab; no network request is made and the generated code is inert text.

References & standards