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
GraphQL で変わったこと・変わらなかったこと / graphql changing an...
Search
qsona
June 02, 2020
Technology
5
20k
GraphQL で変わったこと・変わらなかったこと / graphql changing and unchanging
吉祥寺.pm22
https://kichijojipm.connpass.com/event/177459/
qsona
June 02, 2020
Tweet
Share
More Decks by qsona
See All by qsona
サーバー間 GraphQL と webmock-graphql の話 / server-to-server graphql and webmock-graphql
qsona
4
350
Backend エンジニア視点からの GraphQL / GraphQL from a perspective of backend engineer
qsona
28
8.1k
3 Practices about Service-to-Service GraphQL Ruby Client
qsona
1
840
いかにして GraphQL を組織に導入するか (新規開発編) / how we introduce GraphQL on scratch development
qsona
6
3.9k
Well-organized Transaction Script - リファクタリングの妥協的手法 -
qsona
4
1.3k
GraphQL と Prisma から考える次のN年を見据えた技術選定 / Architecture decision for the next N years at StudySapuri
qsona
25
14k
最高のマスターデータ管理手法考察 & VSCode Extension を活用した話 / developing masterdata management tool by using vscode extension
qsona
9
6.1k
GraphQL を活用したスキーマ駆動開発の実践 / schema-driven development with GraphQL
qsona
6
5k
GraphQL を利用したアーキテクチャの勘所 / Architecture practices with GraphQL
qsona
37
15k
Other Decks in Technology
See All in Technology
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
Platform Engineering for Software Developers and Architects
syntasso
1
520
AGIについてChatGPTに聞いてみた
blueb
0
130
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
240
SDN の Hype Cycle を一通り経験してみて思うこと / Going through the Hype Cycle of SDN
mshindo
1
150
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
950
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.7k
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
180
Application Development WG Intro at AppDeveloperCon
salaboy
0
200
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
120
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
95
5.2k
Rails Girls Zürich Keynote
gr2m
94
13k
How GitHub (no longer) Works
holman
310
140k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Gamification - CAS2011
davidbonilla
80
5k
Producing Creativity
orderedlist
PRO
341
39k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Scaling GitHub
holman
458
140k
A Tale of Four Properties
chriscoyier
156
23k
Transcript
GraphQL ͰมΘͬͨ͜ͱɾ มΘΒͳ͔ͬͨ͜ͱ 2020-06-02 ٢ࣉ.pm22 @qsona
whoami • @qsona • Web Developer at Quipper Limited •
͖ͪͽʔॳࢀՃ!!! ͏Ε͍͠!!! ٢ࣉԕ͍!!!
ࠓͷ • ͜Ε·ͰԿ͔ GraphQL & Rails Ͱ API ։ൃΛͯ͠ ຊ൪ϦϦʔεͨ͠
• RESTful ࣌ͱʮมΘͬͨ͜ͱɾมΘΒͳ͔ͬͨ͜ͱʯ ʹ͍͍ͭͯͨ͠
લఏ • Web API Internal use Λఆ͢Δ • πʔϧɾΤίγεςϜͷҰ͠ͳ͍
• APIͷઃܭɾ࣮ͷ͚ͩ • ਅͷREST (Hypermedia API) ͷ͠ͳ͍
Web API ͷઃܭख๏ • Usecase ϕʔε • Resource ϕʔε
Usecase-based Web API • ΫϥΠΞϯτͷϢʔεέʔεʹ߹Θͤͯ Web API Λ࡞Δ • Ϣʔεέʔε
≒ ը໘ • • ࣅͨΑ͏ͳAPI͕ཚཱ͍͢͠ • ຖAPI࡞Δͷ͕໘ => ෳͷϢʔεέʔεʹରԠ͢Δ ਆAPI ͕Ͱ͖Δ
Resource-based Web API • ΞϓϦέʔγϣϯͦͷͷͷ༷ʹ߹Θͤͯ Web API Λ࡞Δ • (جຊతʹ
API ఏڙଆͷ߹Ͱ࡞Δ)
Resource-based Web API • : ΫϥΠΞϯτͷϢʔεέʔεʹ߹Θͳ͍͕࣌͋Δ • 1ը໘ͰෳͷAPIϦΫΤετ͕ඞཁʹͳͬͨΓ • ٯʹ1ϦΫΤετதͰෆཁͳϑΟʔϧυؚΊͯऔͬͯ͠·͏͜ͱ͕͋Δ
• (=> ύϑΥʔϚϯεͷѱԽ) • Resource ͕ࡉ͔͘ͳΓ͗ͯ͢ (ςʔϒϧ୯ҐͳͲ) ΫϥΠΞϯτ͔Β͍ʹ͍͘͜ͱ͕͋Δ
Resource • ݸਓతʹɺ Recourse-based API ʹ͓͍ͯ JSONͷ1֊͝ͱͷ෦Λ Resource ͱݺΜͰ͍·͢
RESTful ࣌ͷࢦ
RESTful ࣌ͷࢦ • جຊతʹ Resource ϕʔεΛબ͢Δ • Resource ΛదͳཻͰఏڙ͢Δ •
ςʔϒϧ୯ҐͰͳ͍ • ΞϓϦέʔγϣϯ্ͷυϝΠϯϞσϧΛߟ͠ɺͦΕʹ߹ΘͤΔ • Ͳ͏ͯ͠ඞཁͳΒผ్ Usecase ༻ͷ endpoint Λੜ͢
GraphQL • Schema ͕ Type ͷ άϥϑߏʹͳ͍ͬͯΔ • query Ͱ
field Λࢦఆ͢Δ͜ͱͰɺ άϥϑͷதͷऔಘ͢Δ෦ΛࢦఆͰ͖Δ
GraphQL ࣌ͷࢦ • GraphQL Type ͕ Resource Λද͢ • query
͕ Usecase Λද͢ • Query Type ͷ field ͕ endpoint Ͱ͋Δ • ͭ·ΓɺResource ϕʔεͷAPIͱ Usecase ϕʔεͷAPIͷ ྑ͍ͱ͜ΖΛཱ྆Ͱ͖Δ!
RESTful => GraphQL Ͱ มΘΒͳ͔ͬͨ͜ͱ
มΘΒͳ͔ͬͨ͜ͱ • ΞϓϦέʔγϣϯͷυϝΠϯΛ͖ͪΜͱߟͯ͠ɺ Resource Λదͳཻʹ͢Δ͜ͱ • Fat Controller, Fat Serializer
Λආ͚Δ͜ͱ • Model ෦ͷઃܭख๏
RESTful => GraphQL Ͱ มΘͬͨ͜ͱ
ແ
มΘͬͨ͜ͱ • ઃܭɾ࣮ϨϕϧͰมΘΔ͜ͱ΄ͱΜͲͳ͔ͬͨ • RESTful ͷͱ͖ͱରԠ͢Δ֓೦͕͋Δ • ͱ͍͑ɺසग़ͷ...? • N+1
• HTTP endpoint ͕શͯ POST /graphql ʹͳΔ
N+1 • Query.users Λ resolve • ͦͷ1݅ͣͭʹରͯ͠ User.jobs Λ resolve
N+1 • ಉ͡ RESTful Ͱى͖Δ • GraphQL ʹ͓͍ͯͳͥΫϩʔζΞο ϓ͞ΕΔ?
N+1 • GraphQL ʹ͓͍ͯӈͷΑ͏ʹɺ ΫϥΠΞϯτ͔Β2௨ΓͷऔΓํ͕γϡο ͱͰ͖Δɺͭ·Γศར • ศར͔ͩΒى͖͍ͯΔ͚ͩ • ղܾ๏:
Batch Loader ͱݺΕΔΈ • Ruby: shopify/graphql-batch
HTTP endpoint ͕શͯ POST /graphql ʹͳΔ • Persisted Query ͱݺΕΔΈͰղܾͰ͖Δ
• ࣄલ / ϥϯλΠϜ ʹΫΤϦΛొ͢Δ
ઃܭ/(୯७ͳ)࣮ΑΓ֎ͷ The NEXT of REST - onk.ninja https://blog.onk.ninja/2017/09/21/the_next_of_rest
͜͜ͰҰ۟ ා͘ͳ͍ GraphQL is Better REST