This is how my schema.prisma file looks like.
model Artist {
id Int @id @default(autoincrement())
name String
slug String
image String
songs Song[]
comments Comment[]
}
model Song {
id Int @id @default(autoincrement())
artist Artist @relation(fields: [artistId], references: [id])
artistId Int
title String
image String
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
song Song? @relation(fields: [songId], references: [id])
songId Int?
date DateTime
type String // VIDEO | IMAGE | TEXT
action String // ADDED | UPDATED
content String
comments Comment[]
}
model Comment {
id Int @id @default(autoincrement())
content String
post Post @relation(fields: [postId], references: [id])
postId Int
artist Artist @relation(fields: [artistId], references: [id])
artistId Int
}
An artist can leave comment on a post (which actually belongs to a song of another ARTIST).
CREATE_COMMENT_MUTATION works properly and I can see comments are added.
But the ARTIST_QUERY and POST_QUERY don’t return the comments data in their result.
I need to retrieve all posts data of an artist which also includes comments left for each post.
So I call this query in my Cell, but it doesn’t return comments data.
export const QUERY = gql`
query FindArtistBySlug($slug: String!) {
artist: artistBySlug(slug: $slug) {
id
name
slug
image
songs {
id
artistId
title
image
posts {
id
songId
date
type
action
content
comments {
content
}
}
}
}
}
`
In my mind, there are two possible cases :
-
Any mistake in defining relationships between COMMENT and POST models in my schema.prisma?
I don’t think so because same format used in making 1:n relationship between SONG / POST and POST / COMMENT. Whenever I create new post, I can see correct data retrieved in SONG_QUERY. -
Do I have to run multiple queries in my CELL?
Please help me with this.
I am digging into RedwoodJS but new to it.
Thanks in advance.