Thuta Learning
ရှာဖွေရန်
GraphQL
ExercisesWeb Developmentbeginner

Exercise — E-commerce Product Catalog Schema ဒီဇိုင်းလုပ်ခြင်း

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Exercise — E-commerce Product Catalog Schema ဒီဇိုင်းလုပ်ခြင်း concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ GraphQL query/code ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် မှန်ကန်စွာအသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

ဒီ 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 ထပ်ထည့်ပါ။

အတူတူ စမ်းရေးကြည့်မယ်

graphql
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 mutation
You should see
Products/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 TypesGraphQL

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Category ကို `Product.category: Category!` (single, non-null) လို့ design မိရင် product တစ်ခုက category အများကြီးမှာ ပါဝင်နိုင်တဲ့ real e-commerce requirement ကို schema level မှာ လုံးဝ ဖော်ပြနိုင်မှာ မဟုတ်ပါ—many-to-many ဖြစ်ရင် list field သုံးပါ။
  • နမူနာ query/mutation ကို production API ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test server နှင့် recoverable data ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

အပေါ်က starter schema ကို `Query` type (products list, product by id, category by id) နှင့် `CreateReviewInput` + `createReview` mutation ဖြင့် ပြည့်စုံအောင် ဆက်ရေးပါ။ Pagination connection pattern ကို `products` list field မှာလည်း လျှောက်ကြည့်ပါ။

You'll know it worked when: Products/categories/reviews အကြား relationship ကို schema design အဖြစ် ကိုယ်တိုင်ရေးနိုင်မည်။

Exercise — E-commerce Product Catalog Schema ဒီဇိုင်းလုပ်ခြင်း | Thuta Learning