rein
10/09/2017, 5:29 PMagartha
10/09/2017, 5:53 PMrein
10/09/2017, 5:56 PMagartha
10/09/2017, 5:59 PMrequested
. If you would call the two User fields 'from' and 'to', then incoming friend requests are all Friendship nodes with 'to' == currentUser && status 'requested', for examplejferrettiboke
10/09/2017, 6:04 PMenum FriendshipStatus {
PENDING
ACCEPTED
BLOCKED
}
type Friendship implements Node {
from: User @relation(name: "FriendshipOnUser")
id: ID! @isUnique
status: FriendshipStatus!
to: User @relation(name: "FriendshipOnUser1")
}
type User implements Node {
firstName: String!
id: ID! @isUnique
requestedFriends: [Friendship!]! @relation(name: "FriendshipOnUser")
targetedFriends: [Friendship!]! @relation(name: "FriendshipOnUser1")
}
Then, you can query the current user friendships like this, where $userId
is the current logged in user ID.
query FriendshipsForCurrentUser($userId: ID!) {
allFriendships(filter: {OR: [{from: {id: $userId}}, {to: {id: $userId}}], status: PENDING}) {
id
status
from {
firstName
}
to {
firstName
}
}
}
rein
10/09/2017, 7:32 PMrein
10/09/2017, 7:32 PMrein
10/09/2017, 7:34 PMrein
10/09/2017, 7:34 PMagartha
10/09/2017, 9:01 PMrein
10/09/2017, 9:16 PMrein
10/09/2017, 9:16 PMrein
10/09/2017, 9:16 PM