နားလည်ထားရမယ့် အချက်
ဒီ lesson က runnable app code မဟုတ်ဘဲ SDL design exercise တစ်ခုပါ—course တစ်ခုလုံးက schema/type system (lesson 3), relationships (lesson 8), enums/interfaces (lesson 9), input types (lesson 11), pagination connections (lesson 13) တွေကို e-commerce domain အသစ်တစ်ခုအပေါ် ကိုယ်တိုင်ပြန်အသုံးချကြည့်ဖို့ပါ။ Products, categories, reviews အကြား relationship ကို ဘယ်လို model လုပ်မလဲဆိုတာက real interview-style GraphQL schema design skill ကို practice လုပ်စေပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial Platform ရဲ့ course catalog (tutorials/authors/categories) structure ကို e-commerce equivalent (products/sellers/categories) အဖြစ် mentally map လုပ်ကြည့်ပါ—`Tutorial↔Category` relationship ကို ယခင် lesson များမှာ လေ့လာခဲ့သလို `Product↔Category` (many-to-many) အဖြစ် ပြန်ဆောက်ကြည့်ပါ။ Reviews ကို `Comment` type လို pattern ကို လိုက်ပြီး `rating: Int!` field ထပ်ထည့်ပါ။
အတူတူ စမ်းရေးကြည့်မယ်
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 mutationProducts/categories/reviews အကြား relationship ကို schema design အဖြစ် ကိုယ်တိုင်ရေးနိုင်မည်။၅ မိနစ် စမ်းကြည့်
အပေါ်က starter schema ကို `Query` type (products list, product by id, category by id) နှင့် `CreateReviewInput` + `createReview` mutation ဖြင့် ပြည့်စုံအောင် ဆက်ရေးပါ။ Pagination connection pattern ကို `products` list field မှာလည်း လျှောက်ကြည့်ပါ။
သတိလေးတစ်ချက်
Category ကို `Product.category: Category!` (single, non-null) လို့ design မိရင် product တစ်ခုက category အများကြီးမှာ ပါဝင်နိုင်တဲ့ real e-commerce requirement ကို schema level မှာ လုံးဝ ဖော်ပြနိုင်မှာ မဟုတ်ပါ—many-to-many ဖြစ်ရင် list field သုံးပါ။
GraphQL — Schemas and Types — GraphQL