Upgrade to Pro — share decks privately, control downloads, hide ads and more …

REST脳脱出のためのGraphQLの命名の話

asmsuechan
December 19, 2018
270

 REST脳脱出のためのGraphQLの命名の話

asmsuechan

December 19, 2018
Tweet

Transcript

  1. (1) GET: /users/:idΛqueryʹ͢Δ ྫ ͑ ͹ getUser(id: $id) { email

    name } (ਖ਼௚͜Ε͸શવڐͤΔ) ϢʔβʔΛ৘ใΛදࣔ͢ΔͨΊͷΤϯυϙΠϯτ 2.1 user(id: $id) { email name } X O ???ʮԶ͸getUser͍ͨ͠Μ͡Όͳͯ͘userͷ৘ใ͕ཉ͍͠ΜͩΑʯ
  2. (2) mutationͷ৔߹ ݁ ࿦ ໊લͷཪʹϦιʔε͕ݟ͑Δ 2.2 REST೴ ໊લͷཪʹৼΔ෣͍͕ݟ͑Δ GraphQL ※Ϧιʔε:

    αʔόʔ಺ͰऔΓѻΘΕΔσʔλͷҙ ※ৼΔ෣͍: ΫϥΠΞϯτͰϢʔβʔ͕࣮ߦ͢Δಈ࡞ͷҙ σʔλΛߋ৽͢Δ΍ͭ
  3. ྫ ͑ ͹ (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