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
| GraphQL | TypeScript | Notes |
|---|---|---|
| String | string | Also used for ID |
| ID | string | GraphQL's opaque identifier scalar |
| Int | number | Also used for Float |
| Float | number | No separate integer/float distinction in TS |
| Boolean | boolean | |
| 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
- 1Paste your GraphQL schema (SDL) — type, input, interface, and enum definitions are all recognized.
- 2Click Convert — each definition becomes its own TypeScript interface or type alias, with field nullability preserved exactly as declared.
- 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.
- 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 responses — Generate interfaces for the object types your queries return so client code is type-safe.
- ▸Input variables — Turn input types into TypeScript so mutation variables are checked at compile time.
- ▸Shared schema types — Produce a base set of types from your SDL to build query-specific types on top of.
- ▸Learning the mapping — See how GraphQL scalars, nullability, and lists translate into TypeScript.
- ▸Reviewing a schema change — Regenerate types after an SDL edit and diff them against your previous types to see exactly what changed for consumers.