နားလည်ထားရမယ့် အချက်
Mutation တစ်ခုက scalar argument များစွာ လက်ခံရမယ်ဆိုရင် `input` object type ဖြင့် ကိုတစ်ခုတည်းအဖြစ် group လုပ်ပေးနိုင်ပါတယ်—`input` types က output object types နဲ့ syntax ဆင်တူပေမယ့် field type ကို nested object type မဟုတ်ဘဲ scalar/enum/other input types သာ ခွင့်ပြုပါတယ်။ Input type ထဲမှာ list of input types (`lessons: [LessonInput!]!`) ထည့်ပြီး nested creation (tutorial + lessons) ကို request တစ်ခုတည်းနဲ့ လုပ်နိုင်ပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Author dashboard ရဲ့ "create tutorial" form ကို `CreateTutorialInput` ဖြင့် တစ်ခါတည်းပို့မယ်—`title`, `difficulty`, `lessons` (each with `title`/`durationMinutes`) ပါဝင်ပါတယ်။ Resolver ထဲမှာ lesson list length, duration range များကို application-level validate လုပ်ပြီး database transaction တစ်ခုတည်းနဲ့ tutorial+lessons ကို insert လုပ်ပါမယ်။
အတူတူ စမ်းရေးကြည့်မယ်
input LessonInput {
title: String!
durationMinutes: Int!
}
input CreateTutorialInput {
title: String!
difficulty: Difficulty!
lessons: [LessonInput!]!
}
mutation CreateTutorial($input: CreateTutorialInput!) {
createTutorial(input: $input) {
id
title
lessons {
title
}
}
}Nested input type ပါသော mutation တစ်ခုရေးပြီး related records များကို request တစ်ခုတည်းနဲ့ ဖန်တီးနိုင်မည်။၅ မိနစ် စမ်းကြည့်
`UpdateTutorialInput` (`title`, `summary`, `difficulty` — all optional) တစ်ခုရေးပြီး partial update ကို support လုပ်သော `updateTutorial` mutation တစ်ခု design လုပ်ပါ။
သတိလေးတစ်ချက်
Input type ထဲမှာ regular object type (ဥပမာ output `Author` type) ကို field type အဖြစ် ထည့်ဖို့ ကြိုးစားရင် schema build error ဖြစ်ပါတယ်—input type ထဲက field များက input types သာ ဖြစ်ရပါမယ်။