model User {
id Int @id @default(autoincrement())
username String @unique
email String @unique
password String
bio String?
avatar String?
followers User[] @relation("FollowRelation", references: [id])
following User[] @relation("FollowRelation", references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
photos Photo[]
likes Like[]
}
model Photo {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int
file String
caption String?
hashtags Hashtag[]
likes Like[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Hashtag {
id Int @id @default(autoincrement())
hashtag String @unique
photos Photo[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Like {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
photo Photo @relation(fields: [photoId], references: [id])
user User @relation(fields: [userId], references: [id])
photoId Int
userId Int
@@unique([photoId, userId])
}
import { gql } from 'apollo-server'
export default gql`
type Photo {
id: Int!
user: User!
file: String!
caption: String
hashtags: [Hashtag]
createdAt: String!
updatedAt: String!
likes: Int!
}
type Hashtag {
id: Int!
hashtag: String!
photos(page: Int!): [Photo]
totalPhotos: Int!
createdAt: String!
updatedAt: String!
}
type Like {
id: Int!
photo: Photo!
createdAt: String!
updatedAt: String!
}
`
check!!! relation,