Skip to content

Generate TypeScript SDK as standalone npm package with package.json #3

@khanakia

Description

@khanakia

Summary

Add the ability to generate the TypeScript SDK as a standalone npm package by automatically creating a package.json (and optionally tsconfig.json) in the output directory. This would make the generated SDK publishable to npm and immediately installable in any TypeScript/JavaScript project.

Current behavior

The generated TypeScript SDK is a set of .ts files that must live inside an existing project. Users need to manually set up package.json, tsconfig.json, and install the gqlkit-ts runtime dependency. The generated builder/index.ts re-exports from gqlkit-ts, which must already be available in the project's node_modules.

Proposed behavior

Add flags like --npm-name and --npm-version that, when provided:

  1. Generate a package.json in the output directory with the given package name, version, and gqlkit-ts as a dependency
  2. Generate a tsconfig.json with sensible defaults for a library package
  3. Generate a root index.ts barrel file that re-exports all public types
  4. Make the SDK directory a fully independent npm package

Example

gqlkit generate-ts \
  --schema schema.graphql \
  --output ./my-sdk \
  --npm-name @yourorg/myapi-sdk \
  --npm-version 1.0.0

This would generate:

my-sdk/
├── package.json           # { "name": "@yourorg/myapi-sdk", "dependencies": { "gqlkit-ts": "^x.y.z" } }
├── tsconfig.json          # library-friendly TS config
├── index.ts               # barrel re-exports
├── builder/
├── scalars/
├── enums/
├── types/
├── inputs/
├── fields/
├── queries/
└── mutations/

Usage after generation

Other projects could then install it:

npm install @yourorg/myapi-sdk
# or from a git repo / local path
npm install ./my-sdk
import { GraphQLClient } from "gqlkit-ts";
import { QueryRoot } from "@yourorg/myapi-sdk/queries";
import { MutationRoot } from "@yourorg/myapi-sdk/mutations";

Why

  • Allows publishing the generated SDK as its own npm package
  • Removes the coupling between the SDK and the parent project
  • Enables sharing the SDK across multiple frontend/backend projects
  • Makes the SDK installable via npm install without copying files
  • Matches the Go SDK's proposed standalone module generation (Generate SDK as standalone Go module with go.mod #2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions