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

@@ -4,6 +4,7 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
pull_policy: always
ports: ports:
- '8888:3000' - '8888:3000'
volumes: volumes:

View File

@@ -11,7 +11,7 @@ export interface SchemaContext {
req: Request; req: Request;
} }
interface SchemaBuilderOption { export interface SchemaBuilderOption {
Context: SchemaContext; Context: SchemaContext;
PrismaTypes: PrismaTypes; PrismaTypes: PrismaTypes;
DataModel: PothosPrismaDatamodel; 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 // Types section
@PothosRef() @PothosRef()
user(): any { user() {
return this.builder.prismaObject('User', { return this.builder.prismaObject('User', {
fields: (t) => ({ fields: (t) => ({
id: t.exposeID('id'), id: t.exposeID('id'),
name: t.exposeString('name'), name: t.exposeString('name'),
email: t.exposeString('email'), email: t.exposeString('email'),
phoneNumber: t.exposeString('phoneNumber'), phoneNumber: t.exposeString('phoneNumber'),
oauthToken: t.exposeString('oauthToken'), oauthToken: t.exposeString('oauthToken', { nullable: true }),
role: t.exposeString('role'), role: t.exposeString('role'),
createdAt: t.expose('createdAt', { createdAt: t.expose('createdAt', { type: 'Date' }),
type: 'Date', updatedAt: t.expose('updatedAt', { type: 'Date' }),
nullable: true,
}),
updatedAt: t.expose('updatedAt', {
type: 'Date',
nullable: true,
}),
}), }),
}); });
} }
@@ -45,8 +39,27 @@ export class UserSchema extends PothosSchema {
init(): void { init(): void {
this.builder.queryFields((t) => ({ this.builder.queryFields((t) => ({
users: t.prismaField({ users: t.prismaField({
type: 'User', type: [this.user()],
resolve: async (query) => this.prisma.user.findMany() as any, 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;
},
}), }),
})); }));
} }