0
0
GraphQLquery~10 mins

Union types in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a union type named SearchResult.

GraphQL
union SearchResult = [1] | Book | Author
Drag options to blanks, or click blank then click option'
AArticle
BSong
CMovie
DReview
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type not defined in the schema.
Forgetting to separate types with |.
2fill in blank
medium

Complete the query to search for a SearchResult by ID.

GraphQL
query { search(id: 1) { ... on [1] { title } ... on Author { name } } }
Drag options to blanks, or click blank then click option'
AMovie
BDirector
CPublisher
DBook
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type not in the union.
Missing the inline fragment syntax.
3fill in blank
hard

Fix the error in the union type definition by completing the code.

GraphQL
union SearchResult = Book | [1] | Author
Drag options to blanks, or click blank then click option'
AMovie
BString
CInt
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Including scalar types in union definitions.
Using types not defined as objects.
4fill in blank
hard

Fill both blanks to complete the query using inline fragments for SearchResult.

GraphQL
query { search(id: 2) { ... on [1] { title } ... on [2] { name } } }
Drag options to blanks, or click blank then click option'
ABook
BAuthor
CMovie
DPublisher
Attempts:
3 left
💡 Hint
Common Mistakes
Using types not in the union.
Forgetting to use inline fragments.
5fill in blank
hard

Fill all three blanks to define a union and query it correctly.

GraphQL
union SearchResult = [1] | [2] | Author

query { search(id: 3) { ... on [3] { title } ... on Author { name } } }
Drag options to blanks, or click blank then click option'
ABook
BMovie
CPublisher
DDirector
Attempts:
3 left
💡 Hint
Common Mistakes
Using scalar types in union.
Mismatch between union types and query fragments.