Skip to content
Snippets Groups Projects
entry.resolver.ts 686 B
Newer Older
  • Learn to ignore specific revisions
  • Pascal Kosak's avatar
    Pascal Kosak committed
    import { Parent, Query, ResolveField, Resolver } from '@nestjs/graphql';
    import { Entry } from './models/entry.model';
    import { PrismaService } from '../prisma/prisma.service';
    
    Pascal Kosak's avatar
    Pascal Kosak committed
    
    @Resolver(() => Entry)
    export class EntryResolver {
    
    Pascal Kosak's avatar
    Pascal Kosak committed
        constructor(private prismaService: PrismaService) {}
    
    Pascal Kosak's avatar
    Pascal Kosak committed
    
        @Query(() => [Entry])
        listEntries() {
            return this.prismaService.entry.findMany({
                take: 200,
            });
        }
    
        @ResolveField('agent')
        async agent(@Parent() entry: Entry) {
            const result = await this.prismaService.entry.findFirst({
                where: { id: entry.id },
                select: { agent: true },
            });
    
            return result.agent;
        }
    }