Bird
0
0

Identify the error in this resolver function using the parent argument:

medium📝 Debug Q14 of 15
GraphQL - Resolvers
Identify the error in this resolver function using the parent argument:
const resolvers = {
  User: {
    posts(args) {
      return postsData.filter(post => post.userId === args.id);
    }
  }
};
AThe resolver should not use <code>filter</code> on postsData.
BThe resolver is missing the <code>parent</code> argument as the first parameter.
CThe resolver should use <code>context</code> instead of <code>args</code>.
DThe resolver function name should be <code>Posts</code> with uppercase P.
Step-by-Step Solution
Solution:
  1. Step 1: Check resolver function parameters

    The resolver function must have parent as the first argument to access parent data.
  2. Step 2: Identify misuse of args instead of parent

    The code incorrectly uses args.id instead of parent.id to filter posts.
  3. Final Answer:

    The resolver is missing the parent argument as the first parameter. -> Option B
  4. Quick Check:

    Parent argument must be first in resolver [OK]
Quick Trick: Always include parent as first resolver argument [OK]
Common Mistakes:
  • Using args instead of parent for parent data
  • Ignoring resolver parameter order
  • Assuming function name case matters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes