import { Args , Info , Mutation , Query , Resolver } from '@nestjs/graphql' ; import { PrismaSelect } from '@paljs/plugins' ; import { PrismaClient } from '@prisma/client' ; import { GraphQLResolveInfo } from 'graphql' ; import { Profile } from '../../@generated/profile/profile.model' ; import { AggregateUser } from '../../@generated/user/aggregate-user.output' ; import { User } from '../../@generated/user/user.model' ; import { UserAggregateArgs } from '../../@generated/user/user-aggregate.args' ; import { UserCreateInput } from '../../@generated/user/user-create.input' ; import { UserUpdateInput } from '../../@generated/user/user-update.input' ; import { UserWhereInput } from '../../@generated/user/user-where.input' ; import { CreateOneUserArgs } from '../../@generated/user/create-one-user.args' ; import { CreateManyUserArgs } from '../../@generated/user/create-many-user.args' ; import { UserDateInput } from './user-date.input' ; const prisma = new PrismaClient ( { errorFormat : 'colorless' , log : [ { emit : 'event' , level : 'query' , } , ] , } ) ; prisma . $on ( 'query' , event => { console . log ( event ) ; } ) ; /**
 * Resolves user object type.
 */ @ Resolver ( ( ) => User ) export class UserResolver { /**
     * Query for single user.
     */ @ Query ( ( ) => [ User ] ) async users ( @ Args ( 'where' ) where , @ Info ( ) info ) { const select = new PrismaSelect ( info ) . value ; return await prisma . user . findMany ( { where , ... select } ) ; } @ Mutation ( ( ) => User , { nullable : true } ) async userUpdate ( @ Args ( 'user' ) user ) { return ; } @ Mutation ( ( ) => User , { nullable : true } ) async userCreate ( @ Args ( 'user' ) user ) { return ; } @ Mutation ( ( ) => User , { nullable : true } ) async createOneUser ( @ Args ( ) args ) { console . log ( 'args' , args ) ; return ; } @ Mutation ( ( ) => User , { nullable : true } ) async userInfo ( @ Args ( 'user' ) user ) { console . log ( 'userInfo Args' , user . date , typeof user . date , user . date ?. constructor ) ; return ; } @ Mutation ( ( ) => [ User ] , { nullable : true } ) async createManyUsers ( @ Args ( ) createManyUserArgs ) { console . log ( 'createManyUserArgs' , createManyUserArgs ) ; return ; } @ Query ( ( ) => AggregateUser ) userAggregate ( @ Args ( ) args ) { return prisma . user . aggregate ( args ) ; } @ Query ( ( ) => Profile ) queryProfile ( ) { const p = new Profile ( ) ; p . id = 1 ; return p ; } }