update many graphql field
This commit is contained in:
9
src/Category/category.module.ts
Normal file
9
src/Category/category.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { CategorySchema } from './category.schema';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [CategorySchema],
|
||||
exports: [CategorySchema],
|
||||
})
|
||||
export class CategoryModule {}
|
||||
59
src/Category/category.schema.ts
Normal file
59
src/Category/category.schema.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos';
|
||||
import { Builder } from '../Graphql/graphql.builder';
|
||||
import { PrismaService } from '../Prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class CategorySchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
category() {
|
||||
return this.builder.prismaObject('Category', {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id'),
|
||||
name: t.exposeString('name'),
|
||||
serviceAndCategory: t.relation('serviceAndCategory'),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
categories: t.prismaField({
|
||||
type: [this.category()],
|
||||
args: this.builder.generator.findManyArgs('Category'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.category.findMany({
|
||||
...query,
|
||||
skip: args.skip ?? undefined,
|
||||
take: args.take ?? 10,
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
where: args.filter ?? undefined,
|
||||
});
|
||||
},
|
||||
}),
|
||||
category: t.prismaField({
|
||||
type: this.category(),
|
||||
args: this.builder.generator.findUniqueArgs('Category'),
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.category.findUnique({
|
||||
...query,
|
||||
where: args.where ?? undefined,
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user