01What is GraphQL to TypeScript?
You have a GraphQL schema and a TypeScript front end, and you want the two to agree on shapes. Full codegen pipelines do this well, but sometimes you just need the types now. Paste SDL into this converter and it writes one TypeScript declaration per definition it recognises. The first pass cleans the input. Triple-quoted and single-line descriptions, # comments and directives such as @deprecated or @key are stripped. After that, enums, scalars and unions are handled, then type, input and interface blocks. Each of those blocks becomes an export interface. A clause like implements Node & Timestamped turns into extends Node, Timestamped. Enums become string enums where each member maps to its own name. Custom scalars become type aliases of string. Unions become TypeScript union types, and the multi-line form that starts each member with a pipe works too. The built-in scalars follow the GraphQL spec's meaning: String and ID map to string, Int and Float to number, Boolean to boolean. Nullability is where hand-written types usually go wrong. The GraphQL spec says a field without ! can come back as null, so the tool makes it optional and adds | null. That matches the default output style of GraphQL Code Generator. Lists are resolved from the inside out. [Post!]! becomes Post[], while [Post] becomes (Post | null)[] | null. Here is a quick run we did. The input was interface Node { id: ID! } plus type Book implements Node & Timestamped with a field pages(first: Int = 10): [[Int!]]! and a field old: String @deprecated. The output was export interface Book extends Node, Timestamped, with id: string, pages: (number[] | null)[] and old?: string | null. The argument list on pages disappeared, as did the directive. That example also shows the limits. Field arguments are dropped, including ones spread over several lines. Default values on input fields are ignored, so age: Int = 18 still becomes age?: number | null. The tool does not check that Timestamped exists. Output is grouped by kind (enums, scalars, unions, then interfaces) instead of following your source order. Schema extensions, query documents and fragments are not handled. If nothing matches, you get an error listing the keywords it expects. The schema text never leaves your tab. Parsing is a set of regular expressions running in the page script, so there is no upload and no account.
Front-end and full-stack developers on GraphQL projects use it when they need TypeScript types from an SDL file without setting up a codegen build step. The tool runs entirely in your browser, so your data never leaves your device.
02How to use GraphQL to TypeScript
- Paste your SDL into the GraphQL Schema panel, or load User Schema, Enums & Inputs or Advanced Types.
- Read the result in TypeScript Output. It updates as you edit.
- If an error appears, check that each block starts with type, input, enum, scalar, union or interface.
- Click Copy to grab the declarations, or Reset to clear both panels.
03Worked examples
- Input:
type User { id: ID! name: String tags: [String!]! } - Result:
export interface User { id: string; name?: string | null; tags: string[]; } - Fields without ! become optional and nullable. ID maps to string.
- Input:
enum Role { ADMIN USER } - Result:
export enum Role { ADMIN = "ADMIN", USER = "USER", } - One-line enums work. Each member's value is its own name.
- Input:
scalar DateTime union SearchResult = User | Post - Result:
export type DateTime = string; export type SearchResult = User | Post; - Custom scalars default to string.
- Input:
type Post { # comment score: Float ids: [ID] } - Result:
export interface Post { score?: number | null; ids?: (string | null)[] | null; } - A list without ! on either side allows null items and a null list. The comment is stripped.
- Input:
interface Node { id: ID! } type Book implements Node & Timestamped { id: ID! pages(first: Int = 10): [[Int!]]! old: String @deprecated(reason: "no") } - Result:
export interface Node { id: string; } export interface Book extends Node, Timestamped { id: string; pages: (number[] | null)[]; old?: string | null; } - implements becomes extends. The field argument and the directive are dropped, and nested lists keep their inner nullability.
- Input:
input CreateUser { """Display name""" name: String! age: Int = 18 } - Result:
export interface CreateUser { name: string; age?: number | null; } - The description is removed and the default value is ignored, so age stays optional.
04Common use cases
- Typing the data returned by an Apollo Client or urql query in a React component before a codegen step exists
- Sharing input types such as CreateUserInput between a Node GraphQL server and a TypeScript form
- Reading a third-party API's SDL as TypeScript interfaces you already know how to scan
- Prototyping against a schema for a day before committing to GraphQL Code Generator config
- Pulling enum values like Role or Status into a select dropdown with matching string values
- Checking how a nullable list such as [Post] should be typed when reviewing a hand-written type
05Tips
- Directives are stripped, so @deprecated fields still show up. Add a /** @deprecated */ JSDoc comment by hand if you want your editor to strike them through.
- Custom scalars all become string. Change DateTime to Date or JSON to unknown yourself if your client parses them that way.
- Default values on input fields do not make a field required here. A field like age: Int = 18 stays optional and nullable.
- Schema-wide interfaces describe every field. A query selects a subset, so operation-level types from a codegen tool are safer for production code.
- Declarations come out grouped by kind, not in source order. TypeScript does not care about order for interfaces, so you can paste them as they are.
06Related concepts
GraphQL SDL, TypeScript interfaces, nullability, union types, code generation.
Frequently Asked Questions
What is GraphQL to TypeScript?
GraphQL to TypeScript is a free, browser-based developer tool on AIDToolStack. Convert GraphQL schemas to TypeScript types It requires no installation or sign-up and works entirely in your browser.
Is GraphQL to TypeScript free to use?
Yes. No sign-up, no fees and no usage cap.
Does GraphQL to TypeScript store my data?
No. It runs in your browser; nothing is uploaded.