Complete the code to define a one-to-many relationship between Author and Book.
type Author {
id: ID!
name: String!
books: [[1]!]!
}The books field in Author should be a list of Book objects to represent a one-to-many relationship.
Complete the code to define a many-to-many relationship between Student and Course.
type Student {
id: ID!
name: String!
courses: [[1]!]!
}
type Course {
id: ID!
title: String!
students: [Student!]!
}The courses field in Student should be a list of Course objects to represent many-to-many relationships.
Fix the error in the code to correctly define a one-to-one relationship between User and Profile.
type User {
id: ID!
username: String!
profile: [1]
}
type Profile {
id: ID!
bio: String
user: User!
}The profile field should be a single Profile object, not a list, and it should be non-nullable to represent a one-to-one relationship.
Fill both blanks to define a bidirectional one-to-many relationship between Category and Product.
type Category {
id: ID!
name: String!
products: [[1]!]!
}
type Product {
id: ID!
name: String!
category: [2]!
}The products field in Category is a list of Product objects, and the category field in Product is a single Category object, both non-nullable.
Fill all three blanks to define a many-to-many relationship with an intermediate type Enrollment between Student and Course.
type Student {
id: ID!
name: String!
enrollments: [[1]!]!
}
type Course {
id: ID!
title: String!
enrollments: [Enrollment!]!
}
type Enrollment {
id: ID!
student: [2]!
course: [3]!
}The enrollments fields in Student and Course reference the Enrollment type. The Enrollment type links back to Student and Course with non-nullable fields.