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

5 年にわたる “ Perl の ” REST API を “ Perl で ” GraphQL API 化し作り直す

183074a00e9e6359eb5180c0f30b60bb?s=47 mangano-ito
March 05, 2022
2.2k

5 年にわたる “ Perl の ” REST API を “ Perl で ” GraphQL API 化し作り直す

183074a00e9e6359eb5180c0f30b60bb?s=128

mangano-ito

March 05, 2022
Tweet

Transcript

  1. id:mangano-ito / גࣜձࣾ͸ͯͳ 5 ೥ʹΘͨΔ “ Perl ͷ ” REST

    API Λ “ Perl Ͱ ” GraphQL API Խ͠࡞Γ௚͢
  2. ࢲ ୡ ʹ͍ͭͯ

  3. ࢲʹ͍ͭͯ id:mangano-ito גࣜձࣾ͸ͯͳ(ϚϯΨνʔϜ ΞϓϦέʔγϣϯΤϯδχΞ 8FC

  4. גࣜձࣾ͸ͯͳ(ϚϯΨνʔϜ ΞϓϦέʔγϣϯΤϯδχΞ 8FC  ˣ ϚϯΨΞϓϦνʔϜΤϯδχΞ "OESPJE ࢲʹ͍ͭͯ id:mangano-ito

  5. ࢲୡͷϓϩμΫτʹ͍ͭͯ

  6. GigaViewer ࣾɾαʔϏεʹಋೖ͞Ε͍ͯΔ 8FCϚϯΨ޲͚Ϗϡʔϫʔ 2017 ʙ

  7. ৽ͨʹϚϯΨΞϓϦʹରԠͨ͠ϏϡʔϫͰ͋Δ ʮ(JHB7JFXFSGPS"QQTʯΛఏڙ 2021 ʙ GigaViewer for Apps +5 years https://hatenacorp.jp/press/release/entry/2021/11/04/153000

  8. ͍··Ͱͷࢲୡ

  9. ͍··Ͱͷ API ։ൃ 3&45"1*  "1*ͷυΩϡϝϯςʔγϣϯ  όϦσʔγϣϯ

  10. hitode909 / APISchem a https://github.com/hitode909/APISchema Made with/for Perl ♥ ࢖ΘΕ͍ͯͨ΋ͷ

  11. l"1*Λ࡞ΔͳΒ εΩʔϚϑΝʔετʹ͍ͨ͠ΑͶz

  12. 👍

  13. lҰํɼ ͍··Ͱͷ3&45"1*։ൃͰ͸ ͜͏͍͏ࠔΓ͝ͱ͕͋ͬͨΑͶz

  14. ΤϯυϙΠϯτͷϨεϙϯεܗ͕ࣜݻఆ Ұํɺը໘͝ͱʹඞཁͱͳΔϑΟʔϧυ͸ҟͳΔ ‑ ࣅͨΑ͏ͳϦιʔε͕ཚཱ

  15. ͦͷ݁Ռ 302 resource s 54 endpoints series series_detail series_detail_of_free_series_campaign series_info_of_free_series_campaign

    ticket_series Series of `series` resources … serial_series
  16. ͜ͷը໘͸͜͏ͳΔ ࡞඼λΠτϧ ஶऀ ֓ཁ

  17. ͜ͷը໘͸͜͏ͳΔ episode_with_series

  18. Ұํ ͜ͷը໘Ͱ͸͜͏ͳΔ ࡞඼λΠτϧ ֓ཁ ࠷৽ΤϐιʔυλΠτϧ νέοτ ར༻Մ൱ ͍͍Ͷ਺

  19. Ұํ ͜ͷը໘Ͱ͸͜͏ͳΔ serial_series

  20. ҧ͍͸… episode_with_series episode author serial_series series

  21. ҧ͍͸… episode_with_series episode author serial_series series_supports_ticket series_detail series

  22. ҧ͍͸… episode_with_series episode author serial_series series_supports_ticket series_detail series

  23. ༻్Ͱ෼Խ͍͍ͯͬͯ͠Δ… • series • Ϧετը໘Ͱ͸ܰΊͷσʔλͰ΄͍͠ΑͶʙ • series_detail • ৄࡉը໘Ͱ͸ΑΓଟ͘ͷؔ࿈৘ใ΋͚ͬͭͯ͘΄͍͠ΑͶʙ series

    series_detail
  24. ͞Βʹ… • listed_series_info • series + author + ৽ணΤϐιʔυ೔࣌ ͕߹ମͨ͠όʔδϣϯ

    • listed_series_info_with_ticket • listed_series_info + ticket ৘ใ͕߹ମͨ͠όʔδϣϯ listed_series_info listed_series_info_with_ticket
  25. 🤯

  26. ॊೈੑ දࣔ݅਺΍ूܭ৚݅ͳͲ͕͢΂ͯ αʔόʔαΠυʹ࣮૷͞Ε͍ͯΔ ΞϓϦͷ։ൃલʹαʔόʔαΠυͰ ઌߦͨ͠։ൃͱϦϦʔε͕ඞཁ

  27. ͋Δ͍͸ϫʔΫϑϩʔ αʔόʔαΠυͰͷඇޓ׵ͳมߋ͸ ڧ੍Ξοϓσʔτ͕ඞཁʹͳΓ͏ΔͷͰ ͳΔ΂͘ͳΒආ͚͍ͨʜʜ

  28. ͋Δ͍͸ϫʔΫϑϩʔ ഁյతͳมߋΛ๷͙ͨΊʹ ৽ͨͳόʔδϣϯͱͯ͠ Ϧιʔε͕஀ੜͨ͠Γ͢Δ /api/v1/rankings /api/v2/rankings

  29. l(SBQI2-Ͱ͸Ͳ͏ͳͷ͔z

  30. GraphQL ͷҰൠతͳϝϦοτ 👉ɹؔ࿈͢ΔσʔλΛάϥϑͱͯ͠औಘͰ͖Δ 👍ɹΫϥΠΞϯτଆ͕ඞཁͳ΋ͷ͚ͩ ɹɹॊೈʹऔಘՄೳ 👍ɹαʔόʔଆ͸୯ମͷϦιʔεͱ ɹɹͦͷؔ܎Λهड़͠࠶ར༻Մೳ Ϧιʔεͷരൃ มߋʹର͢Δॊೈੑ

  31. ͖ͬ͞ͷը໘͸͜͏ॻ͚Δ

  32. ͖ͬ͞ͷը໘͸͜͏ॻ͚Δ series.titl e series.author.nam e series.description

  33. ผͷը໘Ͱʴα͚ͨ͠Ε͹…

  34. ผͷը໘Ͱʴα͚ͨ͠Ε͹… ࡞඼λΠτϧ series.description series.latestEpisode.title serie s .supportsTicket series.likeCount

  35. series.titl e series.author.nam e series.description

  36. ผͷը໘Ͱ-α͚ͨ͠Ε͹… series.titl e series.author.nam e series.description

  37. ॊೈੑόπάϯʂ

  38. ։ൃޮ཰ (SBQIJ2-ศརͳ(SBQI2-ΫϥΠΞϯτ

  39. None
  40. ΧελϚΠζͨ͠Γ΋… https://developer.hatenastaff.com/entry/2021/05/14/093000

  41. 3&45ˠ(SBQI2- ͯ͠Έͨ͋͘Γ·ͤΜ͔

  42. l1FSMͰͰ͖Δͷ͔ʁz

  43. 👍΋ͪΖΜͰ͖Δ ࣾ಺Ͱ΋࠾༻࣮੷͋Γ ฐࣾͰ͸1FSMͳΒ͜ΕҰ୒ ͱ͍͏ҹ৅

  44. lͳʹΛ͢Ε͹Α͍ͷ͔z

  45. ઌʹεΩʔϚΛॻ͘

  46. ͨͱ͑͹ series ͸͜͏ॻ͚Δ

  47. series ΁ͷΫΤϦ͸͜Ε͚ͩ

  48. ղܾͷγεςϜ

  49. ରԠ͢Δ࣮૷Λॻ͍͍ͯ͘ Resolver

  50. ରԠ͢Δ࣮૷Λॻ͘

  51. None
  52. ͜͏ͯ͠εΩʔϚϑΝʔετͰ ఆٛˠ࣮૷Λ͍ͯ͘͠

  53. جຊ εΩʔϚͱ࣮૷ͷͭͳ͗͜Έ

  54. None
  55. None
  56. εΩʔϚఆٛΛجʹ Resolver ࣮૷΁ { } Giga::GraphQL::Resolver::Query::Series Giga::GraphQL::Resolver::Series Giga::GraphQL::Resolver::Author GraphQL Schema

  57. ൃల গ͠ؤுΓ͸ඞཁʹͳΔ͚ΕͲʜ

  58. Τϥʔͷදݱ ͍··ͰΤϥʔΛฦ͍ͯͨ͠෦෼͸Ͳ͏͢Δͷ͔ʁ

  59. GraphQL ͷΤϥʔදݱ

  60. None
  61. None
  62. ΤϥʔϋϯυϥʔΛಋೖ ErrorHandler { } GraphQL::Error Error Report Raised Error Object

    Error Response { } Query ΤϥʔΛू໿ 🧨
  63. Ͱ͖͕͋Δ

  64. N+1 ໰୊

  65. None
  66. DataLoader Λಋೖ͢Δ

  67. ϖʔδωʔγϣϯ Relay GraphQL Cursor Connections Specificatio n https://relay.dev/graphql/connections.htm

  68. ΞμϓλʔΛಋೖ͢Δ Connection Repository Offset = 2 0 Limit = 10

    First = 1 0 After = %ABC$ { }
  69. ύϑΥʔϚϯε΁ͷऔΓ૊Έ ط஌ͷΫΤϦͷΩϟογϡΛࣄલ࡞੒͠΢ΥʔϜΞοϓ͢Δ ఆظతʹ ΩϟογϡΛ ͭ͘Δ ࣄલʹΫΤϦΛ ετοΫ͓ͯ͘͠ ΞΫηε࣌ʹ͸ Ωϟογϡ͕ ͋ͨͨ·ͬͯΔ

  70. ܗ͕Ͱ͖ͨʂ

  71. ͋ͱ͸ίʔυΛॻ͚ͩ͘ʁ

  72. ϑϩϯτΤϯυͰͷ࢖ΘΕํʹΑͬͯ ٻΊΒΕΔεΩʔϚ͕ܾ·Δ "1*։ൃଆ͚ͩͰ͸ܾΊΒΕΔΘ͚Ͱ͸ͳ͍ 👱👱👨🦱👨🦰

  73. App νʔϜͱ࿈ܞͨ͠ҙࢥܾఆΛ͍ͨ͠ l྆νʔϜͰ߹ҙΛऔΓͳ͕ΒɹεΩʔϚΛܾΊ͍͖͍ͯͨz ͱ͍͏ͷ͕ 3&45࣌୅͔Βड͚ܧ͕ΕΔߟ͔͑ͨ 👱🤝👱🤝👨🦱🤝👨🦰

  74. εΩʔϚϑΝʔετ™

  75. ͨͩ…೉͍͠෦෼͕͋Δ εΩʔϚΛߟ͑Δ͜ͱ͕·ͣ೉͍͠ εΩʔϚϑΝʔετΛ࣮ݱ͢Δ೉͠͞ ϫʔΫϑϩʔతͳ೉͠͞΋͋Δ

  76. ٕज़͚ͩͰ͸ͳ͍ εΩʔϚϑΝʔετ

  77. νʔϜӽڥͨ͠औΓ૊Έ΋ඞཁ

  78. None
  79. զʑͷऔΓ૊Έϧʔϓ ΍Γ͍ܾͨΊ͍ͨ΋ͷ͝ͱ͕͋Δ ͖ͨͨ୆Λߟ͑Δ ձͰಉظతʹ૬ஊ ܾఆ͸ه࿥Λ࢒͢ ࣮૷͢Δ

  80. 1. ࣮ݱ͍ͨ͠ػೳ͕͋Δ ʮ͜ͷϞσϧΛͲ͏͍͏εΩʔϚͰఆٛ͠Α͏ʯ͸͜Ε

  81. 2. ͖ͨͨ୆Λߟ͑Δ w ͜͜Ͱ۩ମతͳεΩʔϚҊΛఏࣔͨ͠Γ͢Δ w দ஛കγεςϜͰෳ਺ҊΛఏࣔ͠ɼQSPTDPOTͰٞ࿦ͨ͠Γ

  82. 3. ձͰಉظతʹ૬ஊ w ຖ೔ΞϓϦνʔϜͷனձʹಥܸ͢Δ w ͦ͜ʹʮ"1*૬ஊίʔφʔʯΛઃ͚ͯ΋Β͍ɼͦ͜Ͱձ࿩͢Δ w ि࣍(JHB(SBQI2-ձ w ͜͜Ͱ͸ΑΓ(SBQI2-"1*ʹಛԽ͍ͯ͠Δ

    w ೖΓ૊Μͩ࿩Λͨ͠Γ͢Δ
  83. 4. େ͖͍ܾఆ͸ه࿥Λ࢒͢ w ҙݟ͕͍Ζ͍Ζ͋Δͱ͖΍ࠓޙʹؔΘΔେ͖ͳܾఆ w ૬ஊͷܦҢΛࢀরͰ͖ΔΑ͏ʹ͢Δ w େ͖͘ͳ͍ͱ͖͸୯ʹٞࣄ࿥ʹॻ͚ͩ͘ϓϩμΫτͷه࿥ʹ࢒ͨ͠Γ

  84. ༷ʑͳܾఆ͕ߦΘΕΔ OVMMBCMF͔OPOOVMM͔ *%Ͳ͏͢Δ͔ ͳΜͰ΋/PEFʹ͸͠ͳ͍ ෳ਺ͷࣅͨܕΛΠϯλʔ ϑΣΠεʹͰ͖ͳ͍͔ ΤϥʔϋϯυϦϯά ৽ͨͳܕͷఆٛ

  85. ͜͏ͯ͠ "1*͕׬੒

  86. ΞϓϦ͕Ͱ͖͕͋Δ (JHB7JFXFSGPS"QQT͕Ͱ͖͕͋Δ

  87. ͞Βʹ Web Ͱ΋׆༻ αʔόʔαΠυϑϩϯτΤϯυʹͱͬͯ΋׆༻͠΍͍͢ɽ ॊೈʹσʔλΛऔͬͯ͜ΕΔɽ ࠓޙΑΓ׆༻͕ਐΜͰ͍͘༧ఆɽ

  88. ·ͱΊ 1FSMͰ(SBQI2-"1*Λ࡞Δͷ͸ ࣮૷Λ௥Ճͯ͠ શવͰ͖Δʂ 3&45"1*Ͱͷ։ൃޮ཰ͷ՝୊͸(SBQI2-ʹΑΓվળ͞Εͨʂ αʔόʔɾΫϥΠΞϯταΠυؒͷ࿈ܞ͕։ൃʹ͓͍ͯ؊ཁʂ

  89. ͋Γ͕ͱ͏͍͟͝·ͨ͠