Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {Args, Parent, Query, ResolveField, Resolver} from "@nestjs/graphql";
import {Agent} from "./models/agent.model";
import {PrismaService} from "../prisma/prisma.service";
import {GraphQLString} from "graphql";
import {NotFoundException} from "@nestjs/common";
@Resolver(() => Agent)
export class AgentResolver {
constructor(
private prismaService: PrismaService,
) {}
@Query(() => [Agent])
listAgents() {
return this.prismaService.agent.findMany({
include: {
unlocks: true,
entries: true,
},
});
}
@Query(() => Agent)
async getAgent(
@Args({ name: 'code', type: () => GraphQLString }) code: string,
) {
const agent = await this.prismaService.agent.findFirst({
where: { slug: code },
});
if (!agent)
throw new NotFoundException();
return agent;
}
@ResolveField('unlocks')
async unlocks(@Parent() entry: Agent) {
const result = await this.prismaService.agent.findFirst({
where: { id: entry.id },
select: { unlocks: true },
});
return result.unlocks;
}
@ResolveField('entries')
async entries(@Parent() entry: Agent) {
const result = await this.prismaService.agent.findFirst({
where: { id: entry.id },
select: { entries: true },
});
return result.entries;
}
}