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.5k
5 年にわたる “ Perl の ” REST API を “ Perl で ” GraphQL API 化し作り直す
mangano-ito
March 05, 2022
Tweet
Share
Featured
See All Featured
Navigating Team Friction
lara
183
14k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
It's Worth the Effort
3n
183
27k
Teambox: Starting and Learning
jrom
133
8.8k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
910
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Designing the Hi-DPI Web
ddemaree
280
34k
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-ʹΑΓվળ͞Εͨʂ αʔόʔɾΫϥΠΞϯταΠυؒͷ࿈ܞ͕։ൃʹ͓͍ͯ؊ཁʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠