純粋培養GraphQL / Pure GraphQL Architecture

942bb606679caf4c57b38927f83178e1?s=47 qsona
August 28, 2020

純粋培養GraphQL / Pure GraphQL Architecture

942bb606679caf4c57b38927f83178e1?s=128

qsona

August 28, 2020
Tweet

Transcript

  1. ७ਮഓཆGraphQL @qsona 2020-08-28 GraphQL Tokyo #10

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

    Microservices / Rails / Node.js / GraphQL
  3. લฤ: ৽نαʔϏε։ൃʹ͓͍ͯ બఆͨ͠ΞʔΩςΫνϟɾ
 ͦͷબఆཧ༝

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

    (ৄࡉ͸·ͩඇެ։) • ن໛ • Backend & Web Frontend devs: 6ਓ • Native devs: ~8ਓ͘Β͍ • ظؒ: > 1೥
  5. ΞʔΩςΫνϟ (Phase 1)

  6. ΞʔΩςΫνϟ (Phase 2)

  7. શൠతʹ GraphQL • શͯͷ API ʹ GraphQL Λར༻͍ͯ͠Δ • Client

    - Gateway • Gateway - Backend • Backend - Backend • ७ਮഓཆ GraphQL ͱͰ΋ݺΜͰ͓͜͏
  8. ୡ੒͔ͨͬͨ͜͠ͱ • ॳख͔ΒαʔϏε෼ׂ (Microservices) • Schema-driven development • Backend ͸

    Resource-based API Λอͭ
  9. (1) ॳख͔ΒαʔϏε෼ׂ (Microservices) • ৽ن "αʔϏε" ։ൃ ͕ͩɺ
 ׬શʹ৽ن"ࣄۀ"Ͱ͸ͳ͍ •

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

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

    => ޙ൒ͰਂೖΓ͢Δ • αʔϏεؒ௨৴΋ GraphQL Λར༻ • ݱࡏ͸ Ruby on Rails => Node.js ͷΞΫηε • ॴײ: ͭͳ͗͜Έ͕͔ͳΓ҆ఆ͢Δ
  12. (2) Schema-driven development • GraphQL Schema Λத৺ʹɺ։ൃϑϩʔΛਐΊΔ • ๬֎ʹ͏·͍ͬͯ͘Δ •

    νʔϜͷΞδϦςΟΛ
 ߴΊΔޮՌ΋
  13. (3) Backend ͸ Resource-based API Λอͭ • ஫: ࡉ͔͗͢ΔϦιʔε΍ɺ
 ςʔϒϧ୯ҐͷϦιʔεΛఏڙ͢Δͱ͍͏ҙຯͰ͸ͳ͍

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

    API ͱͷྑ͍ͱ͜ΖऔΓ͕Ͱ͖Δ • ؆୯ʹݴ͏ͱ...
 Schema શମ͕ Resource Λද͠
 Query ͕ Usecase Λද͢ • ৄ͘͠͸ӈͷࢿྉΛݟͯͶ!!
  15. ଞͷΞʔΩςΫνϟͱͷൺֱ • ७ਮഓཆ͡Όͳ͍GraphQLύλʔϯͱൺֱͯ͠ΈΔ • (a) GraphQL Gateway - REST/gRPC ύλʔϯ

    • (b) BFF (RPC) - GraphQL ύλʔϯ
  16. ଞͷΞʔΩςΫνϟͱͷൺֱ (a) GraphQL Gateway - REST/gRPC ύλʔϯ

  17. ଞͷΞʔΩςΫνϟͱͷൺֱ (a) GraphQL Gateway - REST/gRPC ύλʔϯ • ࢲݟ: Α΄Ͳͷཧ༝͕ͳ͚Ε͹


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

  19. ଞͷΞʔΩςΫνϟͱͷൺֱ (b) BFF (RPC) - GraphQL ύλʔϯ • ے͕ྑ͍ͱࢥ͍ͬͯΔ •

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

  21. GraphQL Gateway ͷ໾ׂ • schema Λ merge ͢Δ • Backend

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

  23. GraphQL Gateway ͷ໾ׂ - merge Backends Gateway merged schema

  24. GraphQL Gateway ͷ໾ׂ - merge Backends Gateway

  25. GraphQL Gateway ͷ໾ׂ - join Backends Gateway ^ ͜͜ʹ author:

    User! Λ௥Ճ͢Δ
  26. GraphQL Gateway ͷ࣮૷ख๏ • Schema stitching (ݱࡏར༻த) • Apollo Federation

    • GraphQL Mesh
  27. Schema stitching ͷػೳ • mergeSchema • delegateSchema • join ʹ࢖͑Δ

    (Ұखؒͷ࣮૷͕ඞཁ) • transformSchema • Schema ΛมߋͰ͖Δ (ϦωʔϜͳͲ)
  28. Schema stitching merge schema join

  29. Schema stitching ͷӡ༻ྫ

  30. Apollo Federation ࣮૷ - backends ଞαʔϏεͷSchemaΛ֦ுͯ͠ɺ ࣗαʔϏεʹؔ࿈͢ΔfieldΛੜ΍͍ͯ͠Δ

  31. Apollo Federation ࣮૷ - gateway શͯͷ৘ใ͸ Backend schema ʹ͋ΔͷͰɺ Gateway

    ͸ͨͩಡΈࠐΉ͚ͩ
  32. Apollo Federation • Schema stitching ͱͷҧ͍ • Schema stitching ͸

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

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

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

    Apollo Federation ͷௐࠪͱಋೖΛ͍ͨ͠ • ͞Βʹ࣍ͷ൒ظ ...
 طଘͷ RESTful / gRPC API ͱ΋ܨ͗͜ΜͰ͍͘
 => GraphQL Mesh ΛτϥΠͯ͠Έ͍ͨ
  36. Thank you for listening! • We're hiring! • ొ৔ͨ͠ϦϯΫ͸ Speaker

    Deck ͷ֓ཁཝʹ
 ͢΂ͯࡌ͓͖ͤͯ·͢