Bird
0
0

Given this resolver code snippet:

medium📝 query result Q13 of 15
GraphQL - Resolvers
Given this resolver code snippet:
const resolver = (parent, args, context) => {
  return context.db.getUserById(args.id);
};

What will resolver(null, {id: 5}, context) return if context.db.getUserById(5) returns { id: 5, name: 'Alice' }?
Anull
B{ id: 5, name: 'Alice' }
Cundefined
DError: getUserById is not a function
Step-by-Step Solution
Solution:
  1. Step 1: Understand the resolver call

    The resolver calls context.db.getUserById with args.id which is 5.
  2. Step 2: Check the return value from context

    Given context.db.getUserById(5) returns { id: 5, name: 'Alice' }, the resolver returns this object.
  3. Final Answer:

    { id: 5, name: 'Alice' } -> Option B
  4. Quick Check:

    Resolver returns context.db.getUserById(args.id) result [OK]
Quick Trick: Resolver returns what context function returns for given args [OK]
Common Mistakes:
  • Assuming resolver returns null or undefined
  • Confusing parent argument with context
  • Expecting an error without checking context structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes