tao da het bi ngu

This commit is contained in:
2024-10-07 17:29:44 +07:00
parent dfa6b35399
commit 30159e01ad
5 changed files with 29 additions and 15 deletions

View File

@@ -11,7 +11,7 @@ export interface SchemaContext {
req: Request;
}
interface SchemaBuilderOption {
export interface SchemaBuilderOption {
Context: SchemaContext;
PrismaTypes: PrismaTypes;
DataModel: PothosPrismaDatamodel;

File diff suppressed because one or more lines are too long

View File

@@ -19,23 +19,17 @@ export class UserSchema extends PothosSchema {
// Types section
@PothosRef()
user(): any {
user() {
return this.builder.prismaObject('User', {
fields: (t) => ({
id: t.exposeID('id'),
name: t.exposeString('name'),
email: t.exposeString('email'),
phoneNumber: t.exposeString('phoneNumber'),
oauthToken: t.exposeString('oauthToken'),
oauthToken: t.exposeString('oauthToken', { nullable: true }),
role: t.exposeString('role'),
createdAt: t.expose('createdAt', {
type: 'Date',
nullable: true,
}),
updatedAt: t.expose('updatedAt', {
type: 'Date',
nullable: true,
}),
createdAt: t.expose('createdAt', { type: 'Date' }),
updatedAt: t.expose('updatedAt', { type: 'Date' }),
}),
});
}
@@ -45,8 +39,27 @@ export class UserSchema extends PothosSchema {
init(): void {
this.builder.queryFields((t) => ({
users: t.prismaField({
type: 'User',
resolve: async (query) => this.prisma.user.findMany() as any,
type: [this.user()],
args: {
skip: t.arg.int(),
take: t.arg.int(),
cursor: t.arg.string(),
where: t.arg.string(),
orderBy: t.arg.string(),
},
resolve: async (query, root, args, ctx, info) => {
const { skip, take, cursor, where, orderBy } = args;
const users = await this.prisma.user.findMany({
skip: skip || 0,
take: take || 10,
cursor: cursor ? { id: cursor } : undefined,
where: where ? JSON.parse(where) : undefined,
orderBy: orderBy ? JSON.parse(orderBy) : undefined,
});
return users;
},
}),
}));
}