This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewFollower.sml
68 lines (58 loc) · 1.64 KB
/
newFollower.sml
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
59
60
61
62
63
64
65
66
67
68
fragment realworld {
"std" 1.0
}
# newFollower is analogous to "POST /api/profiles/:username/follow"
# resolving a mutation causing the creation of a subscription of the user
# identified by p:followerUsername to the user identified by p:followeeUsername
newFollower = (
# followerUsername identifies the user to create the subcription for
followerUsername Username,
# followeeUsername identifies the user to be followed
followeeUsername Username,
) -> (
std::Mutation<UserResolver> or
ErrUnauth or
ErrUserNotFound or
ErrFolloweeNotFound or
ErrFolloweeInvalid
) => {
follower = entity<User>(predicate: (u) => u.username == followerUsername)
followee = entity<User>(predicate: (u) => u.username == followeeUsername)
& = match {
// Ensure the follower exists
follower == Nil then ErrUserNotFound
// Ensure the followee exists
followee == Nil then ErrFolloweeNotFound
// Ensure the client is the follower
!isOwner(owner: User from follower) then ErrUnauth
// Ensure the user doesnt follow himself
id(User from follower) == id(User from followee) then
ErrFolloweeInvalid
else {
follower = User from follower
followee = User from followee
updatedFollowerProfile = User{
following: {
..follower.following,
followee,
},
..follower,
}
& = std::Mutation{
effects: {
// Update the follower profile
std::mutated(follower, updatedFollowerProfile),
// Update the followee profile
std::mutated(followee, User{
followers: {
..followee.followers,
follower,
},
..followee,
}),
},
data: UserResolver{user: updatedFollowerProfile},
}
}
}
}