-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.ts
More file actions
56 lines (52 loc) · 1.05 KB
/
object.ts
File metadata and controls
56 lines (52 loc) · 1.05 KB
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
import { builder } from "~/builder";
const UserTypeEnum = builder.enumType("UserType", {
values: {
HUMAN: {
description: "A human user",
value: "Human",
},
ROBOT: {
description: "A robot user",
value: "Robot",
},
},
});
export const UserObject = builder.simpleInterface("User", {
fields: (t) => ({
id: t.int({
nullable: false,
}),
name: t.string({
nullable: false,
}),
type: t.field({
type: UserTypeEnum,
nullable: false,
}),
}),
resolveType: (user) => {
if (user.type === "Human") {
return "Human";
} else {
return "Robot";
}
},
});
builder.simpleObject("Human", {
interfaces: [UserObject],
fields: (t) => ({
registrationNumber: t.string({
description: "The registration number of the human",
nullable: false,
}),
}),
});
builder.simpleObject("Robot", {
interfaces: [UserObject],
fields: (t) => ({
modelNumber: t.string({
description: "The model number of the robot",
nullable: false,
}),
}),
});