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

GraphQL と Prisma から考える次のN年を見据えた技術選定 / Architect...

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)

qsona

November 27, 2021
Tweet

More Decks by qsona

Other Decks in Technology

Transcript

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

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


    Ξϯαʔൃද (?) Ͱ͢ https://speakerdeck.com/yasaichi/architecture-decision-for-the-next-10-years-at-pixta
  3. ઌߦൃදʹ͓͚Δٕज़બఆࣄྫ • @_yasaichi ͞Μͷॴଐ͢Δ૊৫Ͱ͸ɺ΋ͱ΋ͱ Ruby on Rails Λ׆༻͓ͯ͠ Γɺಛʹ Active

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

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


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

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

    Prisma ࠾༻ࣄྫͱ ٕज़બఆͷཧ༝ • ୈೋ෦: Active Record ͱରൺͯ͠ߟ͑Δ
 Prisma ͱ։ൃதظҎ߱ͷ։ൃੜ࢈ੑ
  8. Prisma ͱ͸ • Database toolkit (O/R Mapper ΛؚΉ) • Node.js

    + TypeScript ͕લఏ • PostgreSQL, MySQL, MongoDB ͳͲʹରԠ • ͜ͷൃදͷείʔϓͰ͸ PostgreSQL / MySQL Λ૝ఆ
  9. Prisma Λར༻ͨ͠։ൃϑϩʔ • Prisma schema ͔ΒҎԼͷ2͕ͭࣗಈੜ੒͞ΕΔ • DB ϚΠάϨʔγϣϯͷίʔυ (Prisma

    Migrate) • ΫΤϦϏϧμʔ (ORM) ͷίʔυ (Prisma Client) Rails Ϣʔβʔ޲͚৘ใ: ridgepole (cookpad) ͱಉ͡։ൃϑϩʔ
  10. Prisma Λར༻ͨ͠։ൃମݧ ࢲݟ: ։ൃମݧ͕ඇৗʹྑ͍ • Prisma schema Λத৺ͱͨ͠ɺҰ؏ͨ͠։ൃମݧ • ࠩ෼

    Migration ·ͰΧόʔͯ͘͠ΕΔ • TypeScript ͷ੩తܕ͕όνόνʹޮ͘ • ࢖ͬͯΈΕ͹Θ͔Γ·͢ʂʂʂʂ (౤͛΍Γ)
  11. ৽ن։ൃϓϩδΣΫτͷ঺հ • ελσΟαϓϦͷ͏ͪɺதֶੜͷϢʔβʔΛର৅ʹ
 αʔϏεΛϦχϡʔΞϧ͢ΔϓϩδΣΫτ • ։ൃ͢Δ΋ͷ • iOS / Android

    / PC Web Apps • Backend APIs • ίϯςϯπΛ؅ཧ͢ΔγεςϜ ֶशαʔϏεΛϑϧεΫϥονͰ ࡞ΔΠϝʔδ
  12. ͦΕͧΕͷαʔϏεͷ੹຿ • content αʔϏε (ࠓճͷ࿩ͷϝΠϯ) • ֶशʹඞཁͳʮίϯςϯπʯΛ؅ཧ͢Δ੹຿Λ࣋ͭ • ໰୊ /

    ಈը / ͦΕΒͷ֊૚ߏ଄ ͳͲ • main αʔϏε • Ϣʔβʔͷֶशཤྺͷσʔλ΍ɺͦͷଞ
 ϢʔβʔσʔλΛ؅ཧ͢Δ੹຿Λ࣋ͭ • Ruby on Rails Λ࠾༻
  13. content αʔϏεͷٕज़બఆཧ༝ • νʔϜͷೳྗɾΦʔφʔγοϓ • GraphQL (ΤίγεςϜؚΉ) ͱͷ૬ੑ • ੩తܕ෇͚

    (ΤίγεςϜؚΉ) ͱͷ૬ੑ • Read ͱ Write Ͱେผ͞ΕΔ
 αʔϏεಛੑͱͷ૬ੑ TypeScript + Node.js Λબ୒ͨ͠ ੵۃతཧ༝ Rails ActiveRecord Λආ͚Δ ফۃతཧ༝͕ͩ ͜ͷൃදʹ͓͚Δຊ୊
  14. νʔϜͷೳྗɾΦʔφʔγοϓ ҎԼͷཧ༝Ͱɺ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 ͱͷൺֱͰߟ͑Δ)
  15. GraphQL (ΤίγεςϜؚΉ) ͱͷ૬ੑ • Ruby Ͱ΋໰୊ͳ͘ GraphQL Server Λ࣮૷Ͱ͖Δ •

    ڧ͍ͯݴ͏ͳΒ͹ TypeScript + Node.js ͷ΄͏͕ɺ
 ΑΓ GraphQL ͱ਌࿨ੑ͕ߴ͍ • ฒߦॲཧͱͷ૬ੑ͕ྑ͍ • JavaScript / TypeScript + GraphQL ͷํ͕ɺ
 ΤίγεςϜ͕੝Γ্͕͍ͬͯΔ
  16. ੩తܕ෇͚ (ΤίγεςϜؚΉ) ͱͷ૬ੑ αʔϏεͷಛੑ͔Βɺ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
  17. Read ͱ Write Ͱେผ͞ΕΔ
 αʔϏεಛੑͱͷ૬ੑ αʔϏεͷಛ௃ͱͯ͠ɺWrite ͱ Read ͷ܏޲͕શ͘ҟͳΔ •

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

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

    Pattern Λద༻Ͱ͖Δͱߟ͑ͨ • Command (ॻ͖ࠐΈܥ) ͱ 
 Query (ಡΈࠐΈܥ) ʹ
 γεςϜ্ͷίʔυΛେผ͢Δύλʔϯ τϥϑΟοΫ υϝΠϯ
 ϩδοΫ 3FBE େ গ 8SJUF ۃখ ଟ
  20. CQS Pattern ͱ ActiveRecord • ࢲݟ: CQS Pattern ͱ Rails

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

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

    GraphQL + Prisma + CQS Pattern ͷ
 ૊Έ߹Θͤʹେ͖ͳظ଴Λ๊͍͍ͯΔ͕ɺ
 ࣗ਎ͷྗྔෆ଍ʹΑΓɺຊൃදͰ͸े෼આ໌Ͱ͖͍ͯͳ͍ • ୅ΘΓʹ (?) ࢀߟࢿྉͱͯ͠
 ҒେͳهࣄΛ঺հ͠·͢ Smart UI ύλʔϯ͕࠶ධՁ͞ΕΔੈք (@onk) https://onk.hatenablog.jp/entry/2020/11/11/024531
  23. Active Record ͷ։ൃੜ࢈ੑ • ઌߦൃදͰ͸ɺ
 Ruby on Rails ͷ Active

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

    ͜ΕʹΑΓɺυϝΠϯϩδοΫΛ
 υϝΠϯϞσϧͷܗͰهड़͢Δ͜ͱ͕Ͱ͖Δ • υϝΠϯϩδοΫ͕ద੾ʹ෼཭͞Εɺ
 ։ൃதظҎ߱ͷߴ͍։ൃੜ࢈ੑΛҡ࣋͠΍͍͢
  25. 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
  26. Prisma ͷ։ൃੜ࢈ੑ • Prisma ͸ Rails Active Record ͱ͸ҟͳΓɺ
 υϝΠϯϩδοΫΛهड़͢Δํ๏Λఏڙ͍ͯ͠ͳ͍

    • ͦͷͨΊɺυϝΠϯϞσϧͰ͸ͳ͘
 τϥϯβΫγϣϯεΫϦϓτ (खଓ͖ܕతίʔυ) ͕ॻ͔Ε͕ͪ • => ։ൃதظҎ߱ɺ։ൃੜ࢈ੑͷ௿ԼΛট͘Մೳੑ͋Γ
  27. ίϯςϯπΠϯϙʔτͷίʔυ֓ཁ • େ͖͘ҎԼͷ3ͭͷؔ਺ʹ෼͔Εɺॱʹ࣮ߦ͞ΕΔ • 1. processContents ...
 CSV, YAML Ͱߏ੒͞Εͨ


    ίϯςϯπσʔλΛશͯparse͠ɺ
 1ຕͷ JS Object ʹม׵͢Δ • 2. deleteAllContents ... DB ্ͷίϯςϯπΛશ࡟আ • 3. insertContents ... 1 Ͱ࡞ͬͨσʔλΛ Prisma ܦ༝Ͱ DB ʹ౤ೖ͢Δ ໿ 700 ߦ, ࠷ਂ 4 ॏϧʔϓ͕ग़ݱ͢Δ τϥϯβΫγϣϯεΫϦϓτɻ ίʔυͷೝ஌ෛՙ͕ߴ͍
  28. ฐνʔϜ಺ͷ Repository ʹͯ 2021-01 ʹ࡞ΒΕͨ issue ͕ͩ 2021-11 ͷஈ֊Ͱ·ͩ Open.

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

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

    ͋Δେ͖ͳػೳ௥ՃͷλΠϛϯάͰಉ࣌ʹϦϑΝΫλϦϯά ͢Δɺͱ߹ҙ͍͕ͯͨ͠ɺ
 ͦͷػೳ௥Ճ͸Ϗδωεతཧ༝Ͱ༏ઌ౓͕Լ͕͍ͬͯΔ
  31. Ұ୴·ͱΊͱ࿦఺੔ཧ ߴ͍։ൃੜ࢈ੑΛ ͲͷΑ͏ʹಘΔ ։ൃॳظ ։ൃதظҎ߱ Ұൠ࿦ ίʔυྔɾ࡞ۀྔ͕গͳ͘ ໎Θͣॻ͚Δ͜ͱ ن໛͕େ͖͍ίʔυΛ ద੾ʹ෼ׂɾ੔ཧͰ͖Δ͜ͱ

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

    ઌߦൃදΑΓҾ༻:
 "υϝΠϯϨΠϠʔҎԼΛυϝΠϯϞσϧͱ Prisma Ͱߏங͠Α͏ͱ͢Δͱɺ
 Prisma ͷฦ͢ POJO ͷσʔλΛυϝΠϯϞσϧʹ٧Ί௚͢ඞཁ͕͋Δ" • ͜ͷʮυϝΠϯϞσϧʯ͸ class ϕʔεͷ࣮૷͕૝ఆ͞Ε͍ͯΔͱࢥΘΕΔ • ٙ໰: υϝΠϯϞσϧͷදݱ͸ class Ͱͳ͍ͱग़དྷͳ͍ͩΖ͏͔? • (ࢲݸਓͷײ֮Ͱ͸ JS/TS ։ൃऀ͸ class Λ͋·Γଟ͘࢖Θͳ͍܏޲)
  33. class ͕ఏڙ͢Δศར͞ • σʔλʹؔ͢Δϝιου܈͕ू·Γɺڽू౓͕ߴ͍ঢ়ଶ
 => ͦͷσʔλʹؔ࿈͢Δؔ਺Λ1ϑΝΠϧʹ·ͱΊΔ͜ͱͰ୅ସՄೳ • obj.method() ͷه๏ =>

    method(obj) Ͱ(ҰԠ)୅ସՄೳ • ΦϒδΣΫτͷ಺෦ঢ়ଶͷߋ৽
 => newObj = method(obj) (Immutable ύλʔϯ) Ͱ(ҰԠ)୅ସՄೳ • ଟଶੑ (Polymorphism) => ???
  34. ଟଶੑ (Polymorphism) • Rails Active Record ʹ͓͍ͯ͸ɺ
 STI (Single Table

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

    • ࣮ࡍ೉͍͠ (ςʔϒϧ୯Ґͱ͸ݶΒͳ͍) • Polymorphism ͕ඞཁͳΒΫϥεΛ࢖͏! • (Ұ෦Λ࣍ϖʔδ͔Β঺հ)
  36. (·ͱΊ) ఏҊ: ؔ਺Λ࢖͏ɺclass Λͨ·ʹ࢖͏ • ؔ਺ͱɺؔ਺Λ·ͱΊͨϑΝΠϧΛ࡞Δ • ૯߹తʹ TypeScript ͱͷ૬ੑ͕ྑ͍

    • ඞཁʹԠͯ͡ class Λ࡞Δ • యܕతʹ͸ Polymorphism ͕΄͍͠ͱ͖ Structural Typing Ͱ͋Δ͜ͱ Plain Object ͕ୈ1ڃͰ͋Δ͜ͱ
  37. ຊൃදʹ͓͚Δओு ҎԼͷٕज़ɾΞʔΩςΫνϟͷ૊Έ߹ΘͤʹΑΓ
 ։ൃॳظ / ։ൃதظҎ߱ ྆ํͰͷߴ͍։ൃੜ࢈ੑΛ୲อͰ͖ΔͷͰ͸ͳ͍͔? • ٕज़: GraphQL +

    Prisma (on Node.js, TypeScript) • ΞʔΩςΫνϟ: • CQS (Command-Query Separation) Pattern ͷ࠾༻Λݕ౼͢Δ • σʔλʹରԠ͢Δؔ਺܈ͱͯ͠ɺυϝΠϯϩδοΫΛ·ͱΊΔ • Polymorphism ͕ඞཁͳہ໘Ͱ͸ɺΫϥεΛར༻͢Δ
  38. ৮ΕΒΕͳ͔ͬͨ࿩ • Prisma ͷʮ։ൃલظʯͷ։ൃੜ࢈ੑʹ͍ͭͯ...
 ࣗಈςετपล͕՝୊ • Prisma + Jest Λར༻͍ͯ͠Δ͕


    Rails + RSpec + Factory Bot ͷମݧʹ௥͍͚ͭͯͳ͍ https://zenn.dev/seya/articles/a0d2d2da20ddad https://twitter.com/sekikazu01/status/1463743468073746435