Pro Yearly is on sale from $80 to $50! »

RubyではじめるGraphQL

 RubyではじめるGraphQL

#ebisurb

C582b722e015633f7900083f8ea75732?s=128

hatappi

May 29, 2019
Tweet

Transcript

  1. RubyͰ࢝ΊΔ GraphQLೖ໳ #23 @hatappi

  2. Yusaku Hatanaka @hatappi Merpay Inc. Go, Ruby, etc… <<Ruby Activity>>

    Roppongi.rb organizer RubyKaigi 2019
  3. ಥવͰ͕࣭͢໰Ͱ͢

  4. GET /users/1 ϦΫΤετ͠·ͨ͠ Կ͕ฦ͖ͬͯ·͔͢ʁ

  5. ᶃ ᶄ ᶅ

  6. ᶃ ᶄ ᶅ

  7. ༗ޮͳJSONΛฦͤΔͳΒOK ͔͠͠ϦιʔεʹΑͬͯϑΥʔϚοτ͕ҟͳΔͱɻɻɻ Τϥʔ࣌ͷϨεϙϯεϑΥʔϚοτ๨Ε͕ͪ

  8. userͱfriendsΛऔಘ͍ͨ͠ GET /users/1 GET /users/1/friends

  9. ඞཁͳ৘ใΛऔಘ͢ΔͨΊʹ Կճ͔ϦΫΤετΛ͢Δ͜ͱ΋

  10. GraphQL͕ ׆༂Ͱ͖Δ͔΋ʁʂ

  11. GraphQL • APIͷͨΊͷΫΤϦݴޠ • ΫΤϦݴޠͷ࢓༷ͱͯ͠ܕఆٛ͞Εͨε ΩʔϚΛఆٛͯ͠ΫΤϦΛ༻͍ͯ໰͍߹Θ ͤΛ͢Δ • FacebookʹΑͬͯ։ൃ͞Εͯ2015೥ʹOSSͱ ͯ͠ެ։͞Εͨ

    • https://graphql.org/
  12. ΫΤϦݴޠ • GraphQLͷAPI΁ϦΫΤετΛ͢ΔͨΊͷݴޠ • σʔλऔಘܥ͸ Query, σʔλΛ࡞੒ͨ͠Γߋ৽͸ Mutation, αʔόʔ͔ΒͷΠϕϯτ Λड͚औΔ

    Subscription ͕͋Δ • GraphQL APIͷ࢓༷Λهड़ • ֤ϑΟʔϧυʹ͸ܕΛએݴ͕ඞཁ • Int, Float, String, Boolean, IDͳͲ͕࠷ॳ͔Βఆٛ͞Ε͍ͯͯࣗ෼Ͱఆٛ͢Δ͜ ͱ΋Մೳ εΩʔϚݴޠ
  13. GitHub GraphQL API https://developer.github.com/v4/explorer/ ਎ۙʹࢼͤΔ!! ※ຊ൪ͷσʔλͳͷͰߋ৽ܥͳͲ͸஫ҙͯ͠࢖͏ʂ

  14. POST /graphql

  15. ϦΫΤετ Ϩεϙϯε

  16. ϦΫΤετ Ϩεϙϯε

  17. ͜͏͍͏ͷ͕΄͍͠!! ʹର͍ͯۙ͠ܗͰฦͯ͘͠ΕΔ

  18. RubyͰGraphQL

  19. graphql-ruby • GraphQLͷύʔαʔͱϥϯλΠϜͷRuby࣮૷ • 2019೥05݄29೔ v1.9.6 ͕࠷৽ • 1.8·ͰಠࣗͷDSL͚ͩͬͨͲ1.8Ҏ߱͸Ϋ ϥεϕʔεͰεΩʔϚఆٛͰ͖ΔΑ͏ʹ

    ͳͬͨ
  20. RubyΒ͘͠GraphQLͷεΩʔϚΛ ఆٛ͢Δ͜ͱ͕Ͱ͖Δ

  21. Anket + GraphQL

  22. • Slack ্ͰΞϯέʔτΛͱΔͨΊͷαʔϏε • 2018/11ʹ βϦϦʔε • Ξϯέʔτͷ࡞੒΍౤ථ͸ Slack ্͔Βߦ͏

    • WEB্ͰμογϡϘʔυΛݟΔ͜ͱ͕Ͱ͖ͯ Rails 5 Ͱ࡞੒͞Ε͍ͯΔ • Railsͱ͔k8sͱ͔ٕज़తཁૉΛࢼ͢৔ͱͯ͠ϓϥΠ ϕʔτͰ࡞੒
  23. ಋೖͨ݁͠Ռ

  24. GraphiQL͕ศར • GraphQL ʹରͯ͠ΫΤϦΛൃߦ͢ΔͨΊͷπʔϧ • GithubͷAPIίϯιʔϧͰ΋࢖༻͞Ε͍ͯΔ • ΫΤϦͷൃߦ͚ͩͰͳ͘ΫΤϦิ׬΍APIϦϑΝϨϯε͕࢖͑ΔͷͰIDEͱͯ͠΋࢖͑Δ • graphql-rubyΛRailsͰ࢖͏࣌͸install͢Δ࣌ʹҰॹʹೖΔ

  25. ςετ

  26. Complexity & Depth ͷ੍ݶ͕͔͚ΒΕΔ • Complexity • 1requestʹର͢ΔComplexityΛ੍ݶ • Depth

    • queryͷೖΕࢠͷ੍ݶ
  27. Complexity fields͝ͱʹComplexityΛઃఆͰ͖ΔͷͰॏ ͍ॲཧͷੜ੒ίετΛେ͖Ίʹઃఆ͢Δͳ Ͳͷઃఆ͕Մೳ

  28. Depth

  29. ·ͱΊ • GraphQL, graphql-rubyͷ࿩Λ͠·ͨ͠ • ୯ҰͷΤϯυϙΠϯτͳͷͰύϑΥʔϚϯεͷܭଌͳͲ͸޻෉͕ඞཁ • Anket ͸ݱঢ়಺޲͖ʹ͔͠GraphQL API

    Λެ։ͯ͠·ͤΜ͕ɺࠓޙ֎޲ ͚ʹ΋ެ։༧ఆͰ͢ʂʂ • ެ։ͨ͠Βͥͻ࢖ͬͯΈ͍ͯͩ͘͞ʂʂ