rick
11/08/2017, 9:35 AMmutation CreateUserMutation($viewedVideoVideoId: ID!, $viewedByUserId: ID!) {
addToViewedVideos(
viewedVideoVideoId: $viewedVideoVideoId,
viewedByUserId: $viewedByUserId
) {
viewedByUser {
id
}
}
}`
and the following types.grapql
type User @model {
# Required system field:
id: ID! @isUnique # read-only (managed by Graphcool)
# Optional system fields (remove if not needed):
createdAt: DateTime! # read-only (managed by Graphcool)
updatedAt: DateTime! # read-only (managed by Graphcool)
facebookUserId: String @isUnique
email: String # optional, because it's obtained from Facebook API
name: String # optional, because it's obtained from Facebook API
viewedVideos: [Video!]! @relation(name: "viewedVideos")
}
# Uncomment the model below as well
type Video @model {
id: ID! @isUnique # read-only (managed by Graphcool)
createdAt: DateTime! # read-only (managed by Graphcool)
updatedAt: DateTime! # read-only (managed by Graphcool)
videoId: Int @isUnique
# Every relation also required a back-relation (to determine 1:1, 1:n or n:m)
viewedByUsers: [User!]! @relation(name: "viewedVideos")
}
Implementing the counter is pretty straightforward now, the only thing that I’m not sure about is storing the user progress per video in a smart way, I probably want to store it on the user, but I’m not sure what’s the best way. I want to be able to send the videoId
to retrieve the progress and I’m not sure if that possible if I save the watch history as a JSON like {"1231": 0.8}
. Any advice would be much appreciated!