Build the mental model
This lesson is a design exercise, not runnable app code — it asks you to reapply schema and type-system ideas (lesson 3), relationships (lesson 8), enums/interfaces (lesson 9), input types (lesson 11), and pagination connections (lesson 13) to a fresh e-commerce domain. Deciding how to model relationships among products, categories, and reviews practices real, interview-style GraphQL schema-design skill.
Connect it to a real scenario
Mentally map the Tutorial Platform's course-catalog structure (tutorials/authors/categories) onto its e-commerce equivalent (products/sellers/categories) — model `Product↔Category` (many-to-many) the same way you modeled `Tutorial↔Category` earlier. Model reviews the way you modeled comments, adding a `rating: Int!` field.
Try the working example
type Product {
id: ID!
name: String!
priceCents: Int!
categories: [Category!]!
reviews: [Review!]!
}
type Category {
id: ID!
name: String!
products: [Product!]!
}
type Review {
id: ID!
rating: Int!
body: String
author: String!
}
# TODO: add Query fields for browsing products by category
# TODO: add a CreateReviewInput and a createReview mutationYou can design and write a schema modeling relationships among products, categories, and reviews.5-minute try-it
Complete the starter schema above with a `Query` type (products list, product by id, category by id) and a `CreateReviewInput` plus `createReview` mutation. Also try applying the pagination connection pattern to the `products` list field.
One important caution
Designing `Product.category: Category!` as a single non-null field cannot express the real e-commerce requirement that a product belongs to many categories — use a list field when the relationship is many-to-many.
GraphQL — Schemas and Types — GraphQL