First time trying redwood and having some trouble getting my graphql queries to return correctly.
I’ve set up a many-to-many relationship as documented here: Docs - Schema Relations : RedwoodJS Docs
Testing the two queries below in the graphql playground, queryWord will correctly return a list of posts that include that word. However, queryPost returns null for the list of words even though my PostsOnWords table shows relationships exist
I’ve included my scheme.prisma files as well as the slightly modified SDL files for word and post schemas
query queryPost {
post (id:2) {
id
body
words {
word {
id
word
}
}
}
}
query queryWord {
word (id: 2) {
id
word
posts{
post {
id
body
}
}
}
}
model Post {
id Int @id @default(autoincrement())
title String
body String
body_string String @default("")
createdAt DateTime @default(now())
words PostsOnWords[]
}
model Word {
id Int @id @default(autoincrement())
word String
posts PostsOnWords[]
}
model PostsOnWords {
id Int @id @default(autoincrement())
post Post @relation(fields: [postId], references: [id])
postId Int // relation scalar field (used in the `@relation` attribute above)
word Word @relation(fields: [wordId], references: [id])
wordId Int // relation scalar field (used in the `@relation` attribute above)
assignedAt DateTime @default(now())
assignedBy String
@@unique([postId, wordId])
}
SDL for word table
export const schema = gql`
type Word {
id: Int!
word: String!
posts: [PostsOnWords]
}
type Query {
words: [Word!]! @skipAuth
word(id: Int!): Word @skipAuth
}
input CreateWordInput {
word: String!
}
input UpdateWordInput {
word: String
}
type Mutation {
createWord(input: CreateWordInput!): Word! @requireAuth
updateWord(id: Int!, input: UpdateWordInput!): Word! @requireAuth
deleteWord(id: Int!): Word! @requireAuth
}
`
SDL for post table
export const schema = gql`
type Post {
id: Int!
title: String!
body: String!
body_string: String!
createdAt: DateTime!
words: [PostsOnWords]
}
type Query {
posts: [Post!]! @skipAuth
post(id: Int!): Post @skipAuth
searchPosts(word: String!): [Post!]! @skipAuth
}
input CreatePostInput {
title: String!
body: String!
body_string: String!
}
input UpdatePostInput {
title: String
body: String
body_string: String
}
type Mutation {
createPost(input: CreatePostInput!): Post! @requireAuth
updatePost(id: Int!, input: UpdatePostInput!): Post! @requireAuth
deletePost(id: Int!): Post! @requireAuth
}
`