PureDevTools

GraphQL to TypeScript Converter

Convert GraphQL SDL to TypeScript — types, inputs, enums, unions, nullable fields

All processing happens in your browser. No data is sent to any server.

Options

596 characters

8 types generated · 830 characters

Types generated: 8Output size: 830 charsMode: interface · export

You have a GraphQL schema defining your API’s type system, and now you need TypeScript types for your client code or resolver implementations. Manually translating GraphQL types — with their nullable-by-default fields, custom scalars, union types, and input objects — to TypeScript interfaces is repetitive and diverges as the schema evolves.

What Is GraphQL to TypeScript Conversion?

GraphQL schemas define types using SDL (Schema Definition Language). TypeScript interfaces define the shape of JavaScript objects at compile time. Converting GraphQL SDL to TypeScript bridges your API’s type system and your application code, enabling type-safe queries, mutations, and resolver functions.

How This Converter Works

Paste GraphQL SDL and the tool generates TypeScript types:

  1. Object types: type User { ... }interface User { ... }
  2. Nullable fields: GraphQL fields are nullable by default. name: Stringname: string | null. Non-null name: String!name: string
  3. Input types: input CreateUserInput { ... }interface CreateUserInput { ... }
  4. Enums: enum Status { ACTIVE, INACTIVE }enum Status { ACTIVE = "ACTIVE", INACTIVE = "INACTIVE" }
  5. Union types: union SearchResult = User | Posttype SearchResult = User | Post
  6. Scalars: IDstring, Intnumber, Floatnumber, Booleanboolean, Stringstring
  7. Lists: [User!]!User[], [User](User | null)[] | null

Common Use Cases

Frontend query typing — Generate TypeScript types from your GraphQL schema to type-check query results in React, Vue, or Svelte components.

Resolver implementation — Use generated types for resolver return types and argument types in Apollo Server, Mercurius, or GraphQL Yoga.

SDK generation — Create typed SDK functions for your GraphQL API by combining generated types with query/mutation definitions.

Schema documentation — TypeScript interfaces serve as readable documentation of your GraphQL schema for team members unfamiliar with SDL.

Working with the Output

After generating, consider:

Frequently Asked Questions

Q: How are GraphQL custom scalars handled? A: Built-in scalars (String, Int, Float, Boolean, ID) are mapped to TypeScript primitives. Custom scalars like DateTime or JSON default to any — you should replace these with appropriate types after generation.

Q: Does this handle GraphQL interfaces? A: Yes. GraphQL interface types are converted to TypeScript interfaces. Types that implement a GraphQL interface extend the generated TypeScript interface.

Q: How are nullable and non-nullable fields different? A: In GraphQL, fields are nullable by default. name: String means the field can be null, generating name: string | null. Adding ! makes it non-null: name: String! generates name: string.

Q: Can I paste a full schema with Query and Mutation types? A: Yes. All types including Query, Mutation, and Subscription root types are converted. You can use the generated Query interface to type your resolver map.

Q: Is my schema sent to a server? A: No. All parsing and TypeScript generation happens entirely in your browser. Your GraphQL schema never leaves your device.

Related Tools

More Code Transforms