Recall & Review
beginner
What is an inline fragment in GraphQL?
An inline fragment lets you conditionally include fields in a query based on the type of the object. It helps when querying interfaces or unions to get fields specific to a certain type.
Click to reveal answer
beginner
How do you write an inline fragment in a GraphQL query?
Use three dots followed by
on TypeName inside curly braces. For example:<br>{ ... on User { name } } This fetches the name field only if the object is of type User.Click to reveal answer
intermediate
Why use inline fragments instead of separate queries?
Inline fragments let you get different fields for different types in a single query. This saves time and network calls, like ordering different toppings on one pizza instead of ordering many pizzas separately.Click to reveal answer
intermediate
Can inline fragments be used with interfaces and unions?
Yes! Inline fragments are especially useful with interfaces and unions because these types can represent multiple object types. Inline fragments let you ask for fields specific to each possible type.Click to reveal answer
beginner
What happens if the inline fragment type does not match the object type?
If the object type does not match the inline fragment type, the fields inside that fragment are ignored and not included in the result. This keeps the query safe and only returns relevant data.
Click to reveal answer
What symbol starts an inline fragment in GraphQL?
✗ Incorrect
Inline fragments start with three dots (...) followed by 'on TypeName'.
Inline fragments are most useful when querying which GraphQL types?
✗ Incorrect
Interfaces and unions can represent multiple types, so inline fragments help fetch fields specific to each type.
If an inline fragment's type does not match the object, what happens?
✗ Incorrect
Fields inside a non-matching inline fragment are ignored, so only relevant data is returned.
Which of these is a correct inline fragment syntax?
✗ Incorrect
The correct syntax is three dots, 'on', then the type name, followed by the fields in braces.
Why use inline fragments instead of separate queries?
✗ Incorrect
Inline fragments let you fetch fields for different types in one query, saving time and network resources.
Explain what inline fragments are and why they are useful in GraphQL queries.
Think about how you get different info for different types in one request.
You got /4 concepts.
Write the syntax for an inline fragment that fetches the 'title' field only if the object is of type 'Book'.
Use ... on TypeName { fields } format.
You got /4 concepts.