Skip to content

mavvystudio/prisma-generator-graphql-typedef

Repository files navigation

prisma-generator-graphql-typedef

Transforms prisma schema into graphql schema

Install

npm i prisma-generator-graphql-typedef

Example

This prisma schema:

model User {
  id        Int      @id @default(autoincrement())
  /// @gqlType Float
  createdAt DateTime @default(now())
  /// @gqlType Float
  updatedAt DateTime @updatedAt
  /// @gqlIgnore
  password  String 
  email     String   @unique
  name      String?
  keywords  String[]
  /// @gqlNonNullElement
  posts     Post[]
  profile   Profile?
  /// user role
  role      Role     @default(USER)
}

Will generate this graphql schema:

  • password field is not included because of the @gqlIgnore keyword

  • createdAt and updatedAt fields' type was changed to Float by using @gqlType Float, which you can supply any type

  • name and profile is optional that makes all the other fields non-null

  • posts is non null by using @gqlNonNullElement

type User {
  id: Int!
  createdAt: Float!
  updatedAt: Float!
  email: String!
  name: String
  keywords: [String]!
  posts: [Post!]!
  profile: Profile
  role: Role!
}

This generator was bootstraped using create-prisma-generator

About

Generates graphql schema from prisma schema

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages