5 年にわたる “ Perl の ” REST API を “ Perl で ” GraphQL API 化し作り直す
by
mangano-ito
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
id:mangano-ito / גࣜձࣾͯͳ 5 ʹΘͨΔ “ Perl ͷ ” REST API Λ “ Perl Ͱ ” GraphQL API Խ͠࡞Γ͢
Slide 2
Slide 2 text
ࢲ ୡ ʹ͍ͭͯ
Slide 3
Slide 3 text
ࢲʹ͍ͭͯ id:mangano-ito גࣜձࣾͯͳ(ϚϯΨνʔϜ ΞϓϦέʔγϣϯΤϯδχΞ 8FC
Slide 4
Slide 4 text
גࣜձࣾͯͳ(ϚϯΨνʔϜ ΞϓϦέʔγϣϯΤϯδχΞ 8FC ˣ ϚϯΨΞϓϦνʔϜΤϯδχΞ "OESPJE ࢲʹ͍ͭͯ id:mangano-ito
Slide 5
Slide 5 text
ࢲୡͷϓϩμΫτʹ͍ͭͯ
Slide 6
Slide 6 text
GigaViewer ࣾɾαʔϏεʹಋೖ͞Ε͍ͯΔ 8FCϚϯΨ͚Ϗϡʔϫʔ 2017 ʙ
Slide 7
Slide 7 text
৽ͨʹϚϯΨΞϓϦʹରԠͨ͠ϏϡʔϫͰ͋Δ ʮ(JHB7JFXFSGPS"QQTʯΛఏڙ 2021 ʙ GigaViewer for Apps +5 years https://hatenacorp.jp/press/release/entry/2021/11/04/153000
Slide 8
Slide 8 text
͍··Ͱͷࢲୡ
Slide 9
Slide 9 text
͍··Ͱͷ API ։ൃ 3&45"1* "1*ͷυΩϡϝϯςʔγϣϯ όϦσʔγϣϯ
Slide 10
Slide 10 text
hitode909 / APISchem a https://github.com/hitode909/APISchema Made with/for Perl ♥ ΘΕ͍ͯͨͷ
Slide 11
Slide 11 text
l"1*Λ࡞ΔͳΒ εΩʔϚϑΝʔετʹ͍ͨ͠ΑͶz
Slide 12
Slide 12 text
👍
Slide 13
Slide 13 text
lҰํɼ ͍··Ͱͷ3&45"1*։ൃͰ ͜͏͍͏ࠔΓ͝ͱ͕͋ͬͨΑͶz
Slide 14
Slide 14 text
ΤϯυϙΠϯτͷϨεϙϯεܗ͕ࣜݻఆ Ұํɺը໘͝ͱʹඞཁͱͳΔϑΟʔϧυҟͳΔ ‑ ࣅͨΑ͏ͳϦιʔε͕ཚཱ
Slide 15
Slide 15 text
ͦͷ݁Ռ 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
Slide 16
Slide 16 text
͜ͷը໘͜͏ͳΔ ࡞λΠτϧ ஶऀ ֓ཁ
Slide 17
Slide 17 text
͜ͷը໘͜͏ͳΔ episode_with_series
Slide 18
Slide 18 text
Ұํ ͜ͷը໘Ͱ͜͏ͳΔ ࡞λΠτϧ ֓ཁ ࠷৽ΤϐιʔυλΠτϧ νέοτ ར༻Մ൱ ͍͍Ͷ
Slide 19
Slide 19 text
Ұํ ͜ͷը໘Ͱ͜͏ͳΔ serial_series
Slide 20
Slide 20 text
ҧ͍… episode_with_series episode author serial_series series
Slide 21
Slide 21 text
ҧ͍… episode_with_series episode author serial_series series_supports_ticket series_detail series
Slide 22
Slide 22 text
ҧ͍… episode_with_series episode author serial_series series_supports_ticket series_detail series
Slide 23
Slide 23 text
༻్ͰԽ͍͍ͯͬͯ͠Δ… • series • Ϧετը໘ͰܰΊͷσʔλͰ΄͍͠ΑͶʙ • series_detail • ৄࡉը໘ͰΑΓଟ͘ͷؔ࿈ใ͚ͬͭͯ͘΄͍͠ΑͶʙ series series_detail
Slide 24
Slide 24 text
͞Βʹ… • listed_series_info • series + author + ৽ணΤϐιʔυ࣌ ͕߹ମͨ͠όʔδϣϯ • listed_series_info_with_ticket • listed_series_info + ticket ใ͕߹ମͨ͠όʔδϣϯ listed_series_info listed_series_info_with_ticket
Slide 25
Slide 25 text
🤯
Slide 26
Slide 26 text
ॊೈੑ දࣔ݅ूܭ݅ͳͲ͕ͯ͢ αʔόʔαΠυʹ࣮͞Ε͍ͯΔ ΞϓϦͷ։ൃલʹαʔόʔαΠυͰ ઌߦͨ͠։ൃͱϦϦʔε͕ඞཁ
Slide 27
Slide 27 text
͋Δ͍ϫʔΫϑϩʔ αʔόʔαΠυͰͷඇޓͳมߋ ڧ੍Ξοϓσʔτ͕ඞཁʹͳΓ͏ΔͷͰ ͳΔ͘ͳΒආ͚͍ͨʜʜ
Slide 28
Slide 28 text
͋Δ͍ϫʔΫϑϩʔ ഁյతͳมߋΛ͙ͨΊʹ ৽ͨͳόʔδϣϯͱͯ͠ Ϧιʔε͕ੜͨ͠Γ͢Δ /api/v1/rankings /api/v2/rankings
Slide 29
Slide 29 text
l(SBQI2-ͰͲ͏ͳͷ͔z
Slide 30
Slide 30 text
GraphQL ͷҰൠతͳϝϦοτ 👉ɹؔ࿈͢ΔσʔλΛάϥϑͱͯ͠औಘͰ͖Δ 👍ɹΫϥΠΞϯτଆ͕ඞཁͳͷ͚ͩ ɹɹॊೈʹऔಘՄೳ 👍ɹαʔόʔଆ୯ମͷϦιʔεͱ ɹɹͦͷؔΛهड़͠࠶ར༻Մೳ Ϧιʔεͷരൃ มߋʹର͢Δॊೈੑ
Slide 31
Slide 31 text
͖ͬ͞ͷը໘͜͏ॻ͚Δ
Slide 32
Slide 32 text
͖ͬ͞ͷը໘͜͏ॻ͚Δ series.titl e series.author.nam e series.description
Slide 33
Slide 33 text
ผͷը໘Ͱʴα͚ͨ͠Ε…
Slide 34
Slide 34 text
ผͷը໘Ͱʴα͚ͨ͠Ε… ࡞λΠτϧ series.description series.latestEpisode.title serie s .supportsTicket series.likeCount
Slide 35
Slide 35 text
series.titl e series.author.nam e series.description
Slide 36
Slide 36 text
ผͷը໘Ͱ-α͚ͨ͠Ε… series.titl e series.author.nam e series.description
Slide 37
Slide 37 text
ॊೈੑόπάϯʂ
Slide 38
Slide 38 text
։ൃޮ (SBQIJ2-ศརͳ(SBQI2-ΫϥΠΞϯτ
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
ΧελϚΠζͨ͠Γ… https://developer.hatenastaff.com/entry/2021/05/14/093000
Slide 41
Slide 41 text
3&45ˠ(SBQI2- ͯ͠Έͨ͋͘Γ·ͤΜ͔
Slide 42
Slide 42 text
l1FSMͰͰ͖Δͷ͔ʁz
Slide 43
Slide 43 text
👍ͪΖΜͰ͖Δ ࣾͰ࠾༻࣮͋Γ ฐࣾͰ1FSMͳΒ͜ΕҰ ͱ͍͏ҹ
Slide 44
Slide 44 text
lͳʹΛ͢ΕΑ͍ͷ͔z
Slide 45
Slide 45 text
ઌʹεΩʔϚΛॻ͘
Slide 46
Slide 46 text
ͨͱ͑ series ͜͏ॻ͚Δ
Slide 47
Slide 47 text
series ͷΫΤϦ͜Ε͚ͩ
Slide 48
Slide 48 text
ղܾͷγεςϜ
Slide 49
Slide 49 text
ରԠ͢Δ࣮Λॻ͍͍ͯ͘ Resolver
Slide 50
Slide 50 text
ରԠ͢Δ࣮Λॻ͘
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
͜͏ͯ͠εΩʔϚϑΝʔετͰ ఆٛˠ࣮Λ͍ͯ͘͠
Slide 53
Slide 53 text
جຊ εΩʔϚͱ࣮ͷͭͳ͗͜Έ
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
εΩʔϚఆٛΛجʹ Resolver ࣮ { } Giga::GraphQL::Resolver::Query::Series Giga::GraphQL::Resolver::Series Giga::GraphQL::Resolver::Author GraphQL Schema
Slide 57
Slide 57 text
ൃల গ͠ؤுΓඞཁʹͳΔ͚ΕͲʜ
Slide 58
Slide 58 text
Τϥʔͷදݱ ͍··ͰΤϥʔΛฦ͍ͯͨ͠෦Ͳ͏͢Δͷ͔ʁ
Slide 59
Slide 59 text
GraphQL ͷΤϥʔදݱ
Slide 60
Slide 60 text
No content
Slide 61
Slide 61 text
No content
Slide 62
Slide 62 text
ΤϥʔϋϯυϥʔΛಋೖ ErrorHandler { } GraphQL::Error Error Report Raised Error Object Error Response { } Query ΤϥʔΛू 🧨
Slide 63
Slide 63 text
Ͱ͖͕͋Δ
Slide 64
Slide 64 text
N+1
Slide 65
Slide 65 text
No content
Slide 66
Slide 66 text
DataLoader Λಋೖ͢Δ
Slide 67
Slide 67 text
ϖʔδωʔγϣϯ Relay GraphQL Cursor Connections Specificatio n https://relay.dev/graphql/connections.htm
Slide 68
Slide 68 text
ΞμϓλʔΛಋೖ͢Δ Connection Repository Offset = 2 0 Limit = 10 First = 1 0 After = %ABC$ { }
Slide 69
Slide 69 text
ύϑΥʔϚϯεͷऔΓΈ طͷΫΤϦͷΩϟογϡΛࣄલ࡞͠ΥʔϜΞοϓ͢Δ ఆظతʹ ΩϟογϡΛ ͭ͘Δ ࣄલʹΫΤϦΛ ετοΫ͓ͯ͘͠ ΞΫηε࣌ʹ Ωϟογϡ͕ ͋ͨͨ·ͬͯΔ
Slide 70
Slide 70 text
ܗ͕Ͱ͖ͨʂ
Slide 71
Slide 71 text
͋ͱίʔυΛॻ͚ͩ͘ʁ
Slide 72
Slide 72 text
ϑϩϯτΤϯυͰͷΘΕํʹΑͬͯ ٻΊΒΕΔεΩʔϚ͕ܾ·Δ "1*։ൃଆ͚ͩͰܾΊΒΕΔΘ͚Ͱͳ͍ 👱👱👨🦱👨🦰
Slide 73
Slide 73 text
App νʔϜͱ࿈ܞͨ͠ҙࢥܾఆΛ͍ͨ͠ l྆νʔϜͰ߹ҙΛऔΓͳ͕ΒɹεΩʔϚΛܾΊ͍͖͍ͯͨz ͱ͍͏ͷ͕ 3&45͔࣌Βड͚ܧ͕ΕΔߟ͔͑ͨ 👱🤝👱🤝👨🦱🤝👨🦰
Slide 74
Slide 74 text
εΩʔϚϑΝʔετ™
Slide 75
Slide 75 text
ͨͩ…͍͠෦͕͋Δ εΩʔϚΛߟ͑Δ͜ͱ͕·͍ͣ͠ εΩʔϚϑΝʔετΛ࣮ݱ͢Δ͠͞ ϫʔΫϑϩʔతͳ͋͠͞Δ
Slide 76
Slide 76 text
ٕज़͚ͩͰͳ͍ εΩʔϚϑΝʔετ
Slide 77
Slide 77 text
νʔϜӽڥͨ͠औΓΈඞཁ
Slide 78
Slide 78 text
No content
Slide 79
Slide 79 text
զʑͷऔΓΈϧʔϓ Γ͍ܾͨΊ͍ͨͷ͝ͱ͕͋Δ ͖ͨͨΛߟ͑Δ ձͰಉظతʹ૬ஊ ܾఆهΛ͢ ࣮͢Δ
Slide 80
Slide 80 text
1. ࣮ݱ͍ͨ͠ػೳ͕͋Δ ʮ͜ͷϞσϧΛͲ͏͍͏εΩʔϚͰఆٛ͠Α͏ʯ͜Ε
Slide 81
Slide 81 text
2. ͖ͨͨΛߟ͑Δ w ͜͜Ͱ۩ମతͳεΩʔϚҊΛఏࣔͨ͠Γ͢Δ w দകγεςϜͰෳҊΛఏࣔ͠ɼQSPTDPOTͰٞͨ͠Γ
Slide 82
Slide 82 text
3. ձͰಉظతʹ૬ஊ w ຖΞϓϦνʔϜͷனձʹಥܸ͢Δ w ͦ͜ʹʮ"1*૬ஊίʔφʔʯΛઃ͚ͯΒ͍ɼͦ͜Ͱձ͢Δ w ि࣍(JHB(SBQI2-ձ w ͜͜ͰΑΓ(SBQI2-"1*ʹಛԽ͍ͯ͠Δ w ೖΓΜͩΛͨ͠Γ͢Δ
Slide 83
Slide 83 text
4. େ͖͍ܾఆهΛ͢ w ҙݟ͕͍Ζ͍Ζ͋Δͱ͖ࠓޙʹؔΘΔେ͖ͳܾఆ w ૬ஊͷܦҢΛࢀরͰ͖ΔΑ͏ʹ͢Δ w େ͖͘ͳ͍ͱ͖୯ʹٞࣄʹॻ͚ͩ͘ϓϩμΫτͷهʹͨ͠Γ
Slide 84
Slide 84 text
༷ʑͳܾఆ͕ߦΘΕΔ OVMMBCMF͔OPOOVMM͔ *%Ͳ͏͢Δ͔ ͳΜͰ/PEFʹ͠ͳ͍ ෳͷࣅͨܕΛΠϯλʔ ϑΣΠεʹͰ͖ͳ͍͔ ΤϥʔϋϯυϦϯά ৽ͨͳܕͷఆٛ
Slide 85
Slide 85 text
͜͏ͯ͠ "1*͕
Slide 86
Slide 86 text
ΞϓϦ͕Ͱ͖͕͋Δ (JHB7JFXFSGPS"QQT͕Ͱ͖͕͋Δ
Slide 87
Slide 87 text
͞Βʹ Web Ͱ׆༻ αʔόʔαΠυϑϩϯτΤϯυʹͱͬͯ׆༻͍͢͠ɽ ॊೈʹσʔλΛऔͬͯ͜ΕΔɽ ࠓޙΑΓ׆༻͕ਐΜͰ͍͘༧ఆɽ
Slide 88
Slide 88 text
·ͱΊ 1FSMͰ(SBQI2-"1*Λ࡞Δͷ ࣮ΛՃͯ͠ શવͰ͖Δʂ 3&45"1*Ͱͷ։ൃޮͷ՝(SBQI2-ʹΑΓվળ͞Εͨʂ αʔόʔɾΫϥΠΞϯταΠυؒͷ࿈ܞ͕։ൃʹ͓͍ͯ؊ཁʂ
Slide 89
Slide 89 text
͋Γ͕ͱ͏͍͟͝·ͨ͠