Create nexus type?
This is Cli tool to Create nexus type for Prisma projects. When you try to upgrade from Prisma 1 to Prisma 2 and need to write nexus types for your models this tool will create this types for you from your schema.prisma
file
How use?
yarn add -D create-nexus-type
or
npm i create-nexus-type --save-dev
cnt
Command options for --schema To add schema file path if you not run command in root of project
--outDir Created files output dir default src/types
-s add this option to use @nexus/schema package
-mq add this option to create Queries and Mutations for models
-m add this option to create Mutations
-q add this option to create Queries
-c add this option to create Queries Count
-f add this option to add {filtering: true} option to Queries
-o add this option to add {ordering: true} option to Queries
--js create javascript version
--mjs create es modules version
Example
// schema.prisma datasource postgresql { url = env("DATABASE_URL") provider = "postgresql"} generator client { provider = "prisma-client-js"} model User { id String @id @default(cuid()) email String @unique birthDate DateTime posts Post[]} model Post { id String @id @default(cuid()) author User[]}
Run
npx cnt --mq -c -f -o
OutPut
; ; ; ;
Create TypeScript types
Have another option to create TypeScript types to use for your work
create-types
Command options for usage: create-types (Create TypeScript types from Prisma schema)
--schema To add schema file path if you not run command in root of project
--outDir Created files output dir default src/generated
Example
// schema.prisma datasource postgresql { url = env("DATABASE_URL") provider = "postgresql"} generator client { provider = "prisma-client-js"} model User { id String @id @default(cuid()) email String @unique birthDate DateTime? role UserRole posts Post[]} model Post { id String @id @default(cuid()) author User[]} enum UserRole { USER ADMIN}
run
npx create-types
OutPut
// types.ts
Have questions?
Didn't find something here? Look through the issues or simply drop us a line at ahmed.elywa@icloud.com.