0
0
GraphQLquery~5 mins

Search across types in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'Search across types' mean in GraphQL?
It means querying multiple different data types in a single search, so you can find results from various categories or objects at once.
Click to reveal answer
intermediate
How can you search across different types in GraphQL?
By using a union or interface type that groups multiple types together, then querying that union or interface to get results from all included types.
Click to reveal answer
beginner
What is a GraphQL union type?
A union type lets you combine multiple object types into one, so a query can return different types of objects in the same field.
Click to reveal answer
intermediate
Why use fragments when searching across types?
Fragments let you specify which fields to get from each type in a union or interface, so you get the right data for each kind of result.
Click to reveal answer
intermediate
Example: How to write a query that searches across 'Book' and 'Author' types?
Use a union type like 'union SearchResult = Book | Author' and query it with fragments for each type to get fields like title for Book and name for Author.
Click to reveal answer
What GraphQL feature allows combining multiple types for a single search?
AInput type
BScalar type
CUnion type
DEnum type
When querying a union type, how do you specify fields for each type?
AUsing fragments
BUsing variables
CUsing directives
DUsing enums
Which of these is NOT a valid use of searching across types?
AGetting user and product info together
BReturning only scalar values
CFinding books and authors in one query
DSearching multiple categories at once
What keyword defines a union type in GraphQL schema?
Aenum
Binterface
Ctype
Dunion
Can you use interfaces instead of unions for searching across types?
AYes, interfaces can also group types
BNo, only unions work
COnly with scalar types
DOnly in mutations
Explain how to perform a search across multiple types in GraphQL.
Think about how to combine types and get fields from each.
You got /4 concepts.
    Describe the difference between union types and interfaces when searching across types.
    Consider how each groups types and what fields they require.
    You got /3 concepts.