Nexus prisma plugin generate types
This is Cli tool to Create CRUD system for Nexus Prisma plugin from your schema.prisma
file
CONTENT
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[]
}
For generate all types you need to run pal g
command for all options click here
pal g
OutPut
// User model
import { objectType, arg, extendType } from '@nexus/schema';
export const User = objectType({
name: 'User',
definition(t) {
t.model.id();
t.model.email();
t.model.birthDate();
t.model.posts();
},
});
export const userQuery = extendType({
type: 'Query',
definition(t) {
t.crud.user();
t.field('findFirstUser', {
type: 'User',
args: {
where: 'UserWhereInput',
orderBy: arg({ type: 'UserOrderByInput', list: true }),
cursor: 'UserWhereUniqueInput',
skip: 'Int',
take: 'Int',
},
async resolve(_root, args, ctx) {
return ctx.prisma.user.findFirst(args);
},
});
t.crud.users({ filtering: true, ordering: true });
t.field('usersCount', {
type: 'Int',
args: {
where: 'UserWhereInput',
},
async resolve(_root, args, ctx) {
return ctx.prisma.user.count(args);
},
});
},
});
export const userMutation = extendType({
type: 'Mutation',
definition(t) {
t.crud.createOneUser();
t.crud.updateOneUser();
t.crud.upsertOneUser();
t.crud.deleteOneUser();
t.crud.updateManyUser();
t.crud.deleteManyUser();
},
});