Upgrade to Pro — share decks privately, control downloads, hide ads and more …

純粋培養GraphQL / Pure GraphQL Architecture

qsona
August 28, 2020

純粋培養GraphQL / Pure GraphQL Architecture

qsona

August 28, 2020
Tweet

More Decks by qsona

Other Decks in Technology

Transcript

  1. whoami • @qsona • Web Engineer at Quipper Ltd •

    Microservices / Rails / Node.js / GraphQL
  2. Զͨͪͷ৽نαʔϏε։ൃ • ࡞Δ΋ͷ: App (iOS/Android, Ұ෦ WebView) / Backend •

    (ৄࡉ͸·ͩඇެ։) • ن໛ • Backend & Web Frontend devs: 6ਓ • Native devs: ~8ਓ͘Β͍ • ظؒ: > 1೥
  3. શൠతʹ GraphQL • શͯͷ API ʹ GraphQL Λར༻͍ͯ͠Δ • Client

    - Gateway • Gateway - Backend • Backend - Backend • ७ਮഓཆ GraphQL ͱͰ΋ݺΜͰ͓͜͏
  4. (1) ॳख͔ΒαʔϏε෼ׂ (Microservices) • ৽ن "αʔϏε" ։ൃ ͕ͩɺ
 ׬શʹ৽ن"ࣄۀ"Ͱ͸ͳ͍ •

    جຊతʹྑ͘஌͍ͬͯΔυϝΠϯͰɺ
 ίϯςΩετͱͦͷڥք͕ݟ͍͑ͯΔ • ͦͷڥքʹԊͬͨద੾ͳαʔϏε෼ׂΛ
 ॳख͔Β΍͓͖͍ͬͯͨ
  5. (1) ॳख͔ΒαʔϏε෼ׂ (Microservices) Microservices ߏ੒ʹ͢ΔͨΊʹ... • API Gateway ·ͨ͸ BFF

    (Backends for Frontends) ͷ૚͕ඞཁ • (͜ͷ2ͭͷҧ͍͸ॾઆ͋Δ͕ɺݸਓతͳ੔ཧͱͯ͠͸...)
 API Gateway: جຊతʹϏδωεϩδοΫΛॻ͔ͳ͍ɻόοΫΤϯυΤϯδχΞ͕։ൃ͢Δͷ͕Ұൠతɻ
 BFF: ΫϥΠΞϯτͷͨΊͷϏδωεϩδοΫΛॻ͘ɻΫϥΠΞϯτΤϯδχΞ͕։ൃ͢ΔͷΛਪ঑ɻ • αʔϏεؒͷAPI࿈ܞ͕ඞཁ
  6. (1) => ΞʔΩςΫνϟͱͷରԠ • API Gateway ύλʔϯΛ࠾༻ • ͢΂ͯΛGraphQLʹ͢Δ͜ͱͰɺΠϯςάϨʔγϣϯΛ௿ίετʹ •

    => ޙ൒ͰਂೖΓ͢Δ • αʔϏεؒ௨৴΋ GraphQL Λར༻ • ݱࡏ͸ Ruby on Rails => Node.js ͷΞΫηε • ॴײ: ͭͳ͗͜Έ͕͔ͳΓ҆ఆ͢Δ
  7. (3) Backend ͸ Resource-based API Λอͭ • ஫: ࡉ͔͗͢ΔϦιʔε΍ɺ
 ςʔϒϧ୯ҐͷϦιʔεΛఏڙ͢Δͱ͍͏ҙຯͰ͸ͳ͍

    • Ϧιʔεͷཻ౓ͷߟ࡯͸ඞཁ • ݸผͷ Usecase ͝ͱͷରԠΛ
 ͳΔ΂ͨ͘͘͠ͳ͍
  8. (3) Backend ͸ Resource-based API Λอͭ • GraphQL ͷ࠾༻ʹΑΓɺ
 Usecase-based

    API ͱͷྑ͍ͱ͜ΖऔΓ͕Ͱ͖Δ • ؆୯ʹݴ͏ͱ...
 Schema શମ͕ Resource Λද͠
 Query ͕ Usecase Λද͢ • ৄ͘͠͸ӈͷࢿྉΛݟͯͶ!!
  9. ଞͷΞʔΩςΫνϟͱͷൺֱ (a) GraphQL Gateway - REST/gRPC ύλʔϯ • ࢲݟ: Α΄Ͳͷཧ༝͕ͳ͚Ε͹


    ৽نαʔϏεͰબ୒͢Δཧ༝͕ͳ͍ • Cons • Gateway Ͱϓϩτίϧม׵͢Δͷ͕໘౗ • ݁ہɺ͋Δఔ౓͸
 Backend ͕ Usecase API Λ࡞Δඞཁ͕ग़ͯ͘Δ
  10. ଞͷΞʔΩςΫνϟͱͷൺֱ (b) BFF (RPC) - GraphQL ύλʔϯ • ے͕ྑ͍ͱࢥ͍ͬͯΔ •

    Backend ͸ Resource-based API Λ࡞Γɺ
 Ϣʔεέʔε͔Βղ์͞ΕΔ • Client ͸ࣗ෼ͨͪͷϢʔεέʔεΛBFFʹ࣮૷Ͱ͖Δ • ࠓճ BFF Λ࠾༻͠ͳ͔ͬͨཧ༝ • ΫϥΠΞϯτ΋όοΫΤϯυ΋ಉ͡νʔϜͰ։ൃ͍ͯ͘͠ͷͰɺ
 ม׵͢Δ૚͕ͦ͜·ͰඞཁʹͳΒͳ͍
  11. GraphQL Gateway ͷ໾ׂ • schema Λ merge ͢Δ • Backend

    ͷෳ਺ͷ GraphQL Schema Λ·ͱΊͯදग़͠ɺ
 ϦΫΤετ͕དྷͨΒΫΤϦΛ෼ղͯ͠ޙΖʹྲྀ͢ • (SQLతͳҙຯͷ) join ͢Δ • ΫϥΠΞϯτ޲͚ͷͪΐͬͱͨ͠ϩδοΫ • ೝূ / ͦͷଞ API Gateway ҰൠʹٻΊΒΕΔ໾ׂ
  12. Schema stitching ͷػೳ • mergeSchema • delegateSchema • join ʹ࢖͑Δ

    (Ұखؒͷ࣮૷͕ඞཁ) • transformSchema • Schema ΛมߋͰ͖Δ (ϦωʔϜͳͲ)
  13. Apollo Federation • Schema stitching ͱͷҧ͍ • Schema stitching ͸

    Gateway server ͕ओମతʹू໿͍ͯ͘͠ • Federation ͸ ֤ Backend servers ʹએݴతʹɺ
 ू໿ͷ৘ใΛશͯهड़͢Δ
  14. GraphQL Mesh • GraphQL API ͚ͩͰͳ͘ɺRESTful (OpenAPI) ΍ gRPC ͳͲ΋

    ू໿͢Δ͜ͱ͕Ͱ͖Δ • (࣌ؒͷؔ܎Ͱলུ)
  15. Mesh ͷҙຯ • Schema stitching ͸͋͘·Ͱ࣮૷Ͱ͋Δɻ • Federation / GraphQL

    Mesh ͸ɺू໿ͷํ๏ͷએݴͰ͋Γɺ Gateway Server ͕ඞਢͰ͸ͳ͍ • Service to Service ͷ৔߹͸ɺ௚઀ෳ਺αʔϏεΛୟ͍ͯू໿ Ͱ͖Δɻ
  16. Զͨͪͷ৽نαʔϏεʹ͓͚Δ༧ఆ • ͜Ε·Ͱ ... Schema stitching Ͱ࣮૷ΛਐΊͨ • ࣍ͷ൒ظ ...

    Apollo Federation ͷௐࠪͱಋೖΛ͍ͨ͠ • ͞Βʹ࣍ͷ൒ظ ...
 طଘͷ RESTful / gRPC API ͱ΋ܨ͗͜ΜͰ͍͘
 => GraphQL Mesh ΛτϥΠͯ͠Έ͍ͨ