Bird
0
0

Consider this nested resolver code:

medium📝 Debug Q14 of 15
GraphQL - Type Relationships
Consider this nested resolver code:
const resolvers = {
  Author: {
    books: (parent) => {
      return books.filter(book => book.authorId = parent.id);
    }
  }
};

What is the error in this resolver?
AUsing assignment '=' instead of comparison '===' in filter
BMissing return statement in resolver
CIncorrect resolver name 'books' instead of 'bookList'
DParent argument is not passed to resolver
Step-by-Step Solution
Solution:
  1. Step 1: Identify filter condition mistake

    The filter uses '=' which assigns value instead of '===' which compares values.
  2. Step 2: Understand impact of '=' in filter

    Using '=' causes all books to be included or unexpected behavior, not filtering correctly.
  3. Final Answer:

    Using assignment '=' instead of comparison '===' in filter -> Option A
  4. Quick Check:

    Filter condition must use '===' not '=' [OK]
Quick Trick: Use '===' for comparison inside filter functions [OK]
Common Mistakes:
  • Confusing '=' with '===' in conditions
  • Forgetting to return filtered array
  • Assuming resolver name must match data variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes