tao da het bi ngu
This commit is contained in:
@@ -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
@@ -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;
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user