I know the deletion is not supported currently, but my app needs this and I am seeking the best solution to deal with this requirement.
I have Profile and Follow models, when a profile follows another, a follow data is created, but when they unfollow, we cannot delete that follow so the relation and relation count are now incorrect. I am not sure what is the best way to deal with this problem.
I ended up adding a “status” property in the Follow model and set it to “ACTIVE” on created, and when the user unfollows, update it to “INACTIVE”, and on the UI I filter out the “INACTIVE” items. This works, but the UI has to do the heavy logic and I am looking for a better solution. Any suggestions? Please.
Here are the models.
type Profile
@createModel(
accountRelation: SINGLE
description: "A profile of an account"
) {
name: String! @string(minLength: 3, maxLength: 64)
}
type Follow
@createModel(accountRelation: LIST, description: "A follow of a profile") {
followerId: StreamID! @documentReference(model: "Profile")
follower: Profile! @relationDocument(property: "followerId")
followingId: StreamID! @documentReference(model: "Profile")
following: Profile! @relationDocument(property: "followingId")
status: Status!
}
enum Status {
ACTIVE
INACTIVE
}
And this is the relation.
type Follow @loadModel(id: "$FOLLOW_ID") {
id: ID!
}
type Profile @loadModel(id: "$PROFILE_ID") {
followers: [Follow]! @relationFrom(model: "Follow", property: "followerId")
followersCount: Int! @relationCountFrom(model: "Follow", property: "followerId")
following: [Follow]! @relationFrom(model: "Follow", property: "followingId")
followingCount: Int! @relationCountFrom(model: "Follow", property: "followingId")
}