-
-
Notifications
You must be signed in to change notification settings - Fork 815
Expand file tree
/
Copy pathcomment.ts
More file actions
37 lines (33 loc) · 973 Bytes
/
comment.ts
File metadata and controls
37 lines (33 loc) · 973 Bytes
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
import { type IComment, Posts, Users } from "../../utils/data";
import { builder } from "../builder";
import { Post } from "./post";
import { User } from "./user";
export const Comment = builder.objectRef<IComment>("Comment");
const DEFAULT_PAGE_SIZE = 10;
Comment.implement({
fields: (t) => ({
id: t.exposeID("id"),
comment: t.exposeString("comment"),
author: t.field({
type: User,
nullable: true,
resolve: (comment) => [...Users.values()].find((user) => user.id === comment.authorId),
}),
post: t.field({
type: Post,
resolve: (comment) => [...Posts.values()].find((post) => post.id === comment.postId),
}),
}),
});
builder.queryFields((t) => ({
posts: t.field({
type: [Post],
nullable: true,
args: {
take: t.arg.int(),
skip: t.arg.int(),
},
resolve: (_root, { skip, take }) =>
[...Posts.values()].slice(skip ?? 0, (skip ?? 0) + (take ?? DEFAULT_PAGE_SIZE)),
}),
}));