Developer • GraphQL & TypeScript
GraphQL to TypeScript Converter
Paste any GraphQL SDL schema to generate clean TypeScript interfaces, type aliases, string-union enums, and custom scalar mappings—100% locally in your browser.
export type DateTime = string;
export type JSON = Record<string;
export type OrderStatus = "PENDING" | "PAID" | "SHIPPED" | "DELIVERED" | "CANCELLED";
export type SearchResult = Product | Order;
export interface Node {
id: string;
createdAt: string;
}
export interface Product extends Node {
id: string;
createdAt: string;
sku: string;
name: string;
description?: string | null;
priceCents: number;
rating?: number | null;
inStock: boolean;
tags: string[];
metadata?: Record<string | null;
}
export interface OrderItem {
product: Product;
quantity: number;
unitPriceCents: number;
}
export interface Order extends Node {
id: string;
createdAt: string;
status: OrderStatus;
items: OrderItem[];
couponCode?: string | null;
totalCents: number;
}
export interface CreateOrderInput {
items: OrderItemInput[];
couponCode?: string | null;
}
export interface OrderItemInput {
productId: string;
quantity: number;
}
GraphQL to TypeScript Type Mapping Reference
| GraphQL SDL | TypeScript Output | Notes |
|---|---|---|
ID! / String! | string | Non-null scalar |
Int! / Float! | number | Numeric scalars |
Boolean! | boolean | Strict boolean |
String (nullable) | string | null | Optional ? when enabled |
[Product!]! | Product[] | Non-null array of non-null items |
union A = B | C | export type A = B | C; | Enable __typename for discriminated unions |
Related Developer Converters
Frequently Asked Questions
How does GraphQL to TypeScript conversion handle nullable and non-null fields?
In GraphQL SDL, fields are nullable by default unless marked with an exclamation mark (!). This converter maps non-null fields like String! directly to string, while nullable fields like String become string | null (or optional ? properties) depending on your selected nullability mode.
How are GraphQL lists like [String!]! converted to TypeScript?
Non-null lists of non-null items ([String!]!) convert to string[]. A non-null list of nullable items ([String]!) converts to (string | null)[], and a nullable list ([String!]) converts to string[] | null.
Should I output GraphQL enums as TypeScript string unions or enum blocks?
String literal unions (e.g., type OrderStatus = 'PENDING' | 'PAID') are usually preferred in modern TypeScript and Next.js projects because they erase completely at compile time, work seamlessly with JSON payloads, and avoid runtime enum overhead.
How do I map custom GraphQL scalars such as DateTime, UUID, or JSON?
Use the Custom Scalars input field with comma-separated pairs like DateTime=string, JSON=Record<string, unknown>, BigInt=string. Built-in defaults already map common scalars like DateTime, Date, UUID, URL, and JSON.
Is my GraphQL schema uploaded to a server?
No. Parsing and TypeScript generation happen 100% locally in your browser, making it safe to paste proprietary API schemas.