home / skills / openclaw / skills / rest-to-graphql

rest-to-graphql skill

This skill converts REST API routes to a GraphQL schema, generating types, queries, and mutations to ease migration and integration.

npx playbooks add skill openclaw/skills --skill rest-to-graphql

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

Files (8)
SKILL.md
2.4 KB
---
name: rest-to-graphql
description: Convert REST API routes to a GraphQL schema. Use when migrating APIs or adding a GraphQL layer.
---

# REST to GraphQL Converter

Got a REST API and want GraphQL? Point this at your routes and get a complete schema with types, queries, and mutations. No manual translation required.

**One command. Zero config. Just works.**

## Quick Start

```bash
npx ai-rest-to-graphql ./src/routes
```

## What It Does

- Analyzes your REST endpoints and generates equivalent GraphQL schema
- Converts CRUD operations to queries and mutations
- Generates TypeScript types alongside the schema
- Maps REST resources to GraphQL types with proper relationships
- Includes resolver stubs that call your existing REST handlers

## Usage Examples

```bash
# Convert routes directory
npx ai-rest-to-graphql ./src/routes

# Single resource
npx ai-rest-to-graphql ./src/routes/users.ts

# Include resolver implementations
npx ai-rest-to-graphql ./src/routes --with-resolvers

# Output to specific file
npx ai-rest-to-graphql ./src/routes -o ./schema.graphql

# Keep REST as datasource
npx ai-rest-to-graphql ./src/routes --wrap-rest
```

## Best Practices

- **Start with core resources** - Don't convert everything at once
- **Review the generated types** - AI maps fields but check the relationships
- **Use as a migration guide** - The output shows you the GraphQL equivalent
- **Consider a gateway approach** - Wrap REST with GraphQL instead of replacing

## When to Use This

- Adding GraphQL to an existing REST API
- Exploring what your API would look like in GraphQL
- Building a BFF layer over microservices
- Learning GraphQL by seeing your own data modeled

## Part of the LXGIC Dev Toolkit

This is one of 110+ free developer tools built by LXGIC Studios. No paywalls, no sign-ups, no API keys on free tiers. Just tools that work.

**Find more:**
- GitHub: https://github.com/LXGIC-Studios
- Twitter: https://x.com/lxgicstudios
- Substack: https://lxgicstudios.substack.com
- Website: https://lxgic.dev

## Requirements

No install needed. Just run with npx. Node.js 18+ recommended.

```bash
npx ai-rest-to-graphql --help
```

## How It Works

The tool parses your REST route definitions to understand your resources and operations. It maps GET endpoints to queries, POST/PUT/DELETE to mutations, and infers type structures from your request/response patterns.

## License

MIT. Free forever. Use it however you want.

Overview

This skill converts REST API routes into a ready-to-use GraphQL schema, types, and optional resolver stubs. It’s designed for teams migrating APIs or adding a GraphQL layer with minimal manual work. One command generates queries, mutations, TypeScript types, and mappings that reflect your existing REST resources.

How this skill works

The tool parses your route definitions to detect resources, endpoints, and typical CRUD patterns. It maps GET endpoints to GraphQL queries and POST/PUT/DELETE to mutations, inferring input and output types from request and response shapes. Optionally it emits resolver stubs that call your existing REST handlers or wraps REST as a data source for a gateway approach.

When to use it

  • Migrating an existing REST API to GraphQL gradually
  • Adding a GraphQL façade or BFF layer on top of microservices
  • Prototyping GraphQL schemas from live REST routes to validate data models
  • Generating starter TypeScript types and resolver stubs for a GraphQL server
  • Learning how your resources and relationships map to GraphQL

Best practices

  • Start with core resources and convert incrementally, not the entire API at once
  • Review and adjust generated types and relationships—AI does a best-effort inference
  • Use the --with-resolvers option to get implementation scaffolding you can refine
  • Keep REST as the datasource initially by wrapping it, then migrate handlers over time
  • Validate schema against real responses and add custom scalars or directives as needed

Example use cases

  • Run against a routes directory to produce schema.graphql and types for a new GraphQL server
  • Convert a single resource file to inspect how fields and relations map to GraphQL
  • Generate resolver stubs to speed up building a GraphQL gateway that forwards to REST
  • Output types and schema for a frontend team to start building GraphQL queries
  • Use as a migration guide to compare REST endpoints with suggested GraphQL equivalents

FAQ

Does this require configuration or special annotations?

No. The tool works with common route definitions and infers types automatically, though annotations help improve accuracy.

Can it keep REST as the data source instead of replacing handlers?

Yes. Use the wrapper option to emit resolvers that call your existing REST endpoints so GraphQL acts as a gateway.