GraphQL - Type RelationshipsWhich of the following is the correct GraphQL syntax to define a many-to-many relationship between two types, Author and Book?Atype Author { books: [Book!]! } type Book { authors: [Author!]! }Btype Author { book: Book } type Book { author: Author }Ctype Author { books: Book } type Book { authors: Author }Dtype Author { books: Book! } type Book { authors: Author! }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand many-to-many syntaxMany-to-many uses lists on both sides to represent multiple connections.Step 2: Check options for list syntaxtype Author { books: [Book!]! } type Book { authors: [Author!]! } uses lists ([Book!]! and [Author!]!) correctly, others do not use lists properly.Final Answer:type Author { books: [Book!]! } type Book { authors: [Author!]! } -> Option AQuick Check:Many-to-many syntax = lists on both sides [OK]Quick Trick: Many-to-many uses lists on both sides [OK]Common Mistakes:Using single object instead of listMissing non-null markersConfusing list syntax
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 8hard GraphQL Basics and Philosophy - First GraphQL query - Quiz 1easy Mutations - Delete mutation pattern - Quiz 4medium Mutations - Input type for complex arguments - Quiz 1easy Queries - Why queries request specific data - Quiz 12easy Queries - Inline fragments - Quiz 6medium Schema Definition Language (SDL) - Input types - Quiz 8hard Type Relationships - One-to-one relationships - Quiz 1easy Type Relationships - Many-to-many relationships - Quiz 10hard Type Relationships - One-to-one relationships - Quiz 8hard