GraphQL to Prisma Schema Converter

Convert GraphQL schema SDL to Prisma schema with models, relations, and annotations.

What is GraphQL to Prisma Schema Converter?

Prisma is a next-generation ORM for Node.js and TypeScript that uses a declarative schema file (schema.prisma) to define database models, relations, and datasource configuration. Writing Prisma schemas by hand from an existing GraphQL API is tedious and error-prone, especially when dealing with type mappings, relation annotations, and naming conventions. This tool bridges that gap by parsing your GraphQL Schema Definition Language (SDL) and producing a complete Prisma schema file. It maps GraphQL scalar types to their Prisma equivalents (ID becomes String with @id, Int stays Int, etc.), detects object-type fields that represent relations and generates @relation annotations with foreign key fields, and applies @map annotations for snake_case column naming. You can choose from four database providers — PostgreSQL, MySQL, SQLite, and MongoDB — and the datasource block is generated accordingly.

How to Use

  1. Select your target database provider from the dropdown (PostgreSQL, MySQL, SQLite, or MongoDB)
  2. Paste your GraphQL SDL containing type definitions into the input panel — include both object types and any relationships between them
  3. Click Generate to parse the schema and produce a Prisma schema with datasource, generator, and model blocks
  4. Review the output for correctness: check that relation fields have the expected @relation annotations and that foreign key columns are present
  5. Copy the result into your schema.prisma file and run npx prisma validate to confirm there are no syntax errors
  6. Run npx prisma migrate dev to apply the schema to your database and generate the Prisma Client

Why Use This Tool?

Automates the tedious GraphQL-to-Prisma type mapping, including ID → String @id @default(cuid()) and email → String @unique
Detects object-type relationships and generates @relation annotations with foreign key fields (e.g., authorId for a Post → User relation)
Produces @map annotations for snake_case column names, matching common database naming conventions without manual edits
Supports PostgreSQL, MySQL, SQLite, and MongoDB out of the box — switch providers with one click
Generates a ready-to-run schema.prisma that passes prisma validate with no additional changes for simple schemas

Tips & Best Practices

  • After generating, add @@unique constraints for composite unique indexes that the GraphQL schema does not express
  • The tool defaults to @default(cuid()) for ID fields — change to @default(uuid()) if your application prefers UUIDs
  • For MongoDB, remove any @@map annotations since MongoDB does not use table names in the same way as relational databases
  • Add @updatedAt timestamps manually if you want Prisma to auto-update a field on every write
  • If your GraphQL schema uses custom scalars, replace the generated String placeholder with the appropriate Prisma type

Frequently Asked Questions

How are GraphQL types mapped to Prisma types?

GraphQL ID maps to Prisma String with @id @default(cuid()). String, Int, Float, and Boolean map directly to their Prisma equivalents. Object-type fields that reference other models become relation fields with @relation annotations, and list fields (e.g., posts: [Post!]!) become array relations using the [] syntax.

When should I NOT use this converter?

If your database schema already exists and you want to introspect it into a Prisma schema, use npx prisma db pull instead. This tool is designed for greenfield projects where the GraphQL schema is the source of truth. It is also not ideal for schemas with complex multi-field composite keys or advanced Prisma features like composite types.

How are relationships handled?

Object-type fields that reference another type in the same schema are treated as relations. For to-one relations (e.g., author: User!), the tool adds a @relation annotation and creates a foreign key field (authorId). For to-many relations (e.g., posts: [Post!]!), it uses the array syntax without a foreign key on the parent side.

Is my schema data sent to a server?

No. All parsing and code generation runs entirely in your browser. Your GraphQL schema never leaves your device, so it is safe for proprietary or internal API definitions.

Does this support GraphQL enums?

Basic enum types are preserved in the output as Prisma enum blocks. However, if your enum values contain special characters or are not valid Prisma identifiers, you may need to adjust them manually after generation.

Can I use this with an existing Prisma schema?

You can paste the generated models into an existing schema.prisma file, but be careful to avoid duplicate model names. It is best to generate a fresh schema and then merge specific models into your existing file.

Real-world Examples

Social media app with User and Post models

A social platform where users create posts and each post belongs to one author. The GraphQL schema expresses this as a one-to-many relationship, which the converter translates into Prisma models with @relation and a foreign key.

Input
type User {
  id: ID!
  username: String!
  email: String!
  posts: [Post!]!
}

type Post {
  id: ID!
  title: String!
  content: String
  author: User!
}
Output
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id       String @id @default(cuid())
  username String
  email    String @unique
  posts    Post[]
}

model Post {
  id       String  @id @default(cuid())
  title    String
  content  String?
  author   User    @relation(name: "PostToUser", fields: [authorId], references: [id])
  authorId String
}

Multi-provider schema for a task tracker

A task management app that needs to support both PostgreSQL for production and SQLite for local development. The same GraphQL schema generates different datasource blocks depending on the selected provider.

Input
type Task {
  id: ID!
  title: String!
  completed: Boolean!
  dueDate: String
}
Output
datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model Task {
  id        String  @id @default(cuid())
  title     String
  completed Boolean
  dueDate   String?
}

Related Tools