Converts GraphQL schemas (SDL) to TypeScript type definitions. Stable v1.10.1, low release cadence. Supports custom scalars, enums, and unions. Differentiator: outputs TypeScript interfaces/classes with optional field mapping. Requires graphql as a peer dependency. No browser support; Node.js-only since v1.
npm install gql2tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts a GraphQL schema to TypeScript type definitions with module and namespace options.
Use buildSchema from graphql to convert SDL string to Schema object before passing to gql2ts.
Rename 'module' to 'moduleType' where used.
Provide custom scalar mapping via 'scalars' option in the configuration.
If numeric enums needed, manual type override required.
Verify generated types match your schema's nullability expectations.
Use named import: import { gql2ts } from 'gql2ts'Run npm install graphql
Use import syntax or upgrade to Node 14+ and use dynamic import().
Use buildSchema from graphql first: const schema = buildSchema(sdlString);