Bird
0
0

You want to write a resolver that returns the full name by combining parent.firstName and parent.lastName. Which of the following resolver signatures and implementations is correct?

hard📝 Application Q8 of 15
GraphQL - Resolvers
You want to write a resolver that returns the full name by combining parent.firstName and parent.lastName. Which of the following resolver signatures and implementations is correct?
Afunction resolver(parent) { return `${parent.firstName} ${parent.lastName}`; }
Bfunction resolver(args) { return `${args.firstName} ${args.lastName}`; }
Cfunction resolver(context) { return `${context.firstName} ${context.lastName}`; }
Dfunction resolver(info) { return `${info.firstName} ${info.lastName}`; }
Step-by-Step Solution
Solution:
  1. Step 1: Identify where firstName and lastName come from

    These are properties of the parent object, so the resolver must accept parent as the first argument.
  2. Step 2: Check each option's argument and usage

    Only function resolver(parent) { return `${parent.firstName} ${parent.lastName}`; } uses parent and accesses firstName and lastName correctly; others use wrong arguments.
  3. Final Answer:

    function resolver(parent) { return `${parent.firstName} ${parent.lastName}`; } -> Option A
  4. Quick Check:

    Use parent for parent fields data [OK]
Quick Trick: Use parent to access parent field data in resolver [OK]
Common Mistakes:
  • Using args instead of parent for parent data
  • Using context or info incorrectly
  • Not combining names properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes