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 ManagedServiceSchema extends PothosSchema { constructor( @Inject(SchemaBuilderToken) private readonly builder: Builder, private readonly prisma: PrismaService, ) { super() } @PothosRef() managedService() { return this.builder.prismaObject('ManagedService', { description: 'A managed service', fields: (t) => ({ id: t.exposeID('id', { description: 'The ID of the managed service.', }), mentorId: t.exposeID('mentorId', { description: 'The ID of the mentor.', }), serviceId: t.exposeID('serviceId', { description: 'The ID of the service.', }), schedule: t.relation('schedule', { description: 'The schedule of the service.', }), mentor: t.relation('mentor', { description: 'The mentor.', }), service: t.relation('service', { description: 'The service.', }), }), }) } @Pothos() init(): void { this.builder.queryFields((t) => ({ managedService: t.field({ type: this.managedService(), args: this.builder.generator.findUniqueArgs('ManagedService'), resolve: async (_parent, args, _ctx) => { return this.prisma.managedService.findUnique({ where: args.where, }) }, }), managedServices: t.field({ type: [this.managedService()], args: this.builder.generator.findManyArgs('ManagedService'), resolve: async (_parent, args, _ctx) => { return this.prisma.managedService.findMany({ where: args.filter ?? undefined, orderBy: args.orderBy ?? undefined, cursor: args.cursor ?? undefined, take: args.take ?? undefined, skip: args.skip ?? undefined, }) }, }), })) this.builder.mutationFields((t) => ({ createManagedService: t.prismaField({ description: 'Create a new managed service.', type: this.managedService(), args: { input: t.arg({ type: this.builder.generator.getCreateInput('ManagedService'), required: true, description: 'The data for the managed service.', }), }, resolve: async (query, _root, args, _ctx, _info) => { return await this.prisma.managedService.create({ ...query, data: args.input, }) }, }), })) } }