GraphQL Schema to TypeScript Types Generator
Turn a GraphQL schema into TypeScript in the browser: object, interface, union, enum, input and scalar types with JSDoc and deprecation notes, field argument types, and result and variables types for your queries, mutations and fragments. Paste SDL or an introspection result, pick the output style and copy or download a .ts file.
Funziona nel tuo browser. I tuoi file non lasciano mai il dispositivo. Scopri come verificarlo
…
Come si usa
- 1Add the schema
Paste SDL or introspection JSON, or open a .graphql or .json file.
- 2Add operations
Optionally paste the queries, mutations and fragments your app uses.
- 3Choose the style
Pick enums as unions, enums or const objects, Maybe helpers, optional nullable fields, __typename and readonly.
- 4Map scalars
Enter TypeScript types for your custom scalars and a fallback for the rest.
- 5Fix problems
Read errors and warnings with their line numbers and correct the schema or the query.
- 6Use the types
Copy the output or download a .ts or .d.ts file, and save the project for next time.
Informazioni su questo strumento
Typed GraphQL clients catch broken queries at compile time, but setting up a code generator, its plugins and a config file is heavy when you only need types for a script, a small frontend or a quick review of an API. This generator parses the schema itself and writes the TypeScript directly in your browser. The parser follows the October 2021 GraphQL specification: descriptions in quotes and block strings, scalar, type, interface with implements, union, enum, input, directive definitions, schema and extend definitions, default values and directives such as @deprecated with a reason. If you only have the server, run the standard introspection query and paste the JSON; the tool converts it, shows the equivalent SDL and lets you download it. The output follows the conventions most TypeScript GraphQL projects use: a Scalars map from built-in and custom scalars to TypeScript types that you set yourself, Maybe and InputMaybe helpers, nullable fields marked optional if you want, __typename literals, readonly modifiers, enums as string unions, TypeScript enums or const objects, and an Args type for every field with arguments. Paste operations in the second box and you also get exact result types for each query, mutation, subscription and fragment, with aliases, nested selections, fragment spreads and inline fragments; selections on an interface or union with type conditions become discriminated unions on __typename. Unknown fields, missing subselections and fragments on unknown types are reported with their line so you can fix the query before your build does.
Output options
Enums as string unions, enum declarations or const objects with a matching type; Scalars map or inlined primitive types; Maybe and InputMaybe helpers or plain T | null; optional markers on nullable fields; __typename fields; readonly properties and ReadonlyArray; argument types; JSDoc from descriptions with @deprecated tags. Custom scalars such as DateTime, JSON or Money are mapped in a small list, and unknown ones fall back to unknown, string or any.
Tested against
The parser and generator were checked with our own schemas and queries (interfaces, unions, enums, inputs, extensions, fragments, introspection JSON) written from the October 2021 specification. The output was not compared with graphql-js validation or GraphQL Code Generator, which may name types differently and reject documents this tool accepts.
What is checked
Syntax errors stop with the line and column. The schema check warns about unknown types, interfaces that are not interfaces, union members that are not objects and duplicate definitions. The operations check reports fields that do not exist on a type, objects selected without subfields, scalars with subfields, unknown fragments and variables of unknown types.
What is not generated
Resolver signatures, React or Vue hooks, Apollo or urql documents, persisted query maps, @defer and @stream partial results and validation rules beyond those listed. The tool is not a full GraphQL validator; run your server's or graphql-js validation in CI.
Privacy
Schemas often describe internal APIs. Everything is parsed in this tab and nothing is uploaded or sent to the endpoint.
Esempio svolto
A team has a 42-line shop schema with 4 object types plus Query and Mutation, 1 interface, 1 union, 2 enums, 2 inputs and the custom scalars DateTime and Money. With the default options and those two scalars mapped, the generator writes 174 lines: a Scalars map with DateTime as string and Money as number, Role as the union "ADMIN" | "STAFF" | "CUSTOMER", UserOrdersArgs with first and status, and NewOrderInput with an optional note. The Search query that selects __typename plus inline fragments on User and on Product through the ProductCard fragment becomes an Array of two object shapes discriminated by __typename "User" or "Product", and a typo in the Me query, displayNmae, is reported as Line 2, column 11: User has no field displayNmae.
In breve
- Categoria: Sviluppo e dati
- Funziona nel browser, senza registrazione né caricamento.
- Le informazioni che inserisci restano sul tuo dispositivo.
- Disponibile in inglese.
- Contenuto rivisto l'ultima volta il:
- Fonte ufficiale: GraphQL Specification, October 2021 edition (type system, SDL, introspection, operations)
Domande frequenti
Can I paste an introspection result instead of SDL?
Yes. Paste the JSON from the standard introspection query, either the full response with data.__schema or only the __schema object. The tool converts it and also offers the schema as SDL to download.
Does it generate types for my queries?
Yes. Paste queries, mutations, subscriptions and fragments in the operations box. Each operation gets a result type and a Variables type, and each fragment gets a Fragment type that follows its selection exactly.
How are custom scalars typed?
List them as Name: type lines, for example DateTime: string, Money: number or JSON: unknown. Scalars you do not list use the fallback you choose: unknown, string or any.
How are unions and interfaces handled in queries?
If a selection uses inline fragments or fragment spreads with type conditions, the result becomes a union of one object shape per possible type, each with a literal __typename, so TypeScript can narrow it.
Is this the same as GraphQL Code Generator?
The style is similar to the typescript and typescript-operations plugins, but this is an independent generator. It is meant for quick types and reviews; large projects can still use their build-time generator.
Is my schema sent anywhere?
No. Parsing and generation run in this browser tab and the endpoint is never contacted.
