Bird
0
0

Consider this GraphQL type definition:

medium📝 Debug Q14 of 15
GraphQL - Type Relationships
Consider this GraphQL type definition:
type User {
  id: ID!
  posts: Post
}

type Post {
  id: ID!
  content: String!
}

What is the main problem with this design if a user can have many posts?
AThe 'posts' field should be a list, not a single Post object.
BThe 'id' field is missing in User type.
CThe 'content' field should be nullable.
DThe Post type should include a reference back to User.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the 'posts' field type

    The 'posts' field is declared as a single Post, but users can have many posts.
  2. Step 2: Identify correct type for multiple posts

    To represent many posts, 'posts' should be a list like [Post!]! instead of a single Post.
  3. Final Answer:

    The 'posts' field should be a list, not a single Post object. -> Option A
  4. Quick Check:

    Multiple posts need list type, not single object [OK]
Quick Trick: Multiple related items need list type in GraphQL [OK]
Common Mistakes:
  • Thinking single object can hold many items
  • Ignoring list syntax for multiple relations
  • Assuming missing fields cause this error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes