Challenge - 5 Problems
Resolver Chain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of nested resolver chain
Given a GraphQL schema where a Book type has an
Assume the resolvers are:
-
-
author field resolved by a chain of resolvers, what is the output of this query?{ book(id: 1) { title author { name } } }Assume the resolvers are:
-
book returns { id: 1, title: "1984", authorId: 42 }-
author resolver fetches author by authorId and returns { id: 42, name: "George Orwell" }Attempts:
2 left
💡 Hint
Think about how nested resolvers return the final nested object.
✗ Incorrect
The
book resolver returns the book object with authorId. The author resolver uses that authorId to fetch and return the author object with the name. So the nested author field resolves to the author object with the name.🧠 Conceptual
intermediate1:30remaining
Understanding resolver chain execution order
In a GraphQL query with nested fields, in what order are resolvers executed?
Attempts:
2 left
💡 Hint
Think about how the parent resolver must provide data for the child resolver.
✗ Incorrect
Resolvers execute top-down. The parent resolver must finish and return data before the child resolver can run because the child depends on the parent's result.
📝 Syntax
advanced2:00remaining
Identify the syntax error in resolver chaining
Which resolver function below will cause a syntax error when used in a resolver chain?
Attempts:
2 left
💡 Hint
Look for misplaced punctuation like semicolons.
✗ Incorrect
Option A includes a trailing semicolon after the arrow function expression, causing a syntax error when defining the resolver as a property value in an object literal.
🔧 Debug
advanced2:30remaining
Why does the nested resolver return null?
A nested resolver in a chain returns null unexpectedly. The parent resolver returns an object with
authorId, but the child resolver returns null. What is the most likely cause?Attempts:
2 left
💡 Hint
Check how the child resolver accesses data from the parent.
✗ Incorrect
If the child resolver expects a field like
authorId but the parent object uses a different field name or the child accesses a wrong property, it will fail to fetch the nested data and return null.❓ optimization
expert3:00remaining
Optimizing resolver chains to reduce database calls
In a resolver chain where multiple books each resolve their authors, how can you optimize to reduce the number of database calls?
Attempts:
2 left
💡 Hint
Think about how to fetch multiple related records efficiently.
✗ Incorrect
Batching author fetches by collecting all needed authorIds and querying once reduces the number of database calls and improves performance.