GraphQL - Type RelationshipsWhich of the following is the correct syntax to define a one-to-many relationship in a GraphQL type?Atype Author { books: Book[] }Btype Author { books: Book }Ctype Author { books: [Book] }Dtype Author { books: Book! }Check Answer
Step-by-Step SolutionSolution:Step 1: Identify how to represent multiple related items in GraphQLSquare brackets [] indicate a list of items in GraphQL types.Step 2: Match this to the optionsOnly type Author { books: [Book] } uses [Book] to show many books related to an author.Final Answer:type Author { books: [Book] } -> Option CQuick Check:List syntax uses brackets = D [OK]Quick Trick: Use square brackets [] for lists in GraphQL types [OK]Common Mistakes:Using Book without brackets for multiple itemsUsing Book! which means non-null single itemUsing Book[] which is invalid syntax in GraphQL
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 6medium GraphQL Basics and Philosophy - Single endpoint architecture - Quiz 5medium Mutations - Create mutation pattern - Quiz 12easy Mutations - Input arguments for mutations - Quiz 7medium Queries - Field selection - Quiz 5medium Resolvers - Default resolvers - Quiz 8hard Resolvers - Args argument - Quiz 6medium Resolvers - Parent (root) argument - Quiz 14medium Schema Definition Language (SDL) - Type definitions - Quiz 15hard Type Relationships - Bidirectional relationships - Quiz 10hard