Bird
0
0

Identify the error in this resolver chain code snippet:

medium📝 Debug Q14 of 15
GraphQL - Resolvers
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' };
    }
  }
};
AThe author resolver is missing the parent argument
BThe book resolver should return a list, not an object
CThe author resolver should not return an object
DThe Query resolver should have three arguments
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes