You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
how can i display an arry of comment that's belong to a post under this single post.
this this typedefs type Post { id: ID! createdAt: DateTime! title: String! author: User! comments: [Comment!]! likes: [Like!]! } type Comment { id: ID! content: String! author: User! post: Post! }
this the query i am firing in apollo studio and i get back the right data query Post ($postId: ID!) { post(id: $postId) { id title comments { content author { name } } } }
this is what i am trying
name: {{post?.title}}
id: {{post?.id}}
author: {{post?.author?.username}}
likes: {{post?.likes?.length}}
// how i can display an array of comments
comments: {{post?.comments?.length}}
{{post?.comments.content}}
i get bacl all post field but not comments
and this the prisma model :
`model Post {
id Int @id@unique@default(autoincrement())
createdAt DateTime @default(now())
title String
author User @relation(fields: [authorId], references: [id], onDelete:Cascade)
authorId Int
comments Comment[]
likes Like[]
}
model Comment {
id Int @id@default(autoincrement())
createdAt DateTime @default(now())
content String
author User @relation(fields: [authorId], references: [id], onDelete:Cascade)
authorId Int
post Post @relation(fields: [postId], references: [id])
postId Int
}
`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
how can i display an arry of comment that's belong to a post under this single post.
this this typedefs
type Post { id: ID! createdAt: DateTime! title: String! author: User! comments: [Comment!]! likes: [Like!]! } type Comment { id: ID! content: String! author: User! post: Post! }
this the query i am firing in apollo studio and i get back the right data
query Post ($postId: ID!) { post(id: $postId) { id title comments { content author { name } } } }
this is what i am trying
// how i can display an array of comments
{{post?.comments.content}}
i get bacl all post field but not comments
and this the prisma model :
`model Post {
id Int @id @unique @default(autoincrement())
createdAt DateTime @default(now())
title String
author User @relation(fields: [authorId], references: [id], onDelete:Cascade)
authorId Int
comments Comment[]
likes Like[]
}
model Comment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
content String
author User @relation(fields: [authorId], references: [id], onDelete:Cascade)
authorId Int
post Post @relation(fields: [postId], references: [id])
postId Int
}
`
Beta Was this translation helpful? Give feedback.
All reactions