Introduction
Many-to-many relationships let us connect items from two groups where each item can link to many items in the other group. This helps organize complex connections clearly.
type Student {
id: ID!
name: String!
courses: [Course!]!
}
type Course {
id: ID!
title: String!
students: [Student!]!
}type Author {
id: ID!
name: String!
books: [Book!]!
}
type Book {
id: ID!
title: String!
authors: [Author!]!
}type User {
id: ID!
username: String!
followedTopics: [Topic!]!
}
type Topic {
id: ID!
name: String!
followers: [User!]!
}type Student {
id: ID!
name: String!
courses: [Course!]!
}
type Course {
id: ID!
title: String!
students: [Student!]!
}
# Sample query to get a student and their courses
query {
student(id: "1") {
name
courses {
title
}
}
}Author and Book?Author can have many Books and each Book can have many Authors.Author and Book types should have a list field referencing the other type.Book in Author and a list of Author in Book -> Option AStudent and Course?[Course!]! and [Student!]!.query { students { name courses { title } } }students with their name and nested courses with title.courses is a list on Student, the result includes each student's name and their list of course titles.type User { groups: Group } type Group { users: User }groups and users are single objects, not lists.User can link to only one Group and vice versa, not many, so it breaks many-to-many.groups and users are not lists, so only one group or user can be linked -> Option BArtist and Album. You want to fetch all artists with their albums, but only include albums released after 2020. Which GraphQL query correctly applies this filter?where with conditions such as releaseYear_gt: 2020 to filter nested lists.query { artists { name albums(where: { releaseYear_gt: 2020 }) { title releaseYear } } } correctly places the where argument inside the albums field to filter albums after 2020.where argument inside nested field [OK]Pass the test and this pattern moves unknown