import { schema } from 'nexus' import { CommentWhereInput, CommentOrderByInput } from 'nexus-plugin-prisma/client' export const Comment = schema.objectType({ name: 'Comment', definition(t) { t.model.id() t.model.createdAt() t.model.updatedAt() t.model.message() t.model.createdById() t.model.createdBy() t.model.serviceRequestAssociatedTo() t.model.task() t.model.mentionedUsers() }, }) export const CommentQueries = schema.extendType({ type: 'Query', definition(t) { t.crud.comment() t.crud.comments({ filtering: true, ordering: true }) t.field('comments', { type: 'Comment', list: true, args: { where: schema.arg({ type: 'CommentWhereInput' }), orderBy: schema.arg({ type: 'CommentOrderByInput', list: true }), first: schema.arg({ type: 'Int' }), skip: schema.arg({ type: 'Int' }), }, resolve: async ( parent, { where, orderBy, first, skip, }: { where?: CommentWhereInput orderBy?: CommentOrderByInput[] first?: number skip?: number }, ctx: NexusContext ) => { return ctx.prisma.comment.findMany({ where, skip, take: first, ...(orderBy?.length > 0 && { orderBy: orderBy[0] }), }) }, }) }, }) export const CommentMutation = schema.extendType({ type: 'Mutation', definition: (t) => { t.crud.deleteOneComment({ alias: 'deleteComment' }) t.crud.updateOneComment({ alias: 'updateComment' }) t.crud.createOneComment({ alias: 'createComment' }) }, })