နားလည်ထားရမယ့် အချက်
Monolithic GraphQL server တစ်ခုတည်းက team ကြီးထွားလာလေ deploy/ownership conflict ဖြစ်လေဖြစ်ပါတယ်—team တစ်ခုချင်းစီက schema ရဲ့ own domain ကို ကိုယ်ပိုင် service အဖြစ် owned/deploy လုပ်ချင်ကြပါတယ်။ Apollo Federation ရဲ့ core idea က team တစ်ခုစီရဲ့ subgraph schema များကို `@key` directive ဖြင့် entity (ဥပမာ `Tutorial`) ကို identify ပြီး gateway (router) တစ်ခုက subgraphs များကို composed unified schema တစ်ခုအဖြစ် client ဆီ ဖော်ပြပေးတာပါ။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial Platform က `tutorials-service` (Tutorial entity ပိုင်) နဲ့ `authors-service` (Author entity ပိုင်) service နှစ်ခုအဖြစ် ခွဲထားမယ်ဆိုပါစို့—`tutorials-service` က `Tutorial @key(fields: "id")` ကို declare ပြီး `authors-service` က `Author @key(fields: "id")` declare ကာ `Tutorial.author` field ကို extend လုပ်ပေးပါတယ်။ Client အနေနဲ့ query တစ်ခုတည်းက gateway ကိုသာ ခေါ်ရပြီး service ခွဲထားကြောင်း လုံးဝမသိရပါ။
အတူတူ စမ်းရေးကြည့်မယ်
# tutorials-service subgraph
type Tutorial @key(fields: "id") {
id: ID!
title: String!
authorId: ID!
}
# authors-service subgraph
type Author @key(fields: "id") {
id: ID!
name: String!
}
extend type Tutorial @key(fields: "id") {
id: ID! @external
author: Author
}Federation ရဲ့ subgraph/gateway model ကို ရှင်းပြပြီး `@key` directive ရဲ့ role ကို နားလည်မည်။၅ မိနစ် စမ်းကြည့်
`comments-service` subgraph တစ်ခု design လုပ်ပြီး `Comment` entity ကို `Tutorial` (`tutorials-service` ပိုင်) နှင့် ဘယ်လို ချိတ်ဆက်မလဲ ရေးပါ။
သတိလေးတစ်ချက်
Federation ကို team တစ်ခုတည်း/service တစ်ခုတည်းရှိသေးတဲ့ project အစောပိုင်းမှာ အစောကြီး introduce လုပ်ရင် operational complexity (gateway, subgraph deploy coordination) က benefit ထက် ကျော်သွားနိုင်ပါတယ်—monolith က mature/team growth ဖြစ်မှ split လုပ်ပါ။
Apollo Federation — Introduction — GraphQL