Recall & Review
beginner
What is a Union type in GraphQL?
A Union type in GraphQL lets a field return one of several different object types. It helps when a query can return different shapes of data.
Click to reveal answer
beginner
How do you define a Union type in GraphQL schema?
Use the
union keyword followed by the union name and the possible types separated by |. For example: union SearchResult = Photo | PersonClick to reveal answer
intermediate
Can Union types include scalar types like String or Int?
No, Union types can only include object types, not scalar types like String or Int.
Click to reveal answer
intermediate
How do you query a field that returns a Union type?
You use inline fragments with
... on TypeName to specify fields for each possible type in the union.Click to reveal answer
advanced
Why use Union types instead of Interfaces in GraphQL?
Union types are for when the types don’t share fields. Interfaces require shared fields. Use Union when types are different and unrelated.
Click to reveal answer
Which keyword defines a Union type in GraphQL?
✗ Incorrect
The
union keyword is used to define a Union type in GraphQL.Can a Union type include scalar types like Int or String?
✗ Incorrect
Union types can only include object types, not scalar types.
How do you specify fields for each type in a Union when querying?
✗ Incorrect
Inline fragments with
... on TypeName let you select fields for each type in a Union.What is a key difference between Union types and Interfaces?
✗ Incorrect
Union types do not require shared fields, unlike Interfaces which do.
Which of these is a valid Union type definition?
✗ Incorrect
Union types can only include object types like Photo and Person, not scalars or enums.
Explain what a Union type is in GraphQL and how it differs from an Interface.
Think about when you want to return different shapes of data without common fields.
You got /4 concepts.
Describe how to query a field that returns a Union type and why inline fragments are needed.
Imagine you get different objects and want to ask for their specific details.
You got /4 concepts.