A relationship connects two or more pieces of data to show how they relate to each other, like how a person owns a car.
Click to reveal answer
beginner
Why do relationships help model real-world data?
Because real-world things are connected, relationships let us represent these connections clearly in data, making it easier to understand and use.
Click to reveal answer
beginner
Give an example of a real-world relationship modeled in data.
A student enrolls in courses. The relationship between students and courses shows which students take which classes.
Click to reveal answer
intermediate
How do relationships improve data organization?
They reduce repetition by linking related data instead of copying it, which keeps data clean and easier to update.
Click to reveal answer
intermediate
What types of relationships commonly exist in databases?
Common types are one-to-one, one-to-many, and many-to-many, describing how many items in one group relate to items in another.
Click to reveal answer
What does a relationship in a database represent?
AA database user
BA type of data format
CA programming language
DA connection between data items
✗ Incorrect
A relationship shows how data items are connected, like linking a customer to their orders.
Which relationship type means one item relates to many items?
AMany-to-many
BOne-to-one
COne-to-many
DNo relationship
✗ Incorrect
One-to-many means one item connects to many others, like one teacher with many students.
Why do relationships reduce data repetition?
ABy copying data multiple times
BBy linking data instead of copying
CBy deleting data
DBy encrypting data
✗ Incorrect
Relationships link data items so you don’t have to store the same data repeatedly.
Which example shows a real-world relationship?
AA book has an author
BA book is a color
CA book is a number
DA book is a fruit
✗ Incorrect
A book having an author shows a real-world connection modeled as a relationship.
What is the main benefit of modeling relationships in data?
AShows how data items connect
BMakes data harder to understand
CRemoves all data
DChanges data types
✗ Incorrect
Modeling relationships helps us see how data items connect, reflecting real-world links.
Explain why relationships are important for modeling real-world data.
Think about how things in life are connected and how data can show that.
You got /4 concepts.
Describe the common types of relationships in databases and give a simple example for each.
Focus on how many items in one group relate to items in another.
You got /4 concepts.
Practice
(1/5)
1. Why do relationships between types in GraphQL help model real-world data?
easy
A. They store data in separate databases automatically.
B. They make the data types run faster in queries.
C. They remove the need for any fields in types.
D. They connect different data types to show how things relate in real life.
Solution
Step 1: Understand the purpose of relationships in data
Relationships link different data types to represent how real-world things connect.
Step 2: Identify how GraphQL uses relationships
GraphQL uses fields in types to show these connections clearly without duplicating data.
Final Answer:
They connect different data types to show how things relate in real life. -> Option D
Quick Check:
Relationships = Real-world connections [OK]
Hint: Think of relationships as real-life links between things [OK]
Common Mistakes:
Confusing relationships with performance improvements
Thinking relationships remove fields
Assuming relationships create separate databases
2. Which of the following is the correct way to define a relationship field in a GraphQL type?
easy
A. type Book { author -> Author }
B. type Book { author = Author }
C. type Book { author: Author }
D. type Book { author: "Author" }
Solution
Step 1: Recall GraphQL field syntax
Fields are defined as fieldName: TypeName without extra symbols or quotes.
Step 2: Check each option
type Book { author: Author } uses correct syntax with colon and type name. Others use invalid symbols or quotes.
Final Answer:
type Book { author: Author } -> Option C
Quick Check:
Field syntax = name: Type [OK]
Hint: Use colon (:) between field and type in GraphQL [OK]
Common Mistakes:
Using equals (=) instead of colon
Using arrows (->) instead of colon
Putting type name in quotes
3. Given the GraphQL types:
type Author { id: ID name: String books: [Book] } type Book { id: ID title: String author: Author }
What will the query <code>{ author(id: "1") { name books { title } } }?
medium
A. Only the list of books without author info
B. Author's name and a list of their books' titles
C. Only the author's name
D. An error because of circular references
Solution
Step 1: Analyze the query structure
The query asks for an author by id, then requests the author's name and their books' titles.
Step 2: Understand the relationship fields
The author type has a books field which is a list of Book types, so nested fields like title can be fetched.
Final Answer:
Author's name and a list of their books' titles -> Option B
Quick Check:
Nested fields return connected data [OK]
Hint: Nested fields fetch related data in one query [OK]
Common Mistakes:
Thinking circular references cause errors in GraphQL
Expecting only one level of data returned
Ignoring nested fields in query
4. Identify the error in this GraphQL type definition:
type User { id: ID name: String posts: Post }
Assuming a user can have many posts, what is wrong?
medium
A. posts field should be a list type, like [Post]
B. posts field should be a scalar type like String
C. posts field should be named postList
D. posts field should be inside a separate type
Solution
Step 1: Understand the data relationship
A user can have many posts, so posts must hold multiple Post objects.
Step 2: Check the field type
The field posts is defined as a single Post, but it should be a list of Post, written as [Post].
Final Answer:
posts field should be a list type, like [Post] -> Option A
Quick Check:
Multiple items = list type [OK]
Hint: Use square brackets [] for lists in GraphQL types [OK]
Common Mistakes:
Using single type for multiple items
Changing field name unnecessarily
Thinking fields must be in separate types
5. You want to model a social network where users can follow many other users. Which GraphQL type definition correctly models this relationship?
hard
A. type User { id: ID name: String followers: [User] following: [User] }
B. type User { id: ID name: String followers: User following: User }
C. type User { id: ID name: String followers: String following: String }
D. type User { id: ID name: String followers: [String] following: [String] }
Solution
Step 1: Understand the relationship type
Users can follow many other users, so followers and following must be lists of User type.
Step 2: Check each option's field types
type User { id: ID name: String followers: [User] following: [User] } correctly uses lists of User for both followers and following. Others use single User or String types incorrectly.
Final Answer:
type User { id: ID name: String followers: [User] following: [User] } -> Option A
Quick Check:
Many-to-many = lists of same type [OK]
Hint: Use lists of the same type for many-to-many relationships [OK]
Common Mistakes:
Using single User type for multiple followers
Using String instead of User type
Confusing field types with scalar lists
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.