GraphQL to TypeScript Definitions — Numio
Generates TypeScript types from a GraphQL schema with @graphql-codegen/typescript, plus result and variables types for any operations in the Document panel. Nullable fields become optional Maybe<T> properties; non-null lists become Array<T>.
Typing the data returned by a query in a frontend without setting up a codegen.yml and CLI run.
When to use it
- Typing the data returned by a query in a frontend without setting up a codegen.yml and CLI run.
- Checking how a schema change (a field becoming nullable, a new enum value) will look in the generated TypeScript before committing it.
How to use
- Paste your SDL (type, enum, interface, union, scalar definitions) into the GraphQL Schema editor.
- Put queries, mutations or fragments in the Document editor, or clear it to get schema types only; a document that does not match the schema is skipped with a warning comment.
- Copy the generated types: schema types such as User, plus GetUserQuery and GetUserQueryVariables for each named operation.
GraphQL schema + document
# GraphQL Schema editor
type Query {
user(id: ID!): User
}
type User {
id: ID!
name: String
tags: [String!]!
}
# Document editor
query GetUser($id: ID!) {
user(id: $id) { id name }
}TypeScript types
…
export type Query = {
__typename?: "Query"
user?: Maybe<User>
}
export type QueryUserArgs = {
id: Scalars["ID"]["input"]
}
export type User = {
__typename?: "User"
id: Scalars["ID"]["output"]
name?: Maybe<Scalars["String"]["output"]>
tags: Array<Scalars["String"]["output"]>
}
export type GetUserQueryVariables = Exact<{
id: Scalars["ID"]["input"]
}>
export type GetUserQuery = {
__typename?: "Query"
user?: { __typename?: "User"; id: string; name?: string | null } | null
}Details and limitations
The output starts with fixed helper types (Maybe, InputMaybe, Exact, MakeOptional, Scalars, …), shortened to '…' above. Scalars maps each scalar to separate input and output types.
Custom scalars such as Date are typed any; enum values become a TypeScript enum with PascalCase keys (USER becomes User = "USER").
Generation runs in a Web Worker in your browser; nothing is uploaded. The result is formatted with Prettier without semicolons, and the page has no codegen config options.
FAQ
Why does the output start with "// Document ignored"?
The Document editor is validated against your schema, and its default example queries fields like username. When validation fails, the page still generates the schema types and puts the first error in a comment at the top. Fix the operations or clear the Document editor.
How are nullable fields typed?
A nullable field such as name: String becomes name?: Maybe<Scalars["String"]["output"]>, where Maybe<T> is T | null. In operation result types it is written inline as name?: string | null.
Are only the selected fields included in the query type?
Yes. GetUserQuery contains just the fields the query selects (id and name here), with __typename as an optional property, while the full User type is generated separately.