SQL to GraphQL Resolver Generator

Convert SQL CREATE TABLE statements to GraphQL schema SDL and resolver stubs with CRUD operations.

What is SQL to GraphQL Resolver Generator?

GraphQL provides a strongly-typed API layer that clients query with precision, requesting only the fields they need. This converter bridges your SQL database schema to a GraphQL API by transforming CREATE TABLE statements into two outputs: a Schema Definition Language (SDL) file with types, queries, and mutations, and TypeScript resolver stubs that implement the field resolution logic. Foreign key relationships become nested field resolvers, enabling clients to traverse relationships like post.author without manual join configuration.

How to Use

  1. Paste your SQL CREATE TABLE statements with REFERENCES constraints into the input area
  2. Click "Generate GraphQL" to produce both the SDL schema and TypeScript resolver stubs
  3. Switch between the Schema SDL and Resolvers tabs to view each output separately
  4. Copy the SDL into your GraphQL server schema file and the resolvers into your resolver module
  5. Implement the TODO placeholder functions in each resolver with your actual database query logic

Why Use This Tool?

Generates a complete GraphQL schema with types, Query operations for single and list fetches, and Mutation operations for create, update, and delete
Foreign key REFERENCES are automatically converted to field resolvers, enabling nested queries like user.posts or post.author
NOT NULL constraints become required GraphQL fields (!) ensuring type safety in the API contract
TypeScript resolver stubs include context parameters and typed arguments, giving you a typed starting point for implementation
UUID primary keys map to the GraphQL ID scalar type, aligning with Relay and Apollo client conventions

Tips & Best Practices

  • Foreign keys produce field resolvers rather than direct ID fields — a column like author_id REFERENCES users(id) becomes an author: User field that resolves by fetching the related user
  • NOT NULL columns become required fields (!) in the schema, while nullable columns remain optional for GraphQL clients
  • Implement the TODO resolver functions with your ORM or database driver — the stubs include example comments showing Prisma-style patterns
  • Customize the context parameter to include your database connection, authentication data, and data loaders for N+1 query prevention

Frequently Asked Questions

How are SQL types mapped to GraphQL scalar types?

INTEGER/SERIAL/BIGINT map to Int, FLOAT/DECIMAL/NUMERIC map to Float, BOOLEAN maps to Boolean, TIMESTAMP/DATE/TIME map to String (use custom scalars like DateTime for richer typing), UUID maps to ID, VARCHAR/TEXT map to String, JSON/JSONB map to String. You can add custom scalar definitions for more precise type handling.

When should I avoid generating resolvers from SQL?

This approach works best for CRUD-centric APIs that mirror your database schema. Avoid it when your GraphQL schema should differ significantly from your database structure, when you need complex computed fields that do not map to columns, or when you already have a hand-crafted schema that evolved through product requirements rather than data modeling.

How are foreign key relationships handled?

Columns with REFERENCES are converted to field resolvers rather than plain ID fields. For example, author_id REFERENCES users(id) becomes an author: User field on the Post type, with a resolver that fetches the related User. This enables GraphQL clients to request nested data in a single query.

What CRUD operations are generated?

For each table, the tool generates: Query operations for fetching a single record by ID and listing all records; Mutation operations for creating a new record, updating an existing record by ID, and deleting a record by ID. All mutations include TypeScript resolver stubs with typed arguments.

Is my SQL schema sent to a server?

No. All parsing and code generation runs entirely in your browser. Your SQL schema is never transmitted over the network, and no external services are contacted during the conversion process.

Real-world Examples

Apollo Server with SQL-backed resolvers

A developer building an Apollo Server API pastes their PostgreSQL schema into this tool, generates the SDL schema and resolver stubs, then implements each resolver using Prisma Client. The foreign key field resolvers enable nested queries that replace multiple REST endpoints.

Input
CREATE TABLE teams (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE members (
  id SERIAL PRIMARY KEY,
  team_id INTEGER NOT NULL REFERENCES teams(id),
  email TEXT NOT NULL,
  role VARCHAR(20) DEFAULT 'member'
);
Output
type Team {
  id: Int!
  name: String!
  createdAt: String
  members: [Member!]!
}

type Member {
  id: Int!
  team: Team!
  email: String!
  role: String
}

Rapid API prototyping from existing database

A startup with an existing MySQL database uses this converter to scaffold a GraphQL API in minutes. The generated schema and resolvers provide a working API that they customize incrementally, adding authentication, validation, and business logic to the resolver stubs.

Related Tools