-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.ts
50 lines (48 loc) · 1.07 KB
/
object.ts
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
import { builder } from "~/builder";
const OrderItemObject = builder.simpleObject("OrderItem", {
fields: (t) => ({
id: t.int({
nullable: false,
description: "The ID of the order item",
}),
name: t.string({
description: "The name of the order item",
nullable: false,
}),
price: t.float({
description: "The price of the order item",
nullable: false,
}),
}),
});
export const OrderObject = builder.simpleObject(
"Order",
{
fields: (t) => ({
id: t.int({
nullable: false,
description: "The ID of the order",
}),
items: t.field({
type: [OrderItemObject],
nullable: false,
description: "The items in the order",
}),
createdUserId: t.int({
nullable: false,
}),
}),
},
(t) => ({
total: t.float({
nullable: false,
description: "The total price of the order",
resolve: (order) => {
return order.items.reduce<number>(
(total, item) => total + item.price,
0
);
},
}),
})
);