what’s the best approach to do the following, I wa...
# prisma-whats-new
r
what’s the best approach to do the following, I want to: - have a video view counter (increments when someone watches a video) - save user progress history Now I have the following mutation
Copy code
mutation CreateUserMutation($viewedVideoVideoId: ID!, $viewedByUserId: ID!) {
addToViewedVideos(
viewedVideoVideoId: $viewedVideoVideoId,
viewedByUserId: $viewedByUserId
) {
viewedByUser {
id
}
}
}`
and the following
types.grapql
Copy code
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!