-
-
Notifications
You must be signed in to change notification settings - Fork 814
Expand file tree
/
Copy pathuser.ts
More file actions
36 lines (33 loc) · 994 Bytes
/
user.ts
File metadata and controls
36 lines (33 loc) · 994 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
import { Comments, type IUser, Posts, Users } from "../../utils/data";
import { builder } from "../builder";
import { Comment } from "./comment";
import { Post } from "./post";
export const User = builder.objectRef<IUser>("User");
User.implement({
fields: (t) => ({
id: t.exposeID("id"),
firstName: t.exposeString("firstName"),
lastName: t.exposeString("lastName"),
fullName: t.string({
resolve: (user) => `${user.firstName} ${user.lastName}`,
}),
posts: t.field({
type: [Post],
resolve: (user) => [...Posts.values()].filter((post) => post.authorId === user.id),
}),
comments: t.field({
type: [Comment],
resolve: (user) => [...Comments.values()].filter((comment) => comment.authorId === user.id),
}),
}),
});
builder.queryFields((t) => ({
user: t.field({
type: User,
nullable: true,
args: {
id: t.arg.id({ required: true }),
},
resolve: (_root, args) => Users.get(String(args.id)),
}),
}));