Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
5 年にわたる “ Perl の ” REST API を “ Perl で ” GraphQ...
Search
mangano-ito
March 05, 2022
3
4.7k
5 年にわたる “ Perl の ” REST API を “ Perl で ” GraphQL API 化し作り直す
mangano-ito
March 05, 2022
Tweet
Share
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
YesSQL, Process and Tooling at Scale
rocio
170
14k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Transcript
id:mangano-ito / גࣜձࣾͯͳ 5 ʹΘͨΔ “ Perl ͷ ” REST
API Λ “ Perl Ͱ ” GraphQL API Խ͠࡞Γ͢
ࢲ ୡ ʹ͍ͭͯ
ࢲʹ͍ͭͯ id:mangano-ito גࣜձࣾͯͳ(ϚϯΨνʔϜ ΞϓϦέʔγϣϯΤϯδχΞ 8FC
גࣜձࣾͯͳ(ϚϯΨνʔϜ ΞϓϦέʔγϣϯΤϯδχΞ 8FC ˣ ϚϯΨΞϓϦνʔϜΤϯδχΞ "OESPJE ࢲʹ͍ͭͯ id:mangano-ito
ࢲୡͷϓϩμΫτʹ͍ͭͯ
GigaViewer ࣾɾαʔϏεʹಋೖ͞Ε͍ͯΔ 8FCϚϯΨ͚Ϗϡʔϫʔ 2017 ʙ
৽ͨʹϚϯΨΞϓϦʹରԠͨ͠ϏϡʔϫͰ͋Δ ʮ(JHB7JFXFSGPS"QQTʯΛఏڙ 2021 ʙ GigaViewer for Apps +5 years https://hatenacorp.jp/press/release/entry/2021/11/04/153000
͍··Ͱͷࢲୡ
͍··Ͱͷ API ։ൃ 3&45"1* "1*ͷυΩϡϝϯςʔγϣϯ όϦσʔγϣϯ
hitode909 / APISchem a https://github.com/hitode909/APISchema Made with/for Perl ♥ ΘΕ͍ͯͨͷ
l"1*Λ࡞ΔͳΒ εΩʔϚϑΝʔετʹ͍ͨ͠ΑͶz
👍
lҰํɼ ͍··Ͱͷ3&45"1*։ൃͰ ͜͏͍͏ࠔΓ͝ͱ͕͋ͬͨΑͶz
ΤϯυϙΠϯτͷϨεϙϯεܗ͕ࣜݻఆ Ұํɺը໘͝ͱʹඞཁͱͳΔϑΟʔϧυҟͳΔ ‑ ࣅͨΑ͏ͳϦιʔε͕ཚཱ
ͦͷ݁Ռ 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
͜ͷը໘͜͏ͳΔ ࡞λΠτϧ ஶऀ ֓ཁ
͜ͷը໘͜͏ͳΔ episode_with_series
Ұํ ͜ͷը໘Ͱ͜͏ͳΔ ࡞λΠτϧ ֓ཁ ࠷৽ΤϐιʔυλΠτϧ νέοτ ར༻Մ൱ ͍͍Ͷ
Ұํ ͜ͷը໘Ͱ͜͏ͳΔ serial_series
ҧ͍… episode_with_series episode author serial_series series
ҧ͍… episode_with_series episode author serial_series series_supports_ticket series_detail series
ҧ͍… episode_with_series episode author serial_series series_supports_ticket series_detail series
༻్ͰԽ͍͍ͯͬͯ͠Δ… • series • Ϧετը໘ͰܰΊͷσʔλͰ΄͍͠ΑͶʙ • series_detail • ৄࡉը໘ͰΑΓଟ͘ͷؔ࿈ใ͚ͬͭͯ͘΄͍͠ΑͶʙ series
series_detail
͞Βʹ… • listed_series_info • series + author + ৽ணΤϐιʔυ࣌ ͕߹ମͨ͠όʔδϣϯ
• listed_series_info_with_ticket • listed_series_info + ticket ใ͕߹ମͨ͠όʔδϣϯ listed_series_info listed_series_info_with_ticket
🤯
ॊೈੑ දࣔ݅ूܭ݅ͳͲ͕ͯ͢ αʔόʔαΠυʹ࣮͞Ε͍ͯΔ ΞϓϦͷ։ൃલʹαʔόʔαΠυͰ ઌߦͨ͠։ൃͱϦϦʔε͕ඞཁ
͋Δ͍ϫʔΫϑϩʔ αʔόʔαΠυͰͷඇޓͳมߋ ڧ੍Ξοϓσʔτ͕ඞཁʹͳΓ͏ΔͷͰ ͳΔ͘ͳΒආ͚͍ͨʜʜ
͋Δ͍ϫʔΫϑϩʔ ഁյతͳมߋΛ͙ͨΊʹ ৽ͨͳόʔδϣϯͱͯ͠ Ϧιʔε͕ੜͨ͠Γ͢Δ /api/v1/rankings /api/v2/rankings
l(SBQI2-ͰͲ͏ͳͷ͔z
GraphQL ͷҰൠతͳϝϦοτ 👉ɹؔ࿈͢ΔσʔλΛάϥϑͱͯ͠औಘͰ͖Δ 👍ɹΫϥΠΞϯτଆ͕ඞཁͳͷ͚ͩ ɹɹॊೈʹऔಘՄೳ 👍ɹαʔόʔଆ୯ମͷϦιʔεͱ ɹɹͦͷؔΛهड़͠࠶ར༻Մೳ Ϧιʔεͷരൃ มߋʹର͢Δॊೈੑ
͖ͬ͞ͷը໘͜͏ॻ͚Δ
͖ͬ͞ͷը໘͜͏ॻ͚Δ series.titl e series.author.nam e series.description
ผͷը໘Ͱʴα͚ͨ͠Ε…
ผͷը໘Ͱʴα͚ͨ͠Ε… ࡞λΠτϧ series.description series.latestEpisode.title serie s .supportsTicket series.likeCount
series.titl e series.author.nam e series.description
ผͷը໘Ͱ-α͚ͨ͠Ε… series.titl e series.author.nam e series.description
ॊೈੑόπάϯʂ
։ൃޮ (SBQIJ2-ศརͳ(SBQI2-ΫϥΠΞϯτ
None
ΧελϚΠζͨ͠Γ… https://developer.hatenastaff.com/entry/2021/05/14/093000
3&45ˠ(SBQI2- ͯ͠Έͨ͋͘Γ·ͤΜ͔
l1FSMͰͰ͖Δͷ͔ʁz
👍ͪΖΜͰ͖Δ ࣾͰ࠾༻࣮͋Γ ฐࣾͰ1FSMͳΒ͜ΕҰ ͱ͍͏ҹ
lͳʹΛ͢ΕΑ͍ͷ͔z
ઌʹεΩʔϚΛॻ͘
ͨͱ͑ series ͜͏ॻ͚Δ
series ͷΫΤϦ͜Ε͚ͩ
ղܾͷγεςϜ
ରԠ͢Δ࣮Λॻ͍͍ͯ͘ Resolver
ରԠ͢Δ࣮Λॻ͘
None
͜͏ͯ͠εΩʔϚϑΝʔετͰ ఆٛˠ࣮Λ͍ͯ͘͠
جຊ εΩʔϚͱ࣮ͷͭͳ͗͜Έ
None
None
εΩʔϚఆٛΛجʹ Resolver ࣮ { } Giga::GraphQL::Resolver::Query::Series Giga::GraphQL::Resolver::Series Giga::GraphQL::Resolver::Author GraphQL Schema
ൃల গ͠ؤுΓඞཁʹͳΔ͚ΕͲʜ
Τϥʔͷදݱ ͍··ͰΤϥʔΛฦ͍ͯͨ͠෦Ͳ͏͢Δͷ͔ʁ
GraphQL ͷΤϥʔදݱ
None
None
ΤϥʔϋϯυϥʔΛಋೖ ErrorHandler { } GraphQL::Error Error Report Raised Error Object
Error Response { } Query ΤϥʔΛू 🧨
Ͱ͖͕͋Δ
N+1
None
DataLoader Λಋೖ͢Δ
ϖʔδωʔγϣϯ Relay GraphQL Cursor Connections Specificatio n https://relay.dev/graphql/connections.htm
ΞμϓλʔΛಋೖ͢Δ Connection Repository Offset = 2 0 Limit = 10
First = 1 0 After = %ABC$ { }
ύϑΥʔϚϯεͷऔΓΈ طͷΫΤϦͷΩϟογϡΛࣄલ࡞͠ΥʔϜΞοϓ͢Δ ఆظతʹ ΩϟογϡΛ ͭ͘Δ ࣄલʹΫΤϦΛ ετοΫ͓ͯ͘͠ ΞΫηε࣌ʹ Ωϟογϡ͕ ͋ͨͨ·ͬͯΔ
ܗ͕Ͱ͖ͨʂ
͋ͱίʔυΛॻ͚ͩ͘ʁ
ϑϩϯτΤϯυͰͷΘΕํʹΑͬͯ ٻΊΒΕΔεΩʔϚ͕ܾ·Δ "1*։ൃଆ͚ͩͰܾΊΒΕΔΘ͚Ͱͳ͍ 👱👱👨🦱👨🦰
App νʔϜͱ࿈ܞͨ͠ҙࢥܾఆΛ͍ͨ͠ l྆νʔϜͰ߹ҙΛऔΓͳ͕ΒɹεΩʔϚΛܾΊ͍͖͍ͯͨz ͱ͍͏ͷ͕ 3&45͔࣌Βड͚ܧ͕ΕΔߟ͔͑ͨ 👱🤝👱🤝👨🦱🤝👨🦰
εΩʔϚϑΝʔετ™
ͨͩ…͍͠෦͕͋Δ εΩʔϚΛߟ͑Δ͜ͱ͕·͍ͣ͠ εΩʔϚϑΝʔετΛ࣮ݱ͢Δ͠͞ ϫʔΫϑϩʔతͳ͋͠͞Δ
ٕज़͚ͩͰͳ͍ εΩʔϚϑΝʔετ
νʔϜӽڥͨ͠औΓΈඞཁ
None
զʑͷऔΓΈϧʔϓ Γ͍ܾͨΊ͍ͨͷ͝ͱ͕͋Δ ͖ͨͨΛߟ͑Δ ձͰಉظతʹ૬ஊ ܾఆهΛ͢ ࣮͢Δ
1. ࣮ݱ͍ͨ͠ػೳ͕͋Δ ʮ͜ͷϞσϧΛͲ͏͍͏εΩʔϚͰఆٛ͠Α͏ʯ͜Ε
2. ͖ͨͨΛߟ͑Δ w ͜͜Ͱ۩ମతͳεΩʔϚҊΛఏࣔͨ͠Γ͢Δ w দകγεςϜͰෳҊΛఏࣔ͠ɼQSPTDPOTͰٞͨ͠Γ
3. ձͰಉظతʹ૬ஊ w ຖΞϓϦνʔϜͷனձʹಥܸ͢Δ w ͦ͜ʹʮ"1*૬ஊίʔφʔʯΛઃ͚ͯΒ͍ɼͦ͜Ͱձ͢Δ w ि࣍(JHB(SBQI2-ձ w ͜͜ͰΑΓ(SBQI2-"1*ʹಛԽ͍ͯ͠Δ
w ೖΓΜͩΛͨ͠Γ͢Δ
4. େ͖͍ܾఆهΛ͢ w ҙݟ͕͍Ζ͍Ζ͋Δͱ͖ࠓޙʹؔΘΔେ͖ͳܾఆ w ૬ஊͷܦҢΛࢀরͰ͖ΔΑ͏ʹ͢Δ w େ͖͘ͳ͍ͱ͖୯ʹٞࣄʹॻ͚ͩ͘ϓϩμΫτͷهʹͨ͠Γ
༷ʑͳܾఆ͕ߦΘΕΔ OVMMBCMF͔OPOOVMM͔ *%Ͳ͏͢Δ͔ ͳΜͰ/PEFʹ͠ͳ͍ ෳͷࣅͨܕΛΠϯλʔ ϑΣΠεʹͰ͖ͳ͍͔ ΤϥʔϋϯυϦϯά ৽ͨͳܕͷఆٛ
͜͏ͯ͠ "1*͕
ΞϓϦ͕Ͱ͖͕͋Δ (JHB7JFXFSGPS"QQT͕Ͱ͖͕͋Δ
͞Βʹ Web Ͱ׆༻ αʔόʔαΠυϑϩϯτΤϯυʹͱͬͯ׆༻͍͢͠ɽ ॊೈʹσʔλΛऔͬͯ͜ΕΔɽ ࠓޙΑΓ׆༻͕ਐΜͰ͍͘༧ఆɽ
·ͱΊ 1FSMͰ(SBQI2-"1*Λ࡞Δͷ ࣮ΛՃͯ͠ શવͰ͖Δʂ 3&45"1*Ͱͷ։ൃޮͷ՝(SBQI2-ʹΑΓվળ͞Εͨʂ αʔόʔɾΫϥΠΞϯταΠυؒͷ࿈ܞ͕։ൃʹ͓͍ͯ؊ཁʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠