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
- Select your target database provider from the dropdown (PostgreSQL, MySQL, SQLite, or MongoDB)
- Paste your GraphQL SDL containing type definitions into the input panel — include both object types and any relationships between them
- Click Generate to parse the schema and produce a Prisma schema with datasource, generator, and model blocks
- Review the output for correctness: check that relation fields have the expected @relation annotations and that foreign key columns are present
- Copy the result into your schema.prisma file and run npx prisma validate to confirm there are no syntax errors
- Run npx prisma migrate dev to apply the schema to your database and generate the Prisma Client
Why Use This Tool?
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.
type User {
id: ID!
username: String!
email: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String
author: User!
}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.
type Task {
id: ID!
title: String!
completed: Boolean!
dueDate: String
}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?
}