FormatterHQ

GraphQL to TypeScript Converter

Paste a GraphQL schema in SDL and get TypeScript interfaces, enums, unions and argument types, with control over how nullable fields are typed.

Input GRAPHQL
Output TYPESCRIPT
Ready.

How to use the GraphQL to TypeScript

  1. Paste your GraphQL schema (SDL) into the input panel.
  2. Choose how Enums and Nullable fields should be written.
  3. Toggle Nullable fields are optional, Generate argument types and Add __typename as needed.
  4. Copy the generated types into a .ts file in your project.

GraphQL to TypeScript: turn your schema into types

This GraphQL to TypeScript converter reads a schema written in the GraphQL Schema Definition Language (SDL) and generates matching TypeScript declarations. Object types, interfaces and input types become interface declarations, enums become string unions or TypeScript enums, and unions become union types. The schema is parsed with the reference graphql-js library, so syntax errors and unknown types are reported with a line and column.

What the converter produces

It targets the schema itself, not individual operations. That makes it a lightweight alternative to a full GraphQL Code Generator setup when you just need types for a resolver, a mock server or a quick prototype. Type descriptions written in triple quotes are kept as JSDoc comments, and deprecated fields get an @deprecated note.

Example

Input schema (an excerpt of the built-in sample, which also defines the Node and Order types that are referenced here):

"""A registered customer"""
type User implements Node {
  id: ID!
  email: String!
  name: String
  role: Role!
  orders(first: Int = 10): [Order!]!
  createdAt: DateTime!
}

enum Role {
  ADMIN
  CUSTOMER
}

scalar DateTime

Output for these types with the default options:

export type Scalars_DateTime = string;

export interface UserOrdersArgs {
  first?: number | null;
}

/** A registered customer */
export interface User extends Node {
  id: string;
  email: string;
  name?: string | null;
  role: Role;
  orders: Array<Order>;
  createdAt: Scalars_DateTime;
}

export type Role = 'ADMIN' | 'CUSTOMER';

Notice that ID maps to string, implements Node becomes extends Node, and the orders(first: Int) field produces a separate UserOrdersArgs interface.

Type mapping

GraphQLTypeScript
ID, Stringstring
Int, Floatnumber
Booleanboolean
[T!]!Array<T>
T (nullable)T | null or Maybe<T>, optionally with ?
Custom scalarA Scalars_Name alias: string for names containing Date or Time, unknown for JSON, any otherwise

Options explained

  • Enums as: string union types ('ADMIN' | 'CUSTOMER') have no runtime cost and work well with isolatedModules. TypeScript enums (enum Role { ADMIN = 'ADMIN' }) give you a runtime object you can iterate.
  • Nullable fields: T | null is explicit. Maybe<T> adds a Maybe helper type at the top, a convention familiar from GraphQL Code Generator.
  • Nullable fields are optional (?): marks nullable fields with ?, which matches responses where the field may be left out of the selection. Turn it off if every field is always present.
  • Generate argument types: creates a TypeFieldArgs interface for every field with arguments, handy for typing resolvers.
  • Add __typename: adds an optional __typename literal to each object type, which helps TypeScript narrow unions and interfaces.

Limitations

The tool converts schemas, not queries, so it does not create result types for a specific query { ... } selection. Argument default values such as first: Int = 10 appear only as an optional property, not as a value; a non-null argument or input field that has a default (limit: Int! = 20) is optional as well. Custom scalars get a placeholder alias you can edit, for example changing Scalars_Money from any to string. Directives other than @deprecated are ignored.

The Query and Mutation root types are generated like any other object type, which is useful for typing a resolver map.

Privacy

Your schema is parsed and converted in the browser; nothing is uploaded. To clean up the SDL before converting, run it through the GraphQL formatter. If you only have a sample JSON response, JSON to TypeScript infers types from data, and JSON Schema to TypeScript handles REST schemas.

Frequently asked questions

Can I generate types from a GraphQL query instead of the schema?
Not with this tool. It turns SDL type definitions into TypeScript. For per-operation result types, use GraphQL Code Generator with its typescript-operations plugin, or write a type that picks fields from the generated interfaces.
How do I get my schema as SDL?
Many servers expose it directly or through their tooling, for example Apollo Server or Hasura exports. You can also run an introspection query and convert the result with buildClientSchema and printSchema from graphql-js.
Should I use enums or string unions?
String unions are lighter: they disappear at compile time and work with any bundler setting. Use TypeScript enums when you need a runtime object, for example to list all values in a dropdown.
Why does it say "Unknown type" for my schema?
The schema must be complete: every type you reference has to be defined in the pasted SDL. Add the missing type, or declare it as scalar Name if it is a custom scalar from your server.
Does it support schema extensions and directives?
Type definitions, interfaces, unions, enums, inputs and custom scalars are supported. Directive usages other than @deprecated are accepted when declared but do not change the output.

Last updated October 3, 2026

Guides

Related tools

JSON Schema to TypeScript Turn JSON Schema into TypeScript interfaces and types with optional properties, enums, $ref definitions and JSDoc comments. JSON to TypeScript Generate TypeScript interfaces from a JSON sample instantly, with nested types detected automatically. XML to TypeScript Generate TypeScript interfaces from a XML sample instantly, with nested types detected automatically. TypeScript Formatter Format TypeScript code online with Prettier, including interfaces, generics, decorators and type annotations. JSON to C++ Generate C++ classes with nlohmann::json helpers from a JSON sample instantly, with nested types detected automatically. JSON to Crystal Generate Crystal classes with JSON mapping from a JSON sample instantly, with nested types detected automatically. JSON to C# Generate C# classes with JsonProperty attributes from a JSON sample instantly, with nested types detected automatically. JSON to Dart Generate Dart classes with fromJson and toJson from a JSON sample instantly, with nested types detected automatically. JSON to Elm Generate Elm type aliases with decoders from a JSON sample instantly, with nested types detected automatically. JSON to Flow Generate Flow Flow type definitions from a JSON sample instantly, with nested types detected automatically. JSON to Go Generate Go structs with json tags from a JSON sample instantly, with nested types detected automatically. JSON to Haskell Generate Haskell records with Aeson instances from a JSON sample instantly, with nested types detected automatically.