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
REST脳脱出のためのGraphQLの命名の話
Search
asmsuechan
December 19, 2018
0
270
REST脳脱出のためのGraphQLの命名の話
asmsuechan
December 19, 2018
Tweet
Share
More Decks by asmsuechan
See All by asmsuechan
入門: マークダウン
asmsuechan
0
10k
Featured
See All Featured
Designing for Performance
lara
604
68k
Creatively Recalculating Your Daily Design Routine
revolveconf
217
12k
Web development in the modern age
philhawksworth
205
10k
Scaling GitHub
holman
458
140k
Designing Experiences People Love
moore
138
23k
Mobile First: as difficult as doing things right
swwweet
222
8.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
279
13k
What's in a price? How to price your products and services
michaelherold
243
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
249
21k
Agile that works and the tools we love
rasmusluckow
327
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
Large-scale JavaScript Application Architecture
addyosmani
509
110k
Transcript
RESTग़ͷͨΊͷ໋໊ͷ asmsuechan
asmsuechan ࣗ ݾ հ 0 ݸਓϓϩμΫτͱ͔ͰGraphQLͬͯΔ ϑϩϯτɺαʔόʔɺͪΐͬͱΫϥυ Alibaba Cloud
MVP
GraphQLͷ໊લ͚ ࠓ ͢ ͜ ͱ “GraphQLͬΆ͍”໊લʹ ͢ΔͨΊʹࢲ͕ҙ͍ࣝͯ͠Δ͜ͱ 1
querymutationͷ໊લͷ
(1) queryͷ߹ ݁ ໊લͷཪʹόοΫΤϯυͷಈ࡞͕ݟ͑Δ 2.1 REST ໊લͷཪʹཉ͍͠σʔλ͕ݟ͑Δ GraphQL ͿͬͪΌ͚queryͷ໋໊RESTͱ͋·Γ͕ࠩͳ͍ؾ͢Δ
σʔλΛऔͬͯ͘Δͭ
(1) GET: /users/:idΛqueryʹ͢Δ ྫ ͑ getUser(id: $id) { email
name } (ਖ਼͜ΕશવڐͤΔ) ϢʔβʔΛใΛදࣔ͢ΔͨΊͷΤϯυϙΠϯτ 2.1 user(id: $id) { email name } X O ???ʮԶgetUser͍ͨ͠Μ͡Όͳͯ͘userͷใ͕ཉ͍͠ΜͩΑʯ
(2) mutationͷ߹ ݁ ໊લͷཪʹϦιʔε͕ݟ͑Δ 2.2 REST ໊લͷཪʹৼΔ͍͕ݟ͑Δ GraphQL ※Ϧιʔε:
αʔόʔͰऔΓѻΘΕΔσʔλͷҙ ※ৼΔ͍: ΫϥΠΞϯτͰϢʔβʔ͕࣮ߦ͢Δಈ࡞ͷҙ σʔλΛߋ৽͢Δͭ
ྫ ͑ (2) POST: /users/:id/followΛmutationʹ͢Δ mutation createFollowee(id: $id) {
user { id name } } mutation follow(id: $id) { user { id name } } FolloweeͬͯϦϨʔγϣϯ͕ݟ͑ͯ͠·͏ “follow”Ͱ1ͭͷৼΔ͍͕ݟ͑Δ (ϢʔβʔΛϑΥϩʔ͢ΔͨΊͷΤϯυϙΠϯτ) ײ͡Δྗ͕େࣄ 2.2 X O
ͳͥ͜Ε͕ྑ͍ͱࢥ͏ͷ͔ ཧ ༝ 3 GraphQLόοΫΤϯυͷσʔλߏΛΒͳ͍ ΫϥΠΞϯτͷ։ൃऀͨͪͷͨΊʹ࡞ΒΕ͔ͨΒ ͭ·Γྺ࢙తഎܠ
ྺ࢙తഎܠ ཧ ༝ 3 ΫϥΠΞϯτ࡞Δਓͱαʔόʔ࡞Δਓผ(ͷͣ) σΧ͍৫ͰෳࡶͳσʔλߏͷαʔϏεΛӡ༻͍ͯ͠Δதɺ σʔλߏΛΒͳ͍ਓͰָʹཉ͍͠σʔλΛऔಘ͍ͨ͠ GraphQLΛ࡞ͬͨͷFacebook
ྺ࢙తഎܠ ཧ ༝ 3 (࣮࢞ͷߘ) • ༑ୡͷߘͷதʹ༑ୡͷ༑ୡͷίϝϯτ͕ݟ͑Δ • ͍͍Ͷʹࣗͷ༑ୡ͕༏ઌදࣔ͞ΕΔ ϦϨʔγϣϯΛ͜Ͷ͘Γճ͍ͯ͠Δ
ྺ࢙తഎܠ ཧ ༝ 3 ϦιʔεAΛऔ͖ͬͯͨΒͦͷidʹج͍ͮͯ ϦιʔεBΛऔ͖ͬͯͯ…. Έ͍ͨͳ͕άνϟάνϟʹଓ͍͍ͯ͘ RESTͰΔͱԿϦΫΤετΛૹΔඞཁ͕͋Δ ͜ΕΛָʹͨͯ͘͠ੜ·Εͨͷ͕GraphQL
ݴ͍͍ͨ͜ͱ ݁ ໊લͷཪʹόοΫΤϯυ͕ݟ͑Δ 5 REST ໊લͷཪʹΫϥΠΞϯτ͕ݟ͑Δ GraphQL ※͜ΕࢲͷࢦͰ͋ͬͯղͰ͋Γ·ͤΜ
ऴ