npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

graphql-to-ts-generator

v1.0.0

Published

Convert GraphQL schemas to TypeScript interfaces with CLI support

Readme

GraphQL to TypeScript Generator

A powerful CLI tool and library to convert GraphQL schemas into TypeScript type definitions.

Features

  • 🚀 CLI Tool - Easy to use command-line interface
  • 📁 Config File Support - JSON or JS configuration files
  • 👀 Watch Mode - Automatically regenerate types on schema changes
  • 🎨 Customizable - Custom scalar mappings, prefixes, suffixes
  • 📝 Comments - Preserve GraphQL descriptions as TypeScript comments
  • 🔧 Flexible Exports - Use as a library in your own tools

Installation

# Global installation
npm install -g graphql-to-ts-generator

# Project dependency
npm install --save-dev graphql-to-ts-generator

Quick Start

# Basic usage
graphql-to-ts schema.graphql

# Specify output file
graphql-to-ts schema.graphql -o types/schema.ts

# Watch mode
graphql-to-ts schema.graphql -w

# With custom options
graphql-to-ts schema.graphql -o types/schema.ts --prefix "GQL" --suffix "Type"

CLI Options

| Option | Description | Default | |--------|-------------|---------| | <input> | Input GraphQL schema file | Required | | -o, --output <path> | Output TypeScript file | types/generated.ts | | -c, --config <path> | Config file path | Auto-detect | | -w, --watch | Watch for file changes | false | | --no-comments | Exclude comments | false | | --prefix <prefix> | Type name prefix | "" | | --suffix <suffix> | Type name suffix | "" | | --enums-as-const | Generate const assertions | false | | --custom-scalars <json> | Custom scalar mappings | {} |

Configuration File

Create a graphql-to-ts.config.json file:

{
  "input": "schema.graphql",
  "output": "types/generated.ts",
  "watch": true,
  "includeComments": true,
  "typePrefix": "GQL",
  "typeSuffix": "Type",
  "enumsAsConst": false,
  "customScalarTypes": {
    "DateTime": "Date",
    "Upload": "File"
  }
}

Or use JavaScript configuration (graphql-to-ts.config.js):

module.exports = {
  input: 'schema.graphql',
  output: 'types/generated.ts',
  customScalarTypes: {
    DateTime: 'Date',
    Upload: 'File'
  }
};

Usage as Library

import { convertGraphQLToTypeScript } from 'graphql-to-ts-generator';

const schema = `
  type User {
    id: ID!
    name: String!
    email: String!
  }
`;

const types = convertGraphQLToTypeScript(schema, {
  customScalarTypes: {
    DateTime: 'Date'
  },
  typePrefix: 'GQL'
});

console.log(types);

Package.json Scripts

Add to your package.json:

{
  "scripts": {
    "generate-types": "graphql-to-ts schema.graphql -o types/generated.ts",
    "generate-types:watch": "graphql-to-ts schema.graphql -o types/generated.ts --watch"
  }
}

Examples

Basic Schema

Input (schema.graphql):

type User {
  id: ID!
  name: String!
  email: String
}

enum Role {
  ADMIN
  USER
}

Output:

export interface User {
  id: string;
  name: string;
  email?: string;
}

export enum Role {
  ADMIN = "ADMIN",
  USER = "USER",
}

With Custom Scalars

graphql-to-ts schema.graphql --custom-scalars '{"DateTime":"Date","JSON":"any"}'

License

MIT


## 10. Publishing Steps

```bash
# Initialize npm package
npm init -y

# Install dependencies
npm install

# Build the package
npm run build

# Test locally
npm link
graphql-to-ts --help

# Publish to npm
npm login
npm publish

11. Example Usage After Publishing

Users can then use your package like this:

# Install globally
npm install -g graphql-to-ts-generator

# Use in any project
graphql-to-ts schema.graphql -o types/generated.ts

# Or as project dependency
npm install --save-dev graphql-to-ts-generator
npx graphql-to-ts schema.graphql

12. Add to package.json scripts

{
  "scripts": {
    "generate-types": "graphql-to-ts schema.graphql -o types/generated.ts",
    "generate-types:watch": "graphql-to-ts schema.graphql -w"
  }
}