GraphQL to TypeScript

Generate TypeScript types from a GraphQL schema (SDL).

GraphQL to TypeScript converts a GraphQL schema written in SDL into TypeScript types. It maps the built-in scalars (String and ID to string, Int and Float to number, Boolean to boolean), respects nullability so a non-null field (Type!) is required while a nullable field becomes optional and unioned with null, turns lists into arrays, and emits enums as string-literal unions. type, input, and interface definitions all become interfaces.

  • Scalar mapping: String/ID → string, Int/Float → number
  • Nullability: Type! is required; nullable fields become optional | null
  • Lists become arrays; enums become string-literal unions
  • 100% private — nothing is uploaded

How Nullability Maps

GraphQL fields are nullable by default, and a trailing ! marks them non-null. This tool mirrors that in TypeScript: name: String! becomes a required name: string, while name: String becomes name?: string | null. A list like [String!]! becomes string[]. To go the other direction — from a JSON payload to a schema — see JSON to TypeScript.

Scalar Mapping Reference

GraphQLTypeScriptNotes
StringstringAlso used for ID
IDstringGraphQL's opaque identifier scalar
IntnumberAlso used for Float
FloatnumberNo separate integer/float distinction in TS
Booleanboolean
Custom scalar (e.g. DateTime)DateTime (kept as-is)Define your own type alias, e.g. type DateTime = string
enum Role { ADMIN MEMBER }"ADMIN" | "MEMBER"String-literal union

How to Use It

  1. 1Paste your GraphQL schema (SDL) — type, input, interface, and enum definitions are all recognized.
  2. 2Click Convert — each definition becomes its own TypeScript interface or type alias, with field nullability preserved exactly as declared.
  3. 3Copy the output into your project. Because it's derived straight from the SDL, the types always match what your GraphQL server actually accepts and returns.
  4. 4For a full pipeline including generated query/mutation types, pair this with a dedicated GraphQL codegen tool — this converter focuses on the object/input/enum type layer.

Common Uses

  • Typing GraphQL responsesGenerate interfaces for the object types your queries return so client code is type-safe.
  • Input variablesTurn input types into TypeScript so mutation variables are checked at compile time.
  • Shared schema typesProduce a base set of types from your SDL to build query-specific types on top of.
  • Learning the mappingSee how GraphQL scalars, nullability, and lists translate into TypeScript.
  • Reviewing a schema changeRegenerate types after an SDL edit and diff them against your previous types to see exactly what changed for consumers.

Frequently Asked Questions

It converts object types, input types, and interfaces into TypeScript interfaces, and enums into string-literal union types. Field arguments and directives are ignored for the output type.

A non-null field (Type!) becomes a required property. A nullable field becomes optional and unioned with null (field?: T | null), matching GraphQL's default-nullable behavior.

Built-in scalars map to string, number, or boolean. Custom scalars keep their name, so you can define a type alias (for example type DateTime = string) for them.

No. Parsing and conversion run entirely in your browser. Nothing is sent to a server.

No — it converts the object/input/interface/enum type definitions from your SDL. Query- and mutation-specific result types are typically generated by a dedicated GraphQL codegen tool that also reads your .graphql query documents.

Interfaces are converted into TypeScript interfaces the same way object types are, since both describe a named shape of fields — implementing types would extend or intersect with them in your own code as needed.

Related Tools