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

GraphQL を完全に理解する

GraphQL を完全に理解する

Masayoshi Tokumoto

June 12, 2021
Tweet

More Decks by Masayoshi Tokumoto

Other Decks in Technology

Transcript

  1. ಈػ • લ৬Ͱ GraphQL ࢖ͬͯศརͩͬͨ • ݱࡏͷҊ݅Ͱ GraphQL Λ࢖͍ͬͯΔ •

    @saboyutaka ͞Μͷ GraphQL ͷهࣄΛݟͯԿ΋Θ͔͍ͬͯͳ͔ͬͨ͜ͱ͕ Θ͔ͬͨ • ൓লͱͱ΋ʹ GraphQL ʹ͍ͭͯͷ஌ࣝΛ͜͜Ͱ੔ཧ͢Δ
  2. ͬ͘͟Γ͍͏ͱ • GraphQL ࣗମ͸ specʢ࢓༷ʣ • QLʢQuery LanguageʣͳͷͰ໰͍߹Θͤݴޠ • GraphQL

    Client ͱ GraphQL Server ؒͷϓϩτίϧ • Client ଆ΋ؚΊͯσβΠϯ͞Ε͍ͯΔ WebAPI ͷ࢓༷
  3. “Graph”QL ͳཧ༝ • ࠷ۙͷΞϓϦͷσʔλ͕ϊʔυͱΤοδͷάϥϑͰදݱͰ͖Δ͜ͱΛ׆༻ • GraphQL ͸ΫΤϦ݁ՌπϦʔΛੜ੒͢ΔͨΊͷ໰͍߹Θͤݴޠ • GraphQL ͷπϦʔߏ଄͸ΫϥΠΞϯταΠυͷΩϟογϡʹ͏͚ͬͯͭ

    • Same Path, Same Object • Same Object ID, Same Object • Apollo Client ͸ Cache ͞Ε͍ͯΔσʔλͷ f ield ͕ߋ৽͞ΕͨΒ Cache ΋ߋ৽ͯ͘͠ΕΔ
  4. GraphQL ͷ࿩Ͱग़ͯ͘Δ༻ޠ • GraphQL Clientʢࡶʹ͍͏ͱ Query Λൃߦ͢Δ΋ͷʣ • GraphQL ServerʢGraphQL

    Λ࣮૷ͨ͠αʔόʔʣ • ResolverʢQuery ͰٻΊΒΕͨσʔλΛฦͨ͢Ίͷ΋ͷʣ • DataSourceʢσʔλΛอ͍࣋ͯ͠Δαʔόʔ΍ΞϓϦέʔγϣϯʣ
  5. GraphQL ͷಈ࡞ݪཧ • Scheme Ͱσʔλ΍ΦϒδΣΫτͷϦϨʔγϣϯΛ͋Β͔͡Ίએݴ͢Δ • એݴ͞ΕͨScheme͸άϥϑߏ଄ʹͳΔ 
 • ΫϥΠΞϯτ͸

    Query Λར༻͠σʔλͷऔಘΛߦ͏ • Query ͸͋ΔϊʔυΛϧʔτͱͨ͠໦ߏ଄ΛऔΓग़͢ૢ࡞ 
 • ύʔε͞Εͯߏங͞Εͨ໦ͷϊʔυΛͲ͏ղܾ͢Δ͔Λهड़ͨؔ͠਺ ʢResolverʣ্͕Ґ͔Βஈ֊తʹݺͼग़͞Εղܾ͍ͯ͘͠ • ྫ 
 • Resolver ͸ DataSource Ϋϥεͷؔ਺Λݺͼग़͢ɻDataSource ͸ HTTP Ϧ ΫΤετΛૹΔ΋ͷ΍DB ΁ SQL Λൃߦ͢Δ΋ͷɺϑΝΠϧΛಡΈࠐΈͳ ͲΛهड़ͨ͠Ϋϥεɻ 
 • શͯͷϊʔυͷresolve͕ऴΘΔͱɺϨεϙϯεΛฦ͢
  6. ࡢࠓͷ Web ։ൃͷτϨϯυ ϑϩϯτΤϯυ • ϚϧνϓϥοτϑΥʔϜԽ • ϦονϑϩϯτΤϯυԽ • ϑϩϯτΤϯυͷΞϓϦέʔγϣϯಛੑ

    • ੡඼ͷϥΠϑαΠΫϧ͕୹͘ɺAPI ʹର͢Δཁٻ͸ৗʹมԽ͢Δ αʔόʔαΠυ • ϚΠΫϩαʔϏεԽ • αʔόʔαΠυओମͷ API ઃܭ
  7. BFF

  8. ʲ༨ஊʳϞόΠϧϑΝʔετͱΠϯλʔωοτͷϑϩϯςΟΞ • GraphQL ͸ Facebook ൃͷ WebAPI ࢓༷ • 2015೥ʹOSSԽ

    • എܠʹ͸ϞόΠϧΫϥΠΞϯτͷٸ૿΍ɺωοτϫʔΫτϥϑΟοΫͷ૿େɺΞϓϦͷWebView͔ΒωΠςΟ ϒԽ͕͋ͬͨ • Facebook ͷΑ͏ͳੈքతͳ IT اۀ͸Ϗδωεͷ֦େͷͨΊʹɺະͩΠϯλʔωοτʹ߃ৗతʹ઀ଓ͢Δ͜ͱ ͕Ͱ͖ͳ͍ੈքͷ໿൒਺ʢ30ԯʣ΁ΠϯλʔωοτΛීٴͤ͞ΔϓϩδΣΫτΛܾߦ͍ͯ͠Δ • ΞϑϦΧΛऔΓғΉւఈέʔϒϧʮ2AfricaʯʢFacebook ͳͲʣ • 12,000 ΋ͷਓ޻Ӵ੕Λ૊Έ߹ΘͤͯӴ੕ϒϩʔυόϯυΛఏڙ͢ΔϓϩδΣΫτʮStarlinkʯʢSpaceXʣ • ↑ͷϓϩδΣΫτ͕͋Δ͜ͱ΋ߟ͑ΔͱϞόΠϧΫϥΠΞϯτͷϦιʔε(CPU, ϝϞϦ, ωοτϫʔΫ, όος Ϧʔ)Λ࠷খԽ͍ͨ͠ͱࢥ͏ͷ͸ࣗવ͔
  9. ϑϩϯτΤϯυͷϝϦοτʢͷҰ෦ʣ • ϢʔεέʔεͷมߋʹॊೈʹରԠͰ͖ΔΑ͏ʹͳΔ • Schema ʹΑΔࣗݾจॻԽʢ্࣮࣭ͷ API υΩϡϝϯτʣ • ΦʔόʔϑΣονɾΞϯμʔϑΣον͠ͳ͘ͳΔ

    • GraphQL ͷΈͳΒͣͦͷपΓͷΤίγεςϜͷԸܙΛड͚Δ͜ͱ͕Ͱ͖Δ • ϑϩϯτΤϯυͷঢ়ଶ؅ཧͷϕετϓϥΫςΟεͱͯ͠ͷ Apollo Client
  10. όοΫΤϯυͷϝϦοτʢͷҰ෦ʣ • ΫϥΠΞϯτ౎߹Ͱͷ API ͷ࢓༷΍ΞʔΩςΫνϟͷมߋΛݮΒ͢͜ͱ͕ग़ དྷΔ • ΞϓϦέʔγϣϯɾσʔλετΞͷมߋ͕༰қʹͳΔ • ஈ֊తͳେن໛ΞʔΩςΫνϟมߋʹ΋ར༻Ͱ͖Δ

    • ΫϥΠΞϯτͷ؀ڥ࢓༷΁ͷߟྀΛݮΒ͢͜ͱ͕ग़དྷΔ • MicroservicesΛ࠾༻ͨ͠৔߹ͷ API ࢓༷ͷ౷ҰԽΛਤΔίετΛݮΒ͢ࣄ͕ ग़དྷΔ