Recall & Review
beginner
What is a one-to-many relationship in databases?
It is a connection where one record in a table can be linked to many records in another table. For example, one author can write many books.
Click to reveal answer
beginner
How do you represent a one-to-many relationship in GraphQL?
You use a field in the 'one' type that returns a list of the 'many' type. For example, an Author type has a books field that returns a list of Book types.
Click to reveal answer
intermediate
Why is a foreign key important in one-to-many relationships?
A foreign key in the 'many' table points back to the 'one' table, linking records together. It helps keep data connected and organized.
Click to reveal answer
intermediate
Example: In GraphQL, how would you define an Author type with many books?
type Author {
id: ID!
name: String!
books: [Book!]!
} This means each author has a list of books.
Click to reveal answer
beginner
What happens if you try to query a one-to-many field in GraphQL?
You get a list of related records. For example, querying an author's books returns all books written by that author.
Click to reveal answer
In a one-to-many relationship, which side holds the foreign key?
✗ Incorrect
The 'many' side holds the foreign key pointing to the 'one' side.
How do you represent multiple related items in a GraphQL type?
✗ Incorrect
You use a list (array) of objects to represent multiple related items.
Which GraphQL type field best shows a one-to-many relationship?
✗ Incorrect
A list of Book objects (books: [Book!]) shows many books related to one author.
What does the exclamation mark (!) mean in GraphQL types like ID! or [Book!]?
✗ Incorrect
The exclamation mark means the field cannot be null; it is required.
If an Author has many Books, what would a query for an author’s books return?
✗ Incorrect
The query returns a list of all books related to that author.
Explain how a one-to-many relationship works using a real-life example.
Think about how one teacher can have many students.
You got /3 concepts.
Describe how you would define a one-to-many relationship in a GraphQL schema.
Focus on how the 'one' type includes a list of the 'many' type.
You got /3 concepts.