GraphQL - Type RelationshipsYou 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 } } }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand filtering in nested queriesTo filter books by published year, use a filter argument on books field.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.Final Answer:{ authors { name books(filter: { publishedYear_gt: 2020 }) { title } } } -> Option CQuick 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 listsUsing equality instead of greater than for filteringIgnoring filtering requirements
Master "Type Relationships" in GraphQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More GraphQL Quizzes GraphQL Basics and Philosophy - Over-fetching and under-fetching problems - Quiz 9hard GraphQL Basics and Philosophy - Schema-first development - Quiz 1easy Mutations - Delete mutation pattern - Quiz 7medium Mutations - Delete mutation pattern - Quiz 9hard Queries - Aliases for field renaming - Quiz 13medium Resolvers - Context argument - Quiz 10hard Resolvers - Resolver function signature - Quiz 2easy Schema Definition Language (SDL) - List types - Quiz 7medium Schema Definition Language (SDL) - Type definitions - Quiz 2easy Schema Definition Language (SDL) - Scalar types (String, Int, Float, Boolean, ID) - Quiz 4medium