home / skills / openclaw / skills / neo-graphql-ts-generator

neo-graphql-ts-generator skill

/skills/martinforsulu/neo-graphql-ts-generator

This skill automatically generates TypeScript types from GraphQL schemas with a CLI, accelerating type-safe client development for OpenClaw agents.

npx playbooks add skill openclaw/skills --skill neo-graphql-ts-generator

Review the files below or copy the command above to add this skill to your agents.

Files (10)
SKILL.md
6.6 KB
---
name: graphql-ts-generator
description: Automatically generates TypeScript types from GraphQL schema files with CLI integration for developers and AI agents.
---

# GraphQL TypeScript Generator Skill

## Product Plan

### One-Sentence Description
Automatically generates TypeScript types from GraphQL schema files with CLI integration for developers and AI agents.

### Core Capabilities
- Convert GraphQL schema (.graphql, .gql) files to TypeScript interfaces and types
- Generate client-side TypeScript types for GraphQL queries and mutations
- Provide command-line interface for direct file processing
- Handle complex GraphQL types including unions, interfaces, and enums
- Validate GraphQL schemas before TypeScript generation
- Integrate with OpenClaw agent workflows for automation
- Support batch processing of multiple schema files

### Out of Scope
- GraphQL server implementation
- Database schema management
- Runtime GraphQL client code generation
- Documentation generation beyond type definitions
- Performance optimization for very large schemas
- Custom code formatting beyond TypeScript standards
- Integration with specific frameworks (React, Angular, etc.)

### Trigger Scenarios
- "Generate TypeScript types from this GraphQL schema"
- "Create TypeScript interfaces from GraphQL schema file"
- "Convert .graphql file to TypeScript types"
- "Auto-generate types for my GraphQL API"
- "Generate client types from GraphQL schema"
- "Transform GraphQL schema to TypeScript"

### Required Resources
- **scripts/**: Contains the main TypeScript generation logic and CLI entry point
- **references/**: GraphQL schema examples and test cases
- **assets/**: CLI help text, configuration templates, and documentation assets

### Key Files
- **scripts/index.ts**: Main CLI entry point
- **scripts/generator.ts**: Core type generation logic
- **scripts/cli.ts**: Command-line interface implementation
- **scripts/utils.ts**: Utility functions for GraphQL parsing
- **references/sample.graphql**: Example GraphQL schema for testing
- **references/test-schema.graphql**: Complex test case with various GraphQL features
- **assets/README.md**: User documentation
- **assets/package.json**: Skill package configuration
- **assets/tsconfig.json**: TypeScript configuration for the skill
- **assets/cli-help.txt**: CLI help text and usage examples

### Acceptance Criteria
- Skill correctly processes simple GraphQL schemas and generates valid TypeScript types
- Skill handles complex GraphQL features (unions, interfaces, enums)
- CLI interface accepts schema file paths and outputs TypeScript files
- Error handling for invalid GraphQL schemas
- Integration with OpenClaw agent workflows for automated processing
- Documentation includes usage examples and troubleshooting
- Test cases pass for all sample GraphQL schemas
- Generated TypeScript types are immediately usable in TypeScript projects

## Architecture Overview

### Directory Layout
```
├── scripts/
│   ├── index.ts        # CLI entry point
│   ├── generator.ts    # Type generation logic (Unions, Interfaces, Enums)
│   ├── cli.ts          # Command-line argument parsing
│   └── utils.ts        # GraphQL parsing utilities
├── references/
│   ├── sample.graphql  # Basic schema example
│   └── test-schema.graphql  # Complex test cases
├── assets/
│   ├── README.md       # User documentation
│   ├── package.json    # Skill package metadata
│   ├── tsconfig.json   # TypeScript config
│   └── cli-help.txt    # CLI usage examples
```

### Scripts Design

#### `scripts/index.ts`
- Language: TypeScript
- Inputs: `argv` (script arguments via CLI)
- Outputs: Generates TypeScript files in output directory
- Core Logic: Parses CLI args → Loads schema → Calls `generator.ts` → Writes output

#### `scripts/generator.ts`
- Language: TypeScript
- Inputs: GraphQL schema AST (parsed from file)
- Outputs: TypeScript interfaces, types
- Core Logic: Type transformation rules for:
  - Scalar types → TS primitives
  - Object types → TS interfaces
  - Union types → Discriminated unions
  - Enum types → TS enum

#### `scripts/cli.ts`
- Language: TypeScript
- Inputs: Raw command-line arguments
- Outputs: Processed schema file paths
- Core Logic: Argument validation → Schema file reading → Result routing

#### `scripts/utils.ts`
- Language: TypeScript
- Inputs: Raw GraphQL text
- Outputs: Parsed AST
- Core Logic: GraphQL parser implementation with error handling

### References Design

#### `references/sample.graphql`
- Content: Basic schema with Query/Mutation
- Usage: Demonstration for new users

#### `references/test-schema.graphql`
- Content: Features unions, interfaces, nested enums
- Usage: Testing boundary cases during development

### Data Flow
1. CLI receives schema path via arguments
2. `cli.ts` validates and loads schema file
3. `utils.ts` parses schema to AST
4. `generator.ts` processes AST using transformation rules
5. Outputs TypeScript files to `dist/` directory

### Integration Points

#### Agent Workflow Example:
1. User requests: "Generate types from schema at /docs/api.graphql"
2. Agent triggers CLI via `exec "graphql-ts-generator /docs/api.graphql"`
3. CLI processes schema, calls generator logic
4. Generated .ts files returned to agent as attachment
5. Agent presents files to user in chat interface

#### CLI Automation:
- Agent can schedule batch processing
- "Generate types for all .graphql in /schemas/" → `exec "graphql-ts-generator /schemas/*.graphql"`

## Usage Instructions

### Installation
```bash
npm install -g graphql-ts-generator
```

### Basic Usage
```bash
# Generate types from a single schema file
graphql-ts-generator schema.graphql

# Generate types and specify output directory
graphql-ts-generator schema.graphql --output dist/

# Process multiple schema files
graphql-ts-generator "schemas/*.graphql"
```

### Options
- `-o, --output <dir>`: Output directory for generated TypeScript files (default: `./generated`)
- `-f, --format <style>`: Code formatting style (default: standard)
- `-v, --verbose`: Enable verbose logging
- `--no-validate`: Skip schema validation (not recommended)
- `-h, --help`: Show help message

### Output
The generator produces TypeScript files containing:
- Interfaces for GraphQL object types
- Type aliases for GraphQL unions
- Enums for GraphQL enums
- Proper nullability handling (TypeScript `| null`)

### Integration with OpenClaw
This skill integrates seamlessly with OpenClaw agent workflows. Trigger via:
- Direct CLI execution in agent sessions
- Scheduled batch generation jobs
- Automated pipeline processing

See `assets/README.md` for complete documentation.

Overview

This skill automatically generates TypeScript types from GraphQL schema files and exposes a CLI for direct use by developers and AI agents. It converts GraphQL objects, unions, interfaces, enums, and scalars into immediately usable TypeScript interfaces, types, and enums. The tool supports batch processing, schema validation, and integration into automated workflows.

How this skill works

The CLI accepts one or more .graphql/.gql files, validates them, and parses each schema into an AST. A generator maps GraphQL constructs to TypeScript equivalents (scalars → primitives, objects → interfaces, unions → discriminated unions, enums → TS enums) and writes output files to a configurable directory. Utilities handle parsing and error reporting so the CLI can be invoked manually or by agents for automated runs.

When to use it

  • You need TypeScript type safety for a GraphQL API defined by schema files.
  • Preparing client-side or shared types for frontend and backend codebases.
  • Automating type generation as part of CI/CD or agent-driven workflows.
  • Converting multiple schema files in batch for monorepos or multi-service projects.
  • Validating schemas and producing fallback types before client generation.

Best practices

  • Keep schema files organized and versioned so generated output stays reproducible.
  • Run validation (default) to catch schema errors early; disable only for trusted inputs.
  • Integrate the CLI into build or CI pipelines to keep types in sync with schema changes.
  • Use the --output option to isolate generated files in a dedicated directory (e.g., generated/).
  • Review generated types for complex custom scalars and add manual mappings if needed.

Example use cases

  • Generate TypeScript interfaces for a single schema file: graphql-ts-generator schema.graphql
  • Batch-generate types for all schemas in a folder as part of a nightly job.
  • Agent-triggered generation where an AI agent executes the CLI and attaches generated .ts files in a chat.
  • Include the tool in CI to fail builds when schema validation fails or types are out of date.
  • Produce discriminated unions and enums for use in strictly typed client query builders.

FAQ

What input file types are supported?

The CLI accepts .graphql and .gql schema files, and supports glob patterns for batch processing.

Can I skip schema validation?

Yes — use --no-validate to skip validation, but this is not recommended for untrusted or changing schemas.

How are custom scalars handled?

Custom scalars map to TypeScript primitive placeholders by default; add explicit mappings in your workflow if you need specific types.