Bird
0
0

This GraphQL schema snippet has an error for one-to-many relationship. What is wrong?

medium📝 Debug Q14 of 15
GraphQL - Type Relationships
This GraphQL schema snippet has an error for one-to-many relationship. What is wrong?
type User { id: ID! name: String! posts: Post } type Post { id: ID! content: String! userId: ID! }
AThe posts field should be a list type [Post!]! instead of Post.
BThe userId field should be removed from Post.
CThe name field in User should be optional.
DThe id fields should be of type String, not ID.
Step-by-Step Solution
Solution:
  1. Step 1: Check the posts field type for one-to-many

    One user can have many posts, so posts must be a list, not a single Post.
  2. Step 2: Verify other fields

    userId in Post is correct to link back; name optionality and id type are unrelated.
  3. Final Answer:

    posts field must be a list [Post!]! -> Option A
  4. Quick Check:

    One-to-many needs list type for many children [OK]
Quick Trick: Use brackets [] for multiple related items in schema [OK]
Common Mistakes:
  • Using single object instead of list for many children
  • Removing foreign key fields mistakenly
  • Changing unrelated field types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes