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

AppSync入門できなかったのでGraphQLに入門した

sin-tanaka
September 21, 2018

 AppSync入門できなかったのでGraphQLに入門した

2018/9/21 JAWS-UG長野でのLT

【2018 秋の部】AWS Cloud Express Roadshow in 長野 後夜祭
https://jawsug-nagano.connpass.com/event/99668/

sin-tanaka

September 21, 2018
Tweet

More Decks by sin-tanaka

Other Decks in Technology

Transcript

  1. AppSync • 4݄ʹҰൠެ։ • GraphQLϚωʔδυαʔϏε • HTTP(S)ϦΫΤετΛड͚ͯAWSαʔϏεʢLambda, DynamoDB, ElasticSearchʣʹͭͳ͗͜Έ͕Ͱ͖Δ •

    GraphQLͷεΩʔϚఆٛ • ΫΤϦΛࢼͤΔίϯιʔϧ෇͖ • GraphQLͷSubscriptionͱ͍͏࢓૊ΈΛ࢖ͬͯσʔλͷมߋΛ ݕ஌ˠը໘΁ͷ൓ө·Ͱग़དྷΔ
  2. ాத ৻ଠ࿠(@_sin_tanaka) ʢגʣ೔ຊγεςϜٕݚ / GeekLab.NAGANO ελοϑ GitHub / Medium: @sin_tanaka

    Իָͱਂ໷ϥδΦ͕޷͖ serverless-wsgi ʹϓϧϦΫग़ͨ͠Γͨ͠ PyCon JP 2018 ͰτʔΫηογϣϯ ← NEW!!
  3. GraphQLͷ࢖͍ํ 1 type Query { 2 me: User 3 }

    4 5 type User { 6 id: ID 7 name: String 8 } 9 foo.scheme εΩʔϚ: αʔό΍ϚωʔδυαʔϏεଆʹఆٛ͢Δ
  4. GraphQLͷ࢖͍ํ 1 { 2 me { 3 name 4 }

    5 } ΫΤϦ: ΫϥΠΞϯτଆ͔Β౤͛Δσʔλ 1 { 2 "me": { 3 "name": "Luke Skywalker" 4 } 5 } https://hogehoge.com/graphql?{me{name}}
  5. Query • ྫ: type Query { allUser(id: Int, first: Int):

    [User] getUser(role: String) me: User } type User { id: ID name: String } foo.scheme
  6. Query - Alias • ྫ: ಉ͡ΫΤϦ͕ෳ਺͋Δͷ͸μϝͳͷͰAliasΛ࢖͏ { getUser(role: admin) {

    id firstName lastName phone username } getUser(role: accountant) { id firstName lastName phone username } }
  7. Query - Alias • ྫ: ಉ͡ΫΤϦ͕ෳ਺͋Δͷ͸μϝͳͷͰAliasΛ࢖͏ { admins: getUser(role: admin)

    { id firstName lastName phone username } accountants: getUser(role: accountant) { id firstName lastName phone username } }
  8. Query - Fragment • ྫ: ·ͱΊ͍ͨ৔߹ { admins: getUser(role: admin)

    { id firstName lastName phone username } accountants: getUser(role: accountant) { id firstName lastName phone username } }
  9. Query - Fragment • ྫ: ·ͱΊ͍ͨ৔߹ { admins: getUser(role: admin)

    { …user } accountants: getUser(role: accountant) { …user } } fragment user on User { id firstName lastName phone username }
  10. Mutation • ࡞੒ / มߋ΋εΩʔϚʹఆٛ͢Δ type Mutation { createReview(episode: String,

    review): Review } mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) { createReview(episode: $ep, review: $review) { stars commentary } } ΫΤϦ
  11. GraphQL vs REST? • REST • endpoint͕ෳ਺ • ԿΛͲ͏ฦ͔͢͸αʔό͕ܾΊΔ •

    GraphQL • endpoint͕୯Ұ • ԿΛͲ͏ฦ͔͢͸ΫϥΠΞϯτ͕ܾΊΔ