Bird
0
0

You want to fetch all authors with their books, but only include books published after 2020. How would you modify the GraphQL query?

hard📝 Application Q8 of 15
GraphQL - Type Relationships
You want to fetch all authors with their books, but only include books published after 2020. How would you modify the GraphQL query?
A{ authors { name books(publishedYear: 2020) { title } } }
B{ authors { name books { title publishedYear } } }
C{ authors { name books(filter: { publishedYear_gt: 2020 }) { title } } }
D{ authors { name books { title } } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering in nested queries

    To filter books by published year, use a filter argument on books field.
  2. Step 2: Identify correct filter syntax

    { authors { name books(filter: { publishedYear_gt: 2020 }) { title } } } uses filter with publishedYear_gt (greater than) 2020, correctly filtering books.
  3. Final Answer:

    { authors { name books(filter: { publishedYear_gt: 2020 }) { title } } } -> Option C
  4. Quick Check:

    Use filter argument to limit nested list items [OK]
Quick Trick: Use filter arguments to limit nested list results [OK]
Common Mistakes:
  • Not using filter argument for nested lists
  • Using equality instead of greater than for filtering
  • Ignoring filtering requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes