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
380
Backend エンジニア視点からの GraphQL / GraphQL from a perspective of backend engineer
qsona
27
8.2k
3 Practices about Service-to-Service GraphQL Ruby Client
qsona
1
860
いかにして 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.2k
GraphQL を活用したスキーマ駆動開発の実践 / schema-driven development with GraphQL
qsona
6
5.1k
GraphQL を利用したアーキテクチャの勘所 / Architecture practices with GraphQL
qsona
37
15k
Other Decks in Technology
See All in Technology
Wantedly での Datadog 活用事例
bgpat
2
630
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
280
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
190
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
生成AIのガバナンスの全体像と現実解
fnifni
1
210
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
230
UI State設計とテスト方針
rmakiyama
3
780
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
180
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.9k
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
350
能動的ドメイン名ライフサイクル管理のすゝめ / Practice on Active Domain Name Lifecycle Management
nttcom
0
200
Server-Side Engineer of LINE Sukimani
lycorp_recruit_jp
0
340
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Documentation Writing (for coders)
carmenintech
66
4.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Visualization
eitanlees
146
15k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Code Reviewing Like a Champion
maltzj
521
39k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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