Bird
0
0

This resolver code throws an error:

medium📝 Debug Q7 of 15
GraphQL - Type Relationships
This resolver code throws an error:
const resolvers = {
  User: {
    posts: (parent) => {
      return parent.posts.map(p => p.title);
    }
  }
};

What is the most likely cause?
ASyntax error in map function
Bparent.posts is undefined or null
CMissing return statement
DGraphQL query missing posts field
Step-by-Step Solution
Solution:
  1. Step 1: Analyze posts resolver code

    It calls parent.posts.map, assuming parent.posts is an array.
  2. Step 2: Identify cause of error

    If parent.posts is undefined or null, calling map causes runtime error.
  3. Final Answer:

    parent.posts is undefined or null -> Option B
  4. Quick Check:

    Undefined array causes map error [OK]
Quick Trick: Check if parent.posts exists before mapping [OK]
Common Mistakes:
  • Assuming syntax error in map
  • Ignoring possibility of undefined parent.posts
  • Thinking missing return causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes