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

Tooling နှင့် Introspection

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

  • Tooling နှင့် Introspection concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ GraphQL query/code ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် မှန်ကန်စွာအသုံးချနိုင်ရန်

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

GraphQL schema က self-describing ဖြစ်လို့ special introspection queries (`__schema`, `__type`) ဖြင့် schema structure ကို runtime မှာတောင်း/ဖတ်နိုင်ပါတယ်။ GraphiQL နဲ့ Apollo Sandbox လို in-browser IDE tools တွေက ဒီ introspection data ကို သုံးပြီး autocomplete, inline docs, query validation ကို live ပေးပါတယ်—developer က schema file ကို tab ခြားဖတ်စရာမလိုတော့ပါ။ Production မှာတော့ introspection ကို attacker အတွက် schema map ဖြစ်နိုင်လို့ disable လုပ်လေ့ရှိပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Development environment မှာ Apollo Server ရဲ့ default Sandbox ကနေ Tutorial Platform schema ရဲ့ types အားလုံးကို browse ပြီး `Tutorial` type ရဲ့ fields များကို `__type(name: "Tutorial")` query ဖြင့် တိုက်ရိုက်ကြည့်နိုင်ပါတယ်။ Production deploy မှာတော့ `introspection: false` သတ်မှတ်ထားလေ့ရှိပါတယ်။

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

graphql
query IntrospectTutorialType {
  __type(name: "Tutorial") {
    name
    fields {
      name
      type {
        name
        kind
      }
    }
  }
}
You should see
Introspection query ဖြင့် type တစ်ခုရဲ့ fields များကို runtime မှာ ရှာဖွေနိုင်မည်။

၅ မိနစ် စမ်းကြည့်

Apollo Sandbox (သို့) GraphiQL ကိုဖွင့်ပြီး schema တစ်ခုရဲ့ root `Query` type အောက်ရှိ field အားလုံးကို docs panel ဖြင့် ရှာဖွေကြည့်ပါ။

သတိလေးတစ်ချက်

Production API မှာ introspection ကို ဖွင့်ထားခဲ့ရင် schema တစ်ခုလုံး (field names, types, deprecated fields) ကို public exposure ဖြစ်သွားနိုင်ပါတယ်—sensitive internal naming ပါလာရင် သတိထားပါ။

GraphQL — IntrospectionGraphQL

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

  • Production API မှာ introspection ကို ဖွင့်ထားခဲ့ရင် schema တစ်ခုလုံး (field names, types, deprecated fields) ကို public exposure ဖြစ်သွားနိုင်ပါတယ်—sensitive internal naming ပါလာရင် သတိထားပါ။
  • နမူနာ query/mutation ကို production API ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test server နှင့် recoverable data ပေါ်တွင် အရင်အတည်ပြုပါ။

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

Apollo Sandbox (သို့) GraphiQL ကိုဖွင့်ပြီး schema တစ်ခုရဲ့ root `Query` type အောက်ရှိ field အားလုံးကို docs panel ဖြင့် ရှာဖွေကြည့်ပါ။

You'll know it worked when: Introspection query ဖြင့် type တစ်ခုရဲ့ fields များကို runtime မှာ ရှာဖွေနိုင်မည်။

Tooling နှင့် Introspection | Thuta Learning