Complete the code to define a bidirectional relationship field in GraphQL schema.
type Author {
id: ID!
name: String!
books: [Book][1]
}
type Book {
id: ID!
title: String!
author: Author
}The @relation(name: "BooksByAuthor") directive defines the bidirectional link between Author.books and Book.author.
Complete the code to define the inverse side of the bidirectional relationship.
type Book {
id: ID!
title: String!
author: Author[1]
}The @relation(name: "BooksByAuthor") directive on Book.author matches the name used on Author.books to create a bidirectional link.
Fix the error in the bidirectional relationship by completing the missing directive.
type Author {
id: ID!
name: String!
books: [Book][1]
}
type Book {
id: ID!
title: String!
author: Author
}The correct relation name @relation(name: "BooksByAuthor") must be used to match the inverse side and fix the bidirectional link.
Fill both blanks to define a bidirectional relationship with explicit foreign key field.
type Author {
id: ID!
name: String!
books: [Book][1]
}
type Book {
id: ID!
title: String!
authorId: ID!
author: Author[2]
}fields and references on the foreign key side.The @relation(name: "BooksByAuthor") on Author.books and @relation(name: "BooksByAuthor", fields: [authorId], references: [id]) on Book.author define a bidirectional relationship with explicit foreign key.
Fill all three blanks to define a bidirectional relationship with custom relation name and explicit foreign key.
type User {
id: ID!
username: String!
posts: [Post][1]
}
type Post {
id: ID!
content: String!
userId: ID!
user: User[2][3]
}references on the foreign key side.The @relation(name: "UserPosts") on User.posts and @relation(name: "UserPosts", fields: [userId]) plus , references: [id] on Post.user define a bidirectional relationship with a custom name and explicit foreign key.