Bird
Raised Fist0
GraphQLquery~20 mins

Resolver chains in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Resolver Chain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Output of nested resolver chain
Given a GraphQL schema where a Book type has an 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" }
A{"data":{"book":{"title":"1984","authorId":42}}}
B{"data":{"book":{"title":"1984","author":{"name":"George Orwell"}}}}
C{"data":{"book":{"title":"1984","author":null}}}
D{"errors":[{"message":"Cannot resolve author"}]}
Attempts:
2 left
💡 Hint
Think about how nested resolvers return the final nested object.
🧠 Conceptual
intermediate
1:30remaining
Understanding resolver chain execution order
In a GraphQL query with nested fields, in what order are resolvers executed?
AParent field resolvers execute first, then child field resolvers execute after parent resolves.
BAll resolvers execute in parallel regardless of nesting.
CChild field resolvers execute first, then parent field resolvers.
DResolvers execute randomly without order.
Attempts:
2 left
💡 Hint
Think about how the parent resolver must provide data for the child resolver.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in resolver chaining
Which resolver function below will cause a syntax error when used in a resolver chain?
Aauthor: (parent) => fetchAuthorById(parent.authorId);
Bauthor: async (parent) => { return await fetchAuthorById(parent.authorId); }
Cauthor: (parent) => { fetchAuthorById(parent.authorId) }
Dauthor: (parent) => fetchAuthorById(parent.authorId)
Attempts:
2 left
💡 Hint
Look for misplaced punctuation like semicolons.
🔧 Debug
advanced
2: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?
AThe schema does not define the nested field.
BThe parent resolver returned null instead of an object.
CThe GraphQL query is missing the nested field.
DThe child resolver is not using the correct field name from the parent object.
Attempts:
2 left
💡 Hint
Check how the child resolver accesses data from the parent.
❓ optimization
expert
3: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?
ARemove the author field from the schema to avoid calls.
BFetch authors inside each book resolver separately without optimization.
CBatch author fetches by collecting all authorIds and querying once in a single resolver.
DCache each author fetch individually without batching.
Attempts:
2 left
💡 Hint
Think about how to fetch multiple related records efficiently.

Practice

(1/5)
1. What is the main purpose of resolver chains in GraphQL?
easy
A. To speed up database indexing
B. To create new database tables automatically
C. To fetch data step-by-step using results from previous resolvers
D. To encrypt data before sending it to clients

Solution

  1. Step 1: Understand resolver chains concept

    Resolver chains allow each resolver to use data from the previous resolver's result, enabling step-by-step data fetching.
  2. Step 2: Compare options with concept

    Only To fetch data step-by-step using results from previous resolvers describes this stepwise data fetching using parent results, which matches the purpose of resolver chains.
  3. Final Answer:

    To fetch data step-by-step using results from previous resolvers -> Option C
  4. Quick Check:

    Resolver chains = step-by-step data fetching [OK]
Hint: Resolver chains pass data stepwise between resolvers [OK]
Common Mistakes:
  • Confusing resolver chains with database indexing
  • Thinking resolver chains create tables
  • Assuming resolver chains encrypt data
2. Which of the following is the correct way to access the parent resolver's result in a GraphQL resolver function?
easy
A. function resolver(args, context) { ... }
B. function resolver(args, parent, context) { ... }
C. function resolver(context, args, parent) { ... }
D. function resolver(parent, args, context) { ... }

Solution

  1. Step 1: Recall resolver function signature

    In GraphQL, the first argument to a resolver is the parent object, followed by args and context.
  2. Step 2: Match signature with options

    Only function resolver(parent, args, context) { ... } correctly places parent as the first argument, allowing access to previous resolver's result.
  3. Final Answer:

    function resolver(parent, args, context) { ... } -> Option D
  4. Quick Check:

    Parent is first argument in resolver [OK]
Hint: Parent is always the first argument in resolver functions [OK]
Common Mistakes:
  • Swapping order of arguments
  • Omitting the parent argument
  • Confusing context with parent
3. Given the following resolver chain, what will be the final output?
const resolvers = {
  Query: {
    user: () => ({ id: 1, name: 'Alice' })
  },
  User: {
    posts: (parent) => [
      { id: 101, title: 'Post 1', authorId: parent.id },
      { id: 102, title: 'Post 2', authorId: parent.id }
    ]
  }
};

// Query: { user { name posts { title } } }
medium
A. { user: { name: 'Alice', posts: [] } }
B. { user: { name: 'Alice', posts: [{ title: 'Post 1' }, { title: 'Post 2' }] } }
C. { user: { name: 'Alice', posts: [{ title: 'Post 1' }, { title: 'Post 2' }, { title: 'Post 3' }] } }
D. Error: Cannot read property 'id' of undefined

Solution

  1. Step 1: Analyze user resolver output

    The user resolver returns an object with id 1 and name 'Alice'.
  2. Step 2: Analyze posts resolver using parent

    The posts resolver receives parent with id 1, so it returns two posts with authorId 1 and titles 'Post 1' and 'Post 2'.
  3. Final Answer:

    { user: { name: 'Alice', posts: [{ title: 'Post 1' }, { title: 'Post 2' }] } } -> Option B
  4. Quick Check:

    Posts use parent.id = 1, two posts returned [OK]
Hint: Parent contains previous resolver's data for next resolver [OK]
Common Mistakes:
  • Assuming posts resolver returns three posts
  • Expecting empty posts array
  • Confusing parent argument as undefined
4. Identify the error in this resolver chain code snippet:
const resolvers = {
  Query: {
    book: () => ({ id: 5, title: 'GraphQL Guide' })
  },
  Book: {
    author: (args) => {
      return { id: 2, name: 'John Doe' };
    }
  }
};
medium
A. The author resolver is missing the parent argument
B. The book resolver should return a list, not an object
C. The author resolver should not return an object
D. The Query resolver should have three arguments

Solution

  1. Step 1: Check author resolver signature

    The author resolver should receive the parent object as the first argument to access book data.
  2. Step 2: Identify missing parent argument

    Here, author resolver only has args, so it cannot access parent data, breaking the resolver chain.
  3. Final Answer:

    The author resolver is missing the parent argument -> Option A
  4. Quick Check:

    Resolvers need parent as first argument [OK]
Hint: Always include parent as first argument in chained resolvers [OK]
Common Mistakes:
  • Ignoring parent argument in nested resolvers
  • Thinking book resolver must return a list
  • Assuming author resolver cannot return objects
5. You want to fetch a list of orders with their customer names using resolver chains. The orders resolver returns an array of orders with customerId. How should you implement the customer resolver to correctly use resolver chains?
hard
A. Use the parent argument to get customerId and fetch customer data from database
B. Ignore the parent argument and fetch all customers in the customer resolver
C. Pass customerId as an argument to the orders resolver
D. Return a static customer object without using parent data

Solution

  1. Step 1: Understand data flow in resolver chains

    The orders resolver returns orders with customerId; the customer resolver uses parent to access customerId.
  2. Step 2: Use parent argument in customer resolver

    The customer resolver should use parent.customerId to fetch the correct customer data from the database.
  3. Final Answer:

    Use the parent argument to get customerId and fetch customer data from database -> Option A
  4. Quick Check:

    Parent passes customerId to customer resolver [OK]
Hint: Use parent.customerId in customer resolver to fetch data [OK]
Common Mistakes:
  • Fetching all customers instead of one
  • Ignoring parent and missing customerId
  • Returning static data ignoring dynamic parent info
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard