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

GraphQL と Prisma から考える次のN年を見据えた技術選定 / Architecture decision for the next N years at StudySapuri

942bb606679caf4c57b38927f83178e1?s=47 qsona
November 27, 2021

GraphQL と Prisma から考える次のN年を見据えた技術選定 / Architecture decision for the next N years at StudySapuri

JSConf JP 2021 で登壇した資料です #jsconfjp #jsconfjp_b

Links:
[Active Recordから考える次の10年を見据えた技術選定](https://speakerdeck.com/yasaichi/architecture-decision-for-the-next-10-years-at-pixta)
[GraphQL を活用したスキーマ駆動開発の実践](https://speakerdeck.com/qsona/schema-driven-development-with-graphql)
[GraphQL を利用したアーキテクチャの勘所 / Architecture practices with GraphQL - Speaker Deck](https://speakerdeck.com/qsona/architecture-practices-with-graphql)
[最高のマスターデータ管理手法考察 & VSCode Extension を活用した話](https://speakerdeck.com/qsona/developing-masterdata-management-tool-by-using-vscode-extension)
[サービスクラスについては僕も悪かったと思っているけど、それでもCQSは実現したいんだ](https://qiita.com/a-suenami/items/8897e2e36fe2836c6949)
[Smart UI パターンが再評価される世界 - id:onk のはてなブログ](https://onk.hatenablog.jp/entry/2020/11/11/024531)
[Ruby on Railsの正体と向き合い方](https://speakerdeck.com/yasaichi/what-is-ruby-on-rails-and-how-to-deal-with-it)
[Explore how to extend the Prisma Client · Issue #7161 · prisma/prisma](https://github.com/prisma/prisma/issues/7161)
[プログラミング言語の未来はどうなるか | κeenのHappy Hacκing Blog](https://keens.github.io/blog/2021/01/04/future_of_proguramming_languages/)
[Prisma で Factory を作るための便利関数を作りました!](https://zenn.dev/seya/articles/a0d2d2da20ddad)

942bb606679caf4c57b38927f83178e1?s=128

qsona

November 27, 2021
Tweet

More Decks by qsona

Other Decks in Technology

Transcript

  1. GraphQL ͱ Prisma ͔Βߟ͑Δ ࣍ͷN೥Λݟਾٕ͑ͨज़બఆ @qsona 2021-11-27 JSConf JP

  2. whoami • @qsona • Web Engineer at ελσΟαϓϦ (ϦΫϧʔτ) •

    Node.js / Rails / GraphQL / Microservices
  3. @qsona ͱ Node.js • ιϑτ΢ΣΞΤϯδχΞͱͯ͠ॳΊͯݱ৔ͰίʔυΛॻ͍ͨͷ͕
 αʔόʔαΠυ Node.js Ͱͨ͠ (!!) •

    Node v0.10, EcmaScript 5 • Node ֶԂͷίϛϡχςΟʹҭͯͯ΋ΒͬͨͷͰɺ
 ࠓ೔ͷ৔ͰొஃͰ͖ͯͱͯ΋͏Ε͍͠Ͱ͢!
  4. ຊൃදͷ֓ཁ • ͜ͷൃද͸ɺ
 @_yasaichi ͞ΜʹΑΔൃද
 ʮActive Record͔Βߟ͑Δ
 ࣍ͷ10೥Λݟਾٕ͑ͨज़બఆʯ (2021/09) ΁ͷ


    Ξϯαʔൃද (?) Ͱ͢ https://speakerdeck.com/yasaichi/architecture-decision-for-the-next-10-years-at-pixta
  5. ͓͜ͱΘΓ • ͜ͷࢿྉʹ͓͚Δจ੹͸͢΂ͯ @qsona ʹ͋Γ·͢ • ઌߦൃදͷ @_yasaichi ͞ΜͷҙਤɾχϡΞϯεΛ
 Ͱ͖Δ͚ͩਖ਼͘͠἞Ή౒ྗΛ͍ͯ͠·͕͢ɺ


    ಺༰ʹٙ໰౳͋Δ৔߹ɺݩͷࢿྉΛ௚઀ࢀর͍ͯͩ͘͠͞
  6. ઌߦൃදʹ͓͚Δٕज़બఆࣄྫ • @_yasaichi ͞Μͷॴଐ͢Δ૊৫Ͱ͸ɺ΋ͱ΋ͱ Ruby on Rails Λ׆༻͓ͯ͠ Γɺಛʹ Active

    Record ͕΋ͨΒ͢։ൃੜ࢈ੑΛߴ͘ධՁ͍ͯ͠Δ • ͔͠͠ɺϑϩϯτΤϯυ (TypeScript) ͱόοΫΤϯυ (Ruby) Ͱ։ൃݴޠ͕ ҧ͏͜ͱʹΑΔɺೝ஌ෛՙͷ૿େ͕՝୊ʹͳͬͨ • ૊৫શମͱͯ͠ɺόοΫΤϯυΛ Node.js + TypeScript Ͱ։ൃ͢Δબ୒ࢶΛ
 ৽ͨʹऔΓೖΕΔܾஅΛͨ͠
  7. ઌߦൃදʹ͓͚Δٕज़બఆࣄྫ • Node.js + TypeScript Ͱͷ O/R Mapper ϥΠϒϥϦͱͯ͠ɺ Prisma

    ͷ࠾༻Λݕ౼ͨ͠ • ͔͠͠ɺ։ൃதظҎ߱ͷ։ൃੜ࢈ੑͷ௿ԼΛݒ೦͠ɺ
 Ұ୴࠾༻ΛݟૹΔܾஅΛͨ͠ • ৄ͍͠ཧ༝͸ɺຊൃදͷୈೋ෦Ͱ৮Ε·͢
  8. ຊൃදͰͷٕज़બఆࣄྫ • @qsona ͕ॴଐ͢ΔɺελσΟαϓϦ։ൃͷࣄۀ෦ (چ Quipper) ಺Ͱͷɺ
 ৽نαʔϏε։ൃࣄྫ • ͦͷதͷҰ෦ͷ(ϚΠΫϩ)αʔϏεͰɺ


    Node.js + TypeScript + Prisma Λ࠾༻ͨ͠ (2020/08 ͝Ζͷҙࢥܾఆ) • ผͷαʔϏεͰ͸ Ruby on Rails ΋Ҿ͖ଓ͖࠾༻ • ※ ઌߦൃදʹൺ΂ͯɺείʔϓͷڱ͍ҙࢥܾఆͰ͋Δ఺ʹ஫ҙ
  9. None
  10. ೋͭͷٕज़બఆͷൺֱ • ͳͥ @qsona ͷॴଐ͢ΔνʔϜͰ͸
 Prisma Λ࠾༻ͨ͠ͷ͔? • ͳͥ @_yasaichi

    ͞Μͷॴଐ͢Δ૊৫Ͱ͸
 Prisma ͷ࠾༻Λݟૹͬͨͷ͔? • @qsona ͷॴଐ͢ΔνʔϜͰ͸ɺ@_yasaichi ͞Μ͕ද໌ͨ͠ݒ೦ʹ
 ରॲͰ͖͍ͯΔͷ͔?
  11. ຊൃදͷߏ੒ • ४උ: Prisma ͱ͸ɺͦͷ։ൃମݧ • ୈҰ෦: ελσΟαϓϦʹ͓͚Δ GraphQL +

    Prisma ࠾༻ࣄྫͱ ٕज़બఆͷཧ༝ • ୈೋ෦: Active Record ͱରൺͯ͠ߟ͑Δ
 Prisma ͱ։ൃதظҎ߱ͷ։ൃੜ࢈ੑ
  12. ४උ: Prisma ͱ͸ɺͦͷ։ൃମݧ

  13. https://www.prisma.io/

  14. Prisma ͱ͸ • Database toolkit (O/R Mapper ΛؚΉ) • Node.js

    + TypeScript ͕લఏ • PostgreSQL, MySQL, MongoDB ͳͲʹରԠ • ͜ͷൃදͷείʔϓͰ͸ PostgreSQL / MySQL Λ૝ఆ
  15. Prisma Λར༻ͨ͠։ൃϑϩʔ • ·ͣ Prisma Schema Λهड़͢Δ https://www.prisma.io/docs/concepts/components/prisma-schema

  16. Prisma Λར༻ͨ͠։ൃϑϩʔ • Prisma schema ͔ΒҎԼͷ2͕ͭࣗಈੜ੒͞ΕΔ • DB ϚΠάϨʔγϣϯͷίʔυ (Prisma

    Migrate) • ΫΤϦϏϧμʔ (ORM) ͷίʔυ (Prisma Client) Rails Ϣʔβʔ޲͚৘ใ: ridgepole (cookpad) ͱಉ͡։ൃϑϩʔ
  17. Prisma Λར༻ͨ͠։ൃϑϩʔ • Prisma Client Λར༻ͯ͠
 ΞϓϦέʔγϣϯͷϩδοΫ ΛίʔσΟϯά͢Δ https://www.prisma.io/docs/concepts/components/prisma-client

  18. Prisma Λར༻ͨ͠։ൃମݧ ࢲݟ: ։ൃମݧ͕ඇৗʹྑ͍ • Prisma schema Λத৺ͱͨ͠ɺҰ؏ͨ͠։ൃମݧ • ࠩ෼

    Migration ·ͰΧόʔͯ͘͠ΕΔ • TypeScript ͷ੩తܕ͕όνόνʹޮ͘ • ࢖ͬͯΈΕ͹Θ͔Γ·͢ʂʂʂʂ (౤͛΍Γ)
  19. ୈҰ෦: ελσΟαϓϦʹ͓͚Δ GraphQL + Prisma ࠾༻ࣄྫͱ ٕज़બఆͷཧ༝

  20. None
  21. https://studysapuri.jp/course/junior/release-2022-spring/

  22. ৽ن։ൃϓϩδΣΫτͷ঺հ • ελσΟαϓϦͷ͏ͪɺதֶੜͷϢʔβʔΛର৅ʹ
 αʔϏεΛϦχϡʔΞϧ͢ΔϓϩδΣΫτ • ։ൃ͢Δ΋ͷ • iOS / Android

    / PC Web Apps • Backend APIs • ίϯςϯπΛ؅ཧ͢ΔγεςϜ ֶशαʔϏεΛϑϧεΫϥονͰ ࡞ΔΠϝʔδ
  23. ্ஈͷٕज़తҙࢥܾఆ ߴ͍։ൃੜ࢈ੑΛ໨ࢦͯ͠ɺҎԼͷٕज़తҙࢥܾఆΛߦͬͨ • GraphQL Λશ໘తʹ׆༻͢Δ • Clients <=> API Gateway

    <=> Backend Services • Backend ͸
 main αʔϏεͱ content αʔϏεʹ෼཭ͯ͠։ൃΛਐΊΔ
  24. ͦΕͧΕͷαʔϏεͷ੹຿ • content αʔϏε (ࠓճͷ࿩ͷϝΠϯ) • ֶशʹඞཁͳʮίϯςϯπʯΛ؅ཧ͢Δ੹຿Λ࣋ͭ • ໰୊ /

    ಈը / ͦΕΒͷ֊૚ߏ଄ ͳͲ • main αʔϏε • Ϣʔβʔͷֶशཤྺͷσʔλ΍ɺͦͷଞ
 ϢʔβʔσʔλΛ؅ཧ͢Δ੹຿Λ࣋ͭ • Ruby on Rails Λ࠾༻
  25. ΞʔΩςΫνϟਤ (Ұ෦ൈਮ)

  26. GraphQL Λશ໘తʹ࠾༻ͨ͠ཧ༝ • εΩʔϚۦಈ։ൃʹΑΓɺطଘ ͷ૊৫త՝୊ΛղܾͰ͖Δ • Client ͔Β Backend ·Ͱશͯ

    GraphQL ʹ͢Δ͜ͱͰ
 ։ൃੜ࢈ੑΛߴΊΔ͜ͱ͕Ͱ͖Δ
  27. ࢀߟ: ॳखͰͷαʔϏε෼ׂͷੋඇ • αʔϏε։ൃͷॳखͰ͍͖ͳΓ(ϚΠΫϩ)αʔϏεʹ෼ׂ͢Δͷ͸
 ϦεΫ΋ߴ͘ɺҰൠతʹ͸નΊΒΕͳ͍ • ελσΟαϓϦͷ৔߹ɺ໿10೥ͷֶशαʔϏε։ൃܦݧ͔Β
 ϏδωευϝΠϯͷڥքΛ͋Δఔ౓ཧղ͍ͯ͠Δ • ࠓճ

    content αʔϏεΛ෼཭͢Δ͜ͱ͸ɺϦεΫΑΓ΋
 Ϧλʔϯ͕ଟ͍ͱ݁࿦͚ͮͨ
  28. content αʔϏεͷٕज़બఆ • GraphQL • ݴޠ/؀ڥ: Node.js + TypeScript •

    ORM ϥΠϒϥϦ: Prisma
  29. content αʔϏεͷٕज़બఆཧ༝ • νʔϜͷೳྗɾΦʔφʔγοϓ • GraphQL (ΤίγεςϜؚΉ) ͱͷ૬ੑ • ੩తܕ෇͚

    (ΤίγεςϜؚΉ) ͱͷ૬ੑ • Read ͱ Write Ͱେผ͞ΕΔ
 αʔϏεಛੑͱͷ૬ੑ TypeScript + Node.js Λબ୒ͨ͠ ੵۃతཧ༝ Rails ActiveRecord Λආ͚Δ ফۃతཧ༝͕ͩ ͜ͷൃදʹ͓͚Δຊ୊
  30. νʔϜͷೳྗɾΦʔφʔγοϓ ҎԼͷཧ༝ͰɺRuby on Rails ͱ Node.js + TypeScript ͷ2୒ʹߜͬͨ •

    Ruby on Rails • ελσΟαϓϦʹ͓͍ͯελϯμʔυͳબ୒Ͱ͋Γɺී௨ʹ࠾༻Մೳ • Node.js + TypeScript • qsona ͕ αʔόʔαΠυ Node.js ͷܦݧ͋Γɺ೤ҙ΋ڧ͍ • νʔϜͱͯ͠ TypeScript Λ໰୊ͳ͘࢖͑Δ (Web Frontend Ͱར༻) • ͦͷଞ͸ɺνʔϜͱͯ͠ೳྗ΍೤ҙΛ͍࣋ͬͯΔબ୒͸ಛʹͳ͔ͬͨ • (͜ΕҎ߱͸ Ruby on Rails ͱ Node.js + TypeScript ͱͷൺֱͰߟ͑Δ)
  31. GraphQL (ΤίγεςϜؚΉ) ͱͷ૬ੑ • Ruby Ͱ΋໰୊ͳ͘ GraphQL Server Λ࣮૷Ͱ͖Δ •

    ڧ͍ͯݴ͏ͳΒ͹ TypeScript + Node.js ͷ΄͏͕ɺ
 ΑΓ GraphQL ͱ਌࿨ੑ͕ߴ͍ • ฒߦॲཧͱͷ૬ੑ͕ྑ͍ • JavaScript / TypeScript + GraphQL ͷํ͕ɺ
 ΤίγεςϜ͕੝Γ্͕͍ͬͯΔ
  32. ੩తܕ෇͚ (ΤίγεςϜؚΉ) ͱͷ૬ੑ αʔϏεͷಛੑ͔ΒɺTypeScript ͷ੩తܕ෇͚͕༗རͱߟ͑ͨ • ΄ͱΜͲͷܕఆٛΛɺࣗಈੜ੒ʹΑͬͯແྉͰಘΒΕΔ • ςʔϒϧఆٛ (Prisma)

    • GraphQL Schema (graphql-codegen/typescript-resolvers) • ίϯςϯπσʔλ (json-schema-to-typescript) • ೖྗࢧԉπʔϧͷͨΊʹ JSON Schema Λผ్ఆ͍ٛͯ͠Δ
 (ৄ͘͠͸ࢿྉࢀর) • ʮ໰୊ʯͷσʔλߏ଄ʹ TypeScript ͷ Union Types ͕Ϛον͢Δ • ໰୊ͷछྨ͝ͱʹɺ࣋ͭΧϥϜ͕มΘΔ • ੩తܕ෇͚ͷॿ͚ΛआΓͣʹѻ͏ͱɺϓϩάϥϛϯά্ͷϛε͕ى͖΍͍͢ https://speakerdeck.com/qsona/developing-masterdata-management-tool-by-using-vscode-extension
  33. Read ͱ Write Ͱେผ͞ΕΔ
 αʔϏεಛੑͱͷ૬ੑ αʔϏεͷಛ௃ͱͯ͠ɺWrite ͱ Read ͷ܏޲͕શ͘ҟͳΔ •

    ϝΠϯͷτϥϑΟοΫͷ΄ͱΜͲ͕ Read • ΤϯυϢʔβʔ (ੜె) ͸ίϯςϯπΛॻ͖ࠐ·ͳ͍ • Write ͸ίϯςϯπνʔϜ͕৽͍͠ίϯςϯπσʔλΛຊ൪ϦϦʔε͢Δͱ͖͚ͩ • ଟ͘ݟੵ΋ͬͯ΋1೔਺ճఔ౓
  34. Read ͱ Write Ͱେผ͞ΕΔ
 αʔϏεಛੑͱͷ૬ੑ αʔϏεͷಛ௃ͱͯ͠ɺWrite ͱ Read ͷ܏޲͕શ͘ҟͳΔ •

    υϝΠϯϩδοΫͷ΄ͱΜͲ͕ Write ʹू·Δ • Read ଆ͸ɺDB ʹೖ͍ͬͯΔσʔλߏ੒Λॊೈʹɺ͔ͭ
 ύϑΥʔϚϯεྑ͘ΫΤϦͰ͖ΔΑ͏ʹ͢Δ͜ͱ͕؊ͱͳΔ • Read ଆʹυϝΠϯϩδοΫ͸গͳ͍
  35. Read ͱ Write Ͱେผ͞ΕΔ
 αʔϏεಛੑͱͷ૬ੑ • ͜ͷαʔϏεಛੑʹର͠ɺ
 CQS (Command-Query Separation)

    Pattern Λద༻Ͱ͖Δͱߟ͑ͨ • Command (ॻ͖ࠐΈܥ) ͱ 
 Query (ಡΈࠐΈܥ) ʹ
 γεςϜ্ͷίʔυΛେผ͢Δύλʔϯ τϥϑΟοΫ υϝΠϯ
 ϩδοΫ 3FBE େ গ 8SJUF ۃখ ଟ
  36. ิ଍: ͜ͷΑ͏ͳಛੑ͸͋Δఔ౓ීวత ͦͷ๻ͷܦݧ্ɺ"DUJWF3FDPSEΛ࢖ͬͯΞϓϦέʔγϣϯΛ։ൃ͢Δ৔ ߹ɺࢀরܥͷػೳʢݕࡧͱ͔ʣ͸ύϑΥʔϚϯε໘Ͱ೰Ή͜ͱ͕ଟ͘ɺొ ࿥ɾߋ৽ܥͰ͸ػೳ໘ʢ࢓༷ͷෳࡶԽɺίʔυͷՄಡੑɺόάࠞೖ཰ʣͷ೰ Έ͕ଟ͘ͳΓ͕ͪͰ͋Δɻͱ͍͏͔ɺ͜Ε͸͓ͦΒ͘3BJMTʹݶͬͨ࿩Ͱ͸ ͳ͘ɺ͔ͩΒͦ͜$234ͱ͍͏ΞʔΩςΫνϟύλʔϯ͕஫໨͞Ε͍ͯΔΜ ͩͱࢥ͏
 Ҿ༻ݩʮαʔϏεΫϥεʹ͍ͭͯ͸๻΋ѱ͔ͬͨͱࢥ͍ͬͯΔ͚ͲɺͦΕͰ΋$24͸࣮ݱ͍ͨ͠Μͩʯ
 !BTVFOBNJ

    https://qiita.com/a-suenami/items/8897e2e36fe2836c6949
  37. CQS Pattern ͱ ActiveRecord • ࢲݟ: CQS Pattern ͱ Rails

    Active Record ͱͷ૬ੑ͕͋·Γྑ͘ͳ͍ • Active Record ͸جຊతʹ1ςʔϒϧɾ1Ϟσϧ͕લఏ • CQS ύλʔϯͰ͸ɺCommand / Query ͦΕͧΕͰผͷϞσϧΛ࢖͏ • Rails ActiveRecord ΛࣗྗͰ֦ு͢Δ͜ͱ͸Ͱ͖Δ͕ɺ
 Rails Way ͔Β཭ΕΔͷͰ Rails ͷڧΈΛ׆͔ͤͳͦ͏ • => Rails ͷબ୒Λආ͚ΔཁҼʹͳͬͨ
  38. GraphQL + Prisma + CQS Pattern • Prisma ͸ೖग़ྗʹ Plain

    Object Λ࢖͏ͷͰɺ
 CQS Pattern Λࣗવʹద༻͢Δ͜ͱ͕Ͱ͖ͨ
  39. GraphQL + Prisma + CQS Pattern • චऀ @qsona ͸

    GraphQL + Prisma + CQS Pattern ͷ
 ૊Έ߹Θͤʹେ͖ͳظ଴Λ๊͍͍ͯΔ͕ɺ
 ࣗ਎ͷྗྔෆ଍ʹΑΓɺຊൃදͰ͸े෼આ໌Ͱ͖͍ͯͳ͍ • ୅ΘΓʹ (?) ࢀߟࢿྉͱͯ͠
 ҒେͳهࣄΛ঺հ͠·͢ Smart UI ύλʔϯ͕࠶ධՁ͞ΕΔੈք (@onk) https://onk.hatenablog.jp/entry/2020/11/11/024531
  40. ͜Ε·Ͱͷ։ൃ;Γ͔͑Γ • ٕज़બఆ࣌ͷ΋͘ΖΈ௨Γɺ
 ͔ͳΓߴ͍։ൃੜ࢈ੑΛಘΔ͜ͱ͕Ͱ͖͍ͯΔ • TypeScript ͷ੩తܕ෇͚͸͔ͳΓ৺ڧ͍ɻ
 ͦΕ͕΄΅ແྉͰಘΒΕ͍ͯΔ • CQS

    ύλʔϯΛ࣠ʹͯ͠։ൃͷϨʔϧΛෑ͍ͨ͜ͱͰɺ
 ίʔυΛॻ͘৔ॴʹ໎͍͕ੜ͡ʹ͍͘
  41. ͜Ε·Ͱͷ։ൃ;Γ͔͑Γ • ͨͩ͠ɺ͜Ε·Ͱͷ։ൃظؒ͸໿1.5೥ɺ
 ͜ͷαʔϏεͷ։ൃʹ͋ͯΒΕͨਓ਺͸ฏۉ1ਓఔ౓ɻ
 ਖ਼ࣜϦϦʔε΋·ͩ • => ։ൃॳظͷஈ֊ͱݴ͑Δ • ͜ͷΞʔΩςΫνϟ͸ɺ։ൃதظҎ߱๚ΕΔ


    υϝΠϯϩδοΫͷෳࡶԽΛड͚ೖΕɺ։ൃੜ࢈ੑΛอͪଓ͚Δ͜ͱ͕
 Ͱ͖Δͷ͔?
  42. ୈೋ෦: Active Record ͱରൺͯ͠ߟ͑Δ Prisma ͱ։ൃதظҎ߱ͷ։ൃੜ࢈ੑ

  43. Active Record ͷ։ൃੜ࢈ੑ • ࠶ͼɺઌߦൃදΛҰ෦঺հ͠ͳ͕ΒਐΊ·͢ • Rails Active Record ͓Αͼ


    Prisma ͕ಋ͘ΞʔΩςΫνϟͱ
 ͦͷ։ൃੜ࢈ੑʹ͍ͭͯ
  44. Active Record ͷ։ൃੜ࢈ੑ • ઌߦൃදͰ͸ɺ
 Ruby on Rails ͷ Active

    Record Λར༻ͨ͠։ൃͷੜ࢈ੑΛ
 ։ൃॳظ / ։ൃதظҎ߱ ͦΕͧΕͰߴ͘ධՁ͍ͯ͠Δ ᷿ͰΑ͘ ޠΒΕΔͷ͸ ͬͪ͜ ઌߦൃදͰத৺తʹޠΒΕ͍ͯΔͷ͸ ͬͪ͜ɻ ࣍ϖʔδ͔Β
  45. Active Record ͷ։ൃੜ࢈ੑ • Rails Active Record ͸ɺ(໊લͷ௨Γ)
 ΞΫςΟϒϨίʔυύλʔϯΛ࣮૷͍ͯ͠Δ •

    ͜ΕʹΑΓɺυϝΠϯϩδοΫΛ
 υϝΠϯϞσϧͷܗͰهड़͢Δ͜ͱ͕Ͱ͖Δ • υϝΠϯϩδοΫ͕ద੾ʹ෼཭͞Εɺ
 ։ൃதظҎ߱ͷߴ͍։ൃੜ࢈ੑΛҡ࣋͠΍͍͢
  46. Active Record ͷ։ൃੜ࢈ੑ • ΋ͪΖΜ Rails Active Record ͸ສೳͰ͸ͳ͍ɻ
 Ή͠ΖҰൠతʹ͸ɺRails

    ΞϓϦέʔγϣϯ͸
 ։ൃதظҎ߱Ͱ։ൃੜ࢈ੑ͕Լ͕Δͱ͍͏ݟํ ΋ڧ͍ • ͜ͷ՝୊ʹରͯ͠ Rails ίϛϡχςΟ͸༷ʑͳղ ܾࡦΛఏ͍ࣔͯ͠Δ • ͦͷܾఆ൛ͷҰͭͱݴ͑Δͷ͕ @_yasaichi ͞Μ ʹΑΔʮRuby on Rails ͷਖ਼ମͱ޲͖߹͍ํʯ https://speakerdeck.com/yasaichi/what-is-ruby-on-rails-and-how-to-deal-with-it
  47. Prisma ͷ։ൃੜ࢈ੑ • Prisma ͸ Rails Active Record ͱ͸ҟͳΓɺ
 υϝΠϯϩδοΫΛهड़͢Δํ๏Λఏڙ͍ͯ͠ͳ͍

    • ͦͷͨΊɺυϝΠϯϞσϧͰ͸ͳ͘
 τϥϯβΫγϣϯεΫϦϓτ (खଓ͖ܕతίʔυ) ͕ॻ͔Ε͕ͪ • => ։ൃதظҎ߱ɺ։ൃੜ࢈ੑͷ௿ԼΛট͘Մೳੑ͋Γ
  48. https://speakerdeck.com/yasaichi/architecture-decision-for-the-next-10-years-at-pixta?slide=53

  49. ࢀߟ: Prisma ଆͰͷݕ౼ঢ়گ https://github.com/prisma/prisma/issues/7161

  50. @qsona ͷݱ৔Ͱ͸໰୊ʹͳ͍ͬͯΔ? • Q. content αʔϏεͷ։ൃ (Prisma Λ࠾༻) ʹ͓͍ͯɺ
 τϥϯβΫγϣϯεΫϦϓτͷංେԽʹΑΔ


    ։ൃੜ࢈ੑͷ௿Լ͸ى͖͍ͯΔ͔?
  51. @qsona ͷݱ৔Ͱ͸໰୊ʹͳ͍ͬͯΔ? • Q. content αʔϏεͷ։ൃ (Prisma Λ࠾༻) ʹ͓͍ͯɺ
 τϥϯβΫγϣϯεΫϦϓτͷංେԽʹΑΔ


    ։ൃੜ࢈ੑͷ௿Լ͸ى͖͍ͯΔ͔? • A. ى͖͍ͯΔ
  52. ίϯςϯπΠϯϙʔτͷίʔυ֓ཁ • େ͖͘ҎԼͷ3ͭͷؔ਺ʹ෼͔Εɺॱʹ࣮ߦ͞ΕΔ • 1. processContents ...
 CSV, YAML Ͱߏ੒͞Εͨ


    ίϯςϯπσʔλΛશͯparse͠ɺ
 1ຕͷ JS Object ʹม׵͢Δ • 2. deleteAllContents ... DB ্ͷίϯςϯπΛશ࡟আ • 3. insertContents ... 1 Ͱ࡞ͬͨσʔλΛ Prisma ܦ༝Ͱ DB ʹ౤ೖ͢Δ ໿ 700 ߦ, ࠷ਂ 4 ॏϧʔϓ͕ग़ݱ͢Δ τϥϯβΫγϣϯεΫϦϓτɻ ίʔυͷೝ஌ෛՙ͕ߴ͍
  53. τϥϯβΫγϣϯεΫϦϓτͷ՝୊ • Ͳ͜ͰԿͷॲཧΛ΍͍ͬͯΔ͔͕ύοͱΘ͔Βͳ͍ • ϧʔϓ͕ଟॏʹͳ͍ͬͯͯɺม਺ͷείʔϓ͕෼͔Γʹ͍͘ • => ίʔυͷೝ஌ෛՙ͕ߴ͘ɺॳݟࡴ͠

  54. ฐνʔϜ಺ͷ Repository ʹͯ 2021-01 ʹ࡞ΒΕͨ issue ͕ͩ 2021-11 ͷஈ֊Ͱ·ͩ Open.

    Read (GraphQL API) ͷςετ͕هड़ ͞ΕΔͳͲɺҰ෦͸վળࡁΈɻ Write ଆ͸ґવτϥϯβΫγϣϯεΫ Ϧϓτͷ··Ͱɺ՝୊͸ೝ͍ࣝͯ͠Δ
  55. Q. ͳͥ͜ͷ໰୊Λղফ͍ͯ͠ͳ͍ͷ͔? • A. ༏ઌ౓͕ͦ͜·Ͱߴ͘ͳ͍͔Β • ཧ༝ (1) ؆୯ͳमਖ਼ͳΒɺ·ͩͦ͜·Ͱ೉͘͠ͳ͍ •

    TypeScript ͷ੩తܕ෇͚͕Α͘ޮ͍͍ͯΔ • த਎ΛΑ͘஌Δ։ൃऀ͕ɺνʔϜ಺ʹෳ਺ਓ͍Δ
  56. Q. ͳͥ͜ͷ໰୊Λղফ͍ͯ͠ͳ͍ͷ͔? • A. ༏ઌ౓͕ͦ͜·Ͱߴ͘ͳ͍͔Β • ཧ༝ (2) ͜ͷίʔυΛେ͖͘मਖ਼ɾ֦ு͢Δ༧ఆ͕ͳ͍ •

    ͋Δେ͖ͳػೳ௥ՃͷλΠϛϯάͰಉ࣌ʹϦϑΝΫλϦϯά ͢Δɺͱ߹ҙ͍͕ͯͨ͠ɺ
 ͦͷػೳ௥Ճ͸Ϗδωεతཧ༝Ͱ༏ઌ౓͕Լ͕͍ͬͯΔ
  57. Q. ͳͥ͜ͷ໰୊Λղফ͍ͯ͠ͳ͍ͷ͔? • ͭ·Γɺద੾ʹʮٕज़తෛ࠴ͷ؅ཧʯ͕ग़དྷ͍ͯΔྑ͍࿩!! ...? • ͕ɺ͍ͣΕղܾ͠ͳ͚Ε͹͍͚ͳ͍ͷ͸มΘΒͳ͍

  58. Ұ୴·ͱΊͱ࿦఺੔ཧ ߴ͍։ൃੜ࢈ੑΛ ͲͷΑ͏ʹಘΔ ։ൃॳظ ։ൃதظҎ߱ Ұൠ࿦ ίʔυྔɾ࡞ۀྔ͕গͳ͘ ໎Θͣॻ͚Δ͜ͱ ن໛͕େ͖͍ίʔυΛ ద੾ʹ෼ׂɾ੔ཧͰ͖Δ͜ͱ

    3BJMT "DUJWF3FDPSE 3BJMT8BZ ઃఆΑΓن໿  "DUJWF3FDPSEʹΑΓ ࣗಈͰϞσϧΛಘΒΕΔ ߴػೳͳ"DUJWF3FDPSEʹΑΓ υϝΠϯϩδοΫΛू໿Ͱ͖Δ ίʔυ੔ཧख๏ͷ஌ݟ͕͋Δ 1SJTNB 1SJTNB4DIFNB͔Β 5ZQF4DSJQUͷ੩తܕ෇͚΍ .JHSBUJPOΛࣗಈͰಘΒΕΔ େ͖ͳखؒͳ͘ɺυϝΠϯϩδοΫΛ ੔ཧ͢Δख๏͕ඞཁ  ࣍ϖʔδ͔Βͷ࿦఺
  59. υϝΠϯϞσϧͷදݱʹ class ͸ඞཁ͔? • Prisma ͸ɺؔ਺ͷೖग़ྗʹ Plain Object Λར༻͢Δ •

    ઌߦൃදΑΓҾ༻:
 "υϝΠϯϨΠϠʔҎԼΛυϝΠϯϞσϧͱ Prisma Ͱߏங͠Α͏ͱ͢Δͱɺ
 Prisma ͷฦ͢ POJO ͷσʔλΛυϝΠϯϞσϧʹ٧Ί௚͢ඞཁ͕͋Δ" • ͜ͷʮυϝΠϯϞσϧʯ͸ class ϕʔεͷ࣮૷͕૝ఆ͞Ε͍ͯΔͱࢥΘΕΔ • ٙ໰: υϝΠϯϞσϧͷදݱ͸ class Ͱͳ͍ͱग़དྷͳ͍ͩΖ͏͔? • (ࢲݸਓͷײ֮Ͱ͸ JS/TS ։ൃऀ͸ class Λ͋·Γଟ͘࢖Θͳ͍܏޲)
  60. https://twitter.com/_yasaichi/status/1459394817125875717 https://keens.github.io/blog/2021/01/04/future_of_proguramming_languages/

  61. https://twitter.com/a_suenami/status/1453293119760486408

  62. class ͕ఏڙ͢Δศར͞ • σʔλʹؔ͢Δϝιου܈͕ू·Γɺڽू౓͕ߴ͍ঢ়ଶ • obj.method() ͷه๏ (IDE Ͱͷิ׬͕ޮ͘) •

    ΦϒδΣΫτͷ಺෦ঢ়ଶͷߋ৽ • ଟଶੑ (Polymorphism)
  63. class Λ࢖ͬͨυϝΠϯϞσϧ Prisma ͷσʔλܕͱಉ͡ܕએݴͱ ͔ͦ͜Β٧Ίସ͑ΔͨΊͷίʔυɻ ຖ౓खಈͰ͜ͷΫϥεΛॻ͍ͨΓɺ ͜ͷΫϥεʹ٧Ίସ͑ͨΓ͢ΔίʔυΛॻ ͘ͷ͸ͱͯ΋໘౗͍͘͞ υϝΠϯϩδοΫͷίʔυɻ ҰͭͷϑΝΠϧʹ·ͱ·͍ͬͯͯ

    ڽू౓͕ߴ͍
  64. ؔ਺܈ͷϑΝΠϧΛ࢖ͬͨυϝΠϯϞσϧ Immutable ύλʔϯΛར༻ Pick (Utility Types) Λར༻ɻ ςʔϒϧͷશΧϥϜΛऔಘ͠ͳͯ͘΋͢Ή఺Ͱ class ϕʔεͷυϝΠϯϞσϧΑΓ༗ར

    Ҿ਺ / ໭Γ஋ ʹ User ΛऔΔؔ਺܈Λ 1ຕͷϑΝΠϧʹ·ͱΊ͍ͯΔ
  65. class ͕ఏڙ͢Δศར͞ • σʔλʹؔ͢Δϝιου܈͕ू·Γɺڽू౓͕ߴ͍ঢ়ଶ
 => ͦͷσʔλʹؔ࿈͢Δؔ਺Λ1ϑΝΠϧʹ·ͱΊΔ͜ͱͰ୅ସՄೳ • obj.method() ͷه๏ =>

    method(obj) Ͱ(ҰԠ)୅ସՄೳ • ΦϒδΣΫτͷ಺෦ঢ়ଶͷߋ৽
 => newObj = method(obj) (Immutable ύλʔϯ) Ͱ(ҰԠ)୅ସՄೳ • ଟଶੑ (Polymorphism) => ???
  66. ଟଶੑ (Polymorphism) • ࢲݟ: ଟଶੑ͕΄͍͠ͱ͖͚ͩ͸ class Λ࢖͏ͷ͕ྑ͍ͱࢥ͏

  67. ଟଶੑ (Polymorphism) • Rails Active Record ʹ͓͍ͯ͸ɺ
 STI (Single Table

    Inheritance) ͱ Polymorphic Association ͷ2ͭͰ Polymorphism ͕αϙʔτ͞Ε͍ͯΔ • ͕ɺ͜ΕΒ͸ςʔϒϧઃܭʹ(͠͹͠͹ѱ͍)ӨڹΛٴ΅͢ͷͰɺ
 த௕ظͷ։ൃੜ࢈ੑΛߴΊΔҙຯͰ͸ਪ঑͞Εͳ͍ • ಛʹ Polymorphic Association ͸
 SQL Ξϯνύλʔϯʹ΋ܝࡌ͞Ε͍ͯΔ • ͕ͨͬͯ͠ɺPolymorphism ͕ཉ͍͠ͱ͖͸ (Rails Ͱ͋ͬͯ΋)
 Active Record Ͱ͸ͳ͍ಠࣗͷΫϥεΛ࡞੒͢Δ͜ͱ͕ଟ͍ • ͭ·ΓɺActive Record ͱͷൺֱͰ͍͑͹ɺͲͪΒ͕༗རͱ͍͏͜ͱ͸ͳ͍
  68. @qsona ͷݱ৔ͷίʔυͷվળख๏ • ͱΓ͋͑ͣ Composed Method ύλʔϯͰ
 ڊେͳτϥϯβΫγϣϯεΫϦϓτΛখ෼͚ʹ͍ͯ͘͠ • গͣͭ͠༗༻ͳυϝΠϯϞσϧΛݟग़͍ͯ͘͠

    • ࣮ࡍ೉͍͠ (ςʔϒϧ୯Ґͱ͸ݶΒͳ͍) • Polymorphism ͕ඞཁͳΒΫϥεΛ࢖͏! • (Ұ෦Λ࣍ϖʔδ͔Β঺հ)
  69. processContentData ͷதͰɺ ໰୊ (Question) Λ processing ͢Δ෦෼ɻ ॲཧͷதͰ΋ಛʹෳࡶͳͷͰɺ parseQuestion ؔ਺ͱͯ͠෼཭͞Ε͍ͯΔ

  70. parseQuestion ͷதͰ͸ɺ
 ΫϥεϕʔεͷϞσϦϯάΛߦͳ͍ͬͯΔɻ Question ͷछྨ͝ͱʹॲཧΛม͑Δ 
 Polymorphism Λར༻͍ͨͨ͠Ίɻ ೖྗଆͷσʔλߏ଄ͰΫϥεΛ࡞͍ͬͯΔͷͰɺ Active

    Record ύλʔϯ͔Β͸͜ͷઃܭ͸ಋग़͞ Εͳ͍
  71. (·ͱΊ) ఏҊ: ؔ਺Λ࢖͏ɺclass Λͨ·ʹ࢖͏ • ؔ਺ͱɺؔ਺Λ·ͱΊͨϑΝΠϧΛ࡞Δ • ૯߹తʹ TypeScript ͱͷ૬ੑ͕ྑ͍

    • ඞཁʹԠͯ͡ class Λ࡞Δ • యܕతʹ͸ Polymorphism ͕΄͍͠ͱ͖ Structural Typing Ͱ͋Δ͜ͱ Plain Object ͕ୈ1ڃͰ͋Δ͜ͱ
  72. ຊൃදͷ·ͱΊ

  73. ຊൃදʹ͓͚Δओு ҎԼͷٕज़ɾΞʔΩςΫνϟͷ૊Έ߹ΘͤʹΑΓ
 ։ൃॳظ / ։ൃதظҎ߱ ྆ํͰͷߴ͍։ൃੜ࢈ੑΛ୲อͰ͖ΔͷͰ͸ͳ͍͔? • ٕज़: GraphQL +

    Prisma (on Node.js, TypeScript) • ΞʔΩςΫνϟ: • CQS (Command-Query Separation) Pattern ͷ࠾༻Λݕ౼͢Δ • σʔλʹରԠ͢Δؔ਺܈ͱͯ͠ɺυϝΠϯϩδοΫΛ·ͱΊΔ • Polymorphism ͕ඞཁͳہ໘Ͱ͸ɺΫϥεΛར༻͢Δ
  74. ·ͱΊ: ຊൃදʹ͓͚Δओு • ͱ͸͍͑ɺߟ࡯͕·ͩෆे෼ͳ఺͸ଟ͍ • Έͳ͞Μ΋ʮຊ౰͔...?ʯͱࢥͬͨՕॴ͕
 ͖ͬͱ͍ͭ͘΋͋ͬͨͱࢥ͍·͢ • Prisma Λ࢖ͬͨத௕ظͷ։ൃࣄྫ͕૿͍͑ͯͬͯ


    ΞʔΩςΫνϟతͳ஌ݟΛڞ༗͠߹͑Δͱྑ͍ͱࢥ͏ • ΈΜͳ Prisma ࢖͓͏ͥ!!
  75. ৮ΕΒΕͳ͔ͬͨ࿩ • Prisma ͷʮ։ൃલظʯͷ։ൃੜ࢈ੑʹ͍ͭͯ...
 ࣗಈςετपล͕՝୊ • Prisma + Jest Λར༻͍ͯ͠Δ͕


    Rails + RSpec + Factory Bot ͷମݧʹ௥͍͚ͭͯͳ͍ https://zenn.dev/seya/articles/a0d2d2da20ddad https://twitter.com/sekikazu01/status/1463743468073746435
  76. ँࣙ • ࠓճͷςʔϚʹ͍ͭͯߟ͑Δ͖͔͚ͬΛ࡞ͬͯͩͬͨ͘͞
 @_yasaichi ͞Μɺ͓Αͼ
 ೔ʑલ޲͖ʹίʔυվળͷٞ࿦ʹ෇͖߹ͬͯ͘ΕΔ
 ελσΟαϓϦͷ։ൃνʔϜͷ஥ؒʹײँ͍ͯ͠·͢