GraphQL to TypeScript Converter
Convert GraphQL SDL to TypeScript — types, inputs, enums, unions, nullable fields
Options
596 characters
8 types generated · 830 characters
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:
- Object types:
type User { ... }→interface User { ... } - Nullable fields: GraphQL fields are nullable by default.
name: String→name: string | null. Non-nullname: String!→name: string - Input types:
input CreateUserInput { ... }→interface CreateUserInput { ... } - Enums:
enum Status { ACTIVE, INACTIVE }→enum Status { ACTIVE = "ACTIVE", INACTIVE = "INACTIVE" } - Union types:
union SearchResult = User | Post→type SearchResult = User | Post - Scalars:
ID→string,Int→number,Float→number,Boolean→boolean,String→string - 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:
- Custom scalar mapping: Map custom scalars like
DateTimeorJSONto appropriate TypeScript types (Date,Record<string, unknown>) - Utility types: Generate
Partial<T>variants for update inputs where all fields are optional - Query result types: Combine generated types with
Pick<T, K>to match specific query selections
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.