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. ७ਮഓཆGraphQL
    @qsona
    2020-08-28 GraphQL Tokyo #10

    View full-size slide

  2. whoami
    • @qsona
    • Web Engineer at Quipper Ltd
    • Microservices / Rails / Node.js / GraphQL

    View full-size slide

  3. લฤ: ৽نαʔϏε։ൃʹ͓͍ͯ
    બఆͨ͠ΞʔΩςΫνϟɾ

    ͦͷબఆཧ༝

    View full-size slide

  4. Զͨͪͷ৽نαʔϏε։ൃ
    • ࡞Δ΋ͷ: App (iOS/Android, Ұ෦ WebView) / Backend
    • (ৄࡉ͸·ͩඇެ։)
    • ن໛
    • Backend & Web Frontend devs: 6ਓ
    • Native devs: ~8ਓ͘Β͍
    • ظؒ: > 1೥

    View full-size slide

  5. ΞʔΩςΫνϟ (Phase 1)

    View full-size slide

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

    View full-size slide

  7. શൠతʹ GraphQL
    • શͯͷ API ʹ GraphQL Λར༻͍ͯ͠Δ
    • Client - Gateway
    • Gateway - Backend
    • Backend - Backend
    • ७ਮഓཆ GraphQL ͱͰ΋ݺΜͰ͓͜͏

    View full-size slide

  8. ୡ੒͔ͨͬͨ͜͠ͱ
    • ॳख͔ΒαʔϏε෼ׂ (Microservices)
    • Schema-driven development
    • Backend ͸ Resource-based API Λอͭ

    View full-size slide

  9. (1) ॳख͔ΒαʔϏε෼ׂ (Microservices)
    • ৽ن "αʔϏε" ։ൃ ͕ͩɺ

    ׬શʹ৽ن"ࣄۀ"Ͱ͸ͳ͍
    • جຊతʹྑ͘஌͍ͬͯΔυϝΠϯͰɺ

    ίϯςΩετͱͦͷڥք͕ݟ͍͑ͯΔ
    • ͦͷڥքʹԊͬͨద੾ͳαʔϏε෼ׂΛ

    ॳख͔Β΍͓͖͍ͬͯͨ

    View full-size slide

  10. (1) ॳख͔ΒαʔϏε෼ׂ (Microservices)
    Microservices ߏ੒ʹ͢ΔͨΊʹ...
    • API Gateway ·ͨ͸ BFF (Backends for Frontends) ͷ૚͕ඞཁ
    • (͜ͷ2ͭͷҧ͍͸ॾઆ͋Δ͕ɺݸਓతͳ੔ཧͱͯ͠͸...)

    API Gateway: جຊతʹϏδωεϩδοΫΛॻ͔ͳ͍ɻόοΫΤϯυΤϯδχΞ͕։ൃ͢Δͷ͕Ұൠతɻ

    BFF: ΫϥΠΞϯτͷͨΊͷϏδωεϩδοΫΛॻ͘ɻΫϥΠΞϯτΤϯδχΞ͕։ൃ͢ΔͷΛਪ঑ɻ
    • αʔϏεؒͷAPI࿈ܞ͕ඞཁ

    View full-size slide

  11. (1) => ΞʔΩςΫνϟͱͷରԠ
    • API Gateway ύλʔϯΛ࠾༻
    • ͢΂ͯΛGraphQLʹ͢Δ͜ͱͰɺΠϯςάϨʔγϣϯΛ௿ίετʹ
    • => ޙ൒ͰਂೖΓ͢Δ
    • αʔϏεؒ௨৴΋ GraphQL Λར༻
    • ݱࡏ͸ Ruby on Rails => Node.js ͷΞΫηε
    • ॴײ: ͭͳ͗͜Έ͕͔ͳΓ҆ఆ͢Δ

    View full-size slide

  12. (2) Schema-driven development
    • GraphQL Schema Λத৺ʹɺ։ൃϑϩʔΛਐΊΔ
    • ๬֎ʹ͏·͍ͬͯ͘Δ
    • νʔϜͷΞδϦςΟΛ

    ߴΊΔޮՌ΋

    View full-size slide

  13. (3) Backend ͸ Resource-based API Λอͭ
    • ஫: ࡉ͔͗͢ΔϦιʔε΍ɺ

    ςʔϒϧ୯ҐͷϦιʔεΛఏڙ͢Δͱ͍͏ҙຯͰ͸ͳ͍
    • Ϧιʔεͷཻ౓ͷߟ࡯͸ඞཁ
    • ݸผͷ Usecase ͝ͱͷରԠΛ

    ͳΔ΂ͨ͘͘͠ͳ͍

    View full-size slide

  14. (3) Backend ͸ Resource-based API Λอͭ
    • GraphQL ͷ࠾༻ʹΑΓɺ

    Usecase-based API ͱͷྑ͍ͱ͜ΖऔΓ͕Ͱ͖Δ
    • ؆୯ʹݴ͏ͱ...

    Schema શମ͕ Resource Λද͠

    Query ͕ Usecase Λද͢
    • ৄ͘͠͸ӈͷࢿྉΛݟͯͶ!!

    View full-size slide

  15. ଞͷΞʔΩςΫνϟͱͷൺֱ
    • ७ਮഓཆ͡Όͳ͍GraphQLύλʔϯͱൺֱͯ͠ΈΔ
    • (a) GraphQL Gateway - REST/gRPC ύλʔϯ
    • (b) BFF (RPC) - GraphQL ύλʔϯ

    View full-size slide

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

    View full-size slide

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

    ৽نαʔϏεͰબ୒͢Δཧ༝͕ͳ͍
    • Cons
    • Gateway Ͱϓϩτίϧม׵͢Δͷ͕໘౗
    • ݁ہɺ͋Δఔ౓͸

    Backend ͕ Usecase API Λ࡞Δඞཁ͕ग़ͯ͘Δ

    View full-size slide

  18. ଞͷΞʔΩςΫνϟͱͷൺֱ
    (b) BFF (RPC) - GraphQL ύλʔϯ

    View full-size slide

  19. ଞͷΞʔΩςΫνϟͱͷൺֱ
    (b) BFF (RPC) - GraphQL ύλʔϯ
    • ے͕ྑ͍ͱࢥ͍ͬͯΔ
    • Backend ͸ Resource-based API Λ࡞Γɺ

    Ϣʔεέʔε͔Βղ์͞ΕΔ
    • Client ͸ࣗ෼ͨͪͷϢʔεέʔεΛBFFʹ࣮૷Ͱ͖Δ
    • ࠓճ BFF Λ࠾༻͠ͳ͔ͬͨཧ༝
    • ΫϥΠΞϯτ΋όοΫΤϯυ΋ಉ͡νʔϜͰ։ൃ͍ͯ͘͠ͷͰɺ

    ม׵͢Δ૚͕ͦ͜·ͰඞཁʹͳΒͳ͍

    View full-size slide

  20. ޙฤ: GraphQL Gateway ͷ
    ໾ׂɾ࣮ݱํ๏

    View full-size slide

  21. GraphQL Gateway ͷ໾ׂ
    • schema Λ merge ͢Δ
    • Backend ͷෳ਺ͷ GraphQL Schema Λ·ͱΊͯදग़͠ɺ

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

    View full-size slide

  22. GraphQL Gateway ͷ໾ׂ - merge
    Backends
    Gateway

    View full-size slide

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

    View full-size slide

  24. GraphQL Gateway ͷ໾ׂ - merge
    Backends
    Gateway

    View full-size slide

  25. GraphQL Gateway ͷ໾ׂ - join
    Backends
    Gateway
    ^ ͜͜ʹ author: User!
    Λ௥Ճ͢Δ

    View full-size slide

  26. GraphQL Gateway ͷ࣮૷ख๏
    • Schema stitching (ݱࡏར༻த)
    • Apollo Federation
    • GraphQL Mesh

    View full-size slide

  27. Schema stitching ͷػೳ
    • mergeSchema
    • delegateSchema
    • join ʹ࢖͑Δ (Ұखؒͷ࣮૷͕ඞཁ)
    • transformSchema
    • Schema ΛมߋͰ͖Δ (ϦωʔϜͳͲ)

    View full-size slide

  28. Schema stitching
    merge schema join

    View full-size slide

  29. Schema stitching ͷӡ༻ྫ

    View full-size slide

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

    View full-size slide

  31. Apollo Federation ࣮૷ - gateway
    શͯͷ৘ใ͸
    Backend schema ʹ͋ΔͷͰɺ
    Gateway ͸ͨͩಡΈࠐΉ͚ͩ

    View full-size slide

  32. Apollo Federation
    • Schema stitching ͱͷҧ͍
    • Schema stitching ͸ Gateway server ͕ओମతʹू໿͍ͯ͘͠
    • Federation ͸ ֤ Backend servers ʹએݴతʹɺ

    ू໿ͷ৘ใΛશͯهड़͢Δ

    View full-size slide

  33. GraphQL Mesh
    • GraphQL API ͚ͩͰͳ͘ɺRESTful (OpenAPI) ΍ gRPC ͳͲ΋
    ू໿͢Δ͜ͱ͕Ͱ͖Δ
    • (࣌ؒͷؔ܎Ͱলུ)

    View full-size slide

  34. Mesh ͷҙຯ
    • Schema stitching ͸͋͘·Ͱ࣮૷Ͱ͋Δɻ
    • Federation / GraphQL Mesh ͸ɺू໿ͷํ๏ͷએݴͰ͋Γɺ
    Gateway Server ͕ඞਢͰ͸ͳ͍
    • Service to Service ͷ৔߹͸ɺ௚઀ෳ਺αʔϏεΛୟ͍ͯू໿
    Ͱ͖Δɻ

    View full-size slide

  35. Զͨͪͷ৽نαʔϏεʹ͓͚Δ༧ఆ
    • ͜Ε·Ͱ ... Schema stitching Ͱ࣮૷ΛਐΊͨ
    • ࣍ͷ൒ظ ... Apollo Federation ͷௐࠪͱಋೖΛ͍ͨ͠
    • ͞Βʹ࣍ͷ൒ظ ...

    طଘͷ RESTful / gRPC API ͱ΋ܨ͗͜ΜͰ͍͘

    => GraphQL Mesh ΛτϥΠͯ͠Έ͍ͨ

    View full-size slide

  36. Thank you for listening!
    • We're hiring!
    • ొ৔ͨ͠ϦϯΫ͸ Speaker Deck ͷ֓ཁཝʹ

    ͢΂ͯࡌ͓͖ͤͯ·͢

    View full-size slide