yantakus
11/13/2018, 11:31 AMvotePost resolver?
My current datamodel is the following:
type Video {
...
votes: [Vote!]! @relation(name: "VideoVotes")
voteScore: Int! @default(value: 0)
}
type Vote {
id: ID! @unique
parent: Video! @relation(name: "VideoVotes")
user: User! @relation(name: "UserVotes")
type: VoteType!
}
type User {
...
votes: [Vote!]! @relation(name: "UserVotes")
}
enum VoteType {
UP
DOWN
}nuno
11/13/2018, 12:31 PMnuno
11/13/2018, 12:33 PMtype Video {
...
votes: [User!]!
voteScore: Int! @default(value: 0)
}
type User {
...
votes: [Video!]!
}nuno
11/13/2018, 12:33 PMyantakus
11/13/2018, 12:46 PMVote type is needed, because it can be both upvote and downvote. I’ve updated the schema above to reflect it. Initially I omitted it for simplicity, didn’t think it’s important here.
voteScore is an Int field reflecting total score of all upvotes and downvotes of a Video. In my opinion it is easier to calculate it once at server when a video is voted than calculating it every time at front end.nuno
11/13/2018, 3:53 PMVote type and it would simplify the datamodel. But if you needed to add more data to votes (e.g. vote comments) it would be more difficult.nuno
11/13/2018, 3:55 PMUser only has a vote per Video in your mutation resolver.nuno
11/13/2018, 3:56 PMvoteScore from the datamodel, and calculate it in your GraphQL server, by counting the upVotes and downVotes.