$30 off During Our Annual Pro Sale. View Details »

GraphQLの誤解/rethinking-graphql

 GraphQLの誤解/rethinking-graphql

GraphQL実践ノウハウ
https://speakerdeck.com/sonatard/graphql-knowhow

GraphQL実践ノウハウv2
https://speakerdeck.com/sonatard/graphql-knowhow-v2

宣言的UIの状態管理とアーキテクチャSwiftUIとGraphQLによる実践
https://speakerdeck.com/sonatard/swiftui-graphql

sonatard

March 03, 2022
Tweet

More Decks by sonatard

Other Decks in Programming

Transcript

  1. 8 (SBIQ2-ͷޡղ w 3&45"1* w VTFS w JE w OBNFZBNBEB

    w PSEFS@JE w PSEFS w JE w QSPEVDU@JE w VTFS@JE w QSPEVDU w JE w /BNFۺ query UserOrder { user { id name order { id product { id name } } } } w (SBQI2- 3&45ͱ(SBQI2-ͷҧ͍͸Կ͔ʁ type User { id: ID! name: String! order: Order! } type Order { id: ID! product: Product! } type Product { id: ID! name: String! }
  2. (SBIQ2-ͷޡղ w (SBQI2-͸3&45ͱൺֱͯ͠ଟ͘ͷ৘ใΛऔಘͰ͖Δʁ w /PɹεΩʔϚʹهࡌ͞Εͨ৘ใҎ্͸औಘͰ͖ͳ͍ w 3&45Ͱ΋(SBQI2-Ͱ΋ଟ͘ͷ஋ΛऔಘՄೳͳ"1*ʹ͢Ε͹औ ಘͰ͖Δ͠ɺͦ͏Ͱͳ͚Ε͹औಘͰ͖ͳ͍ w (SBQI2-͸ɺ%#ͷ2VFSZͷ੹຿ΛΫϥΠΞϯτ͕͍࣋ͬͯΔʁ

    w /PεΩʔϚͰެ։͞ΕͨൣғͰ͔͠ΫΤϦʔͰ͖ͳ͍ w 3&45ͱಉ౳ͷεΩʔϚͰ͋Ε͹ɺͰ͖Δ͜ͱ͸ಉ͡ w ͭ·Γෳ਺ճ"1*Λ࣮ߦ͢Δ͔ɺ౓2VFSZΛ౤͛Δ͔ͷҧ͍͔͠ ͳ͍ type User { id: ID! name: String! order: Order! } type Order { id: ID! product: Product! } type Product { id: ID! name: String! } 9
  3. 10 (SBIQ2-ͷޡղ w "1*ͷ৘ใྔ͕ಉ͡ͳΒ͹ɺ(SBQI2-͸3&45ͷ "1*ΛͰϚοϐϯά͚ͨͩ͠ͷ΋ͷ w ͦ͜ʹ(SBQIߏ଄ͱ͍͏ಛ௃ʹΑΓɺϦϨʔγϣ ϯ͕͋Δ΋ͷΛ౓ͷΫΤϦʔͰऔಘՄೳʹͳͬ ͍ͯΔ w

    3&45ͳΒෳ਺ճ"1*Λ࣮ߦ͢Δ͜ͱͰಉ౳ͷ ͜ͱ͕࣮ݱͰ͖Δ query UserOrder { user { id name order { id product { id name } } } } w 3&45"1* w VTFS w JE w OBNFZBNBEB w PSEFS@JE w PSEFS w JE w QSPEVDU@JE w VTFS@JE w QSPEVDU w JE w /BNFۺ VTFS PSEFS QSPEVDU ରԠ
  4. 11 (SBIQ2-ͷޡղ w ΫϥΠΞϯταΠυͷݡ͞͸૿͑ͯͳ͍ w Ή͠ΖٯͰɺΫϥΠΞϯταΠυ͕͍࣋ͬͯͨ"1*Λ૊ΈཱͯΔ੹຿͕όοΫΤϯυʹҕৡ͞Ε͍ͯΔ %# %# %#ͷ 2VFSZͷ੹຿

    %#ͷ 2VFSZͷ੹຿ "1*Λ ૊ΈཱͯΔ੹຿ "1*Λ ૊ΈཱͯΔ੹຿ VTFS"1*Λ࣮ߦͯ͠ϨεϙϯεͷPSEFS@JEΛऔಘͯ͠ɺ PSEFSPSEFS@JE"1*Λ࣮ߦͯ͠ϨεϙϯεͷQSPEVDU@JEͰ QSPEVDUQSPEVDU@JE"1*Λ࣮ߦ͢Δ query UserOrder { user { id name order { id product { id name } } } } 2VFSZΛ౤͛Δ JEͷVTFSΛ%#͔ΒҾ͍ͯPSEFS@JEΛऔಘͯ͠ɺ JEPSEFS@JEͷPSEFSΛ%#͔ΒҾ͍ͯQSPEVDU@JEΛऔಘͯ͠ɺ *EQSPEVDU@JEͷQSPEVDUΛ%#͔Βऔಘ͢Δ ཉ͍͠৘ใΛૉ௚ʹهड़
  5. 12 (SBIQ2-ͷޡղ w 3&45Ͱ΋ΫϥΠΞϯτʹґଘͨ͠"1*Λ༻ҙ͢Δ͜ͱͰɺΫϥΠΞϯταΠυ͔Β͸ಉ౳ͷମݧΛ ಘΒΕΔ͕ɺҎԼͷΑ͏ͳ໰୊͕͋Δ %# %#ͷ 2VFSZͷ੹຿ "1*Λ ૊ΈཱͯΔ੹຿

    ը໘ઐ༻ͷ"1*Λ࣮ߦ͢Δ ΫϥΠΞϯτͷϢʔεέʔεʹԠͨ͡"1*Λ૊ΈཱͯΔίετ͕ߴ͍ ·ͨΫϥΠΞϯτͷϢʔεέʔεʹԠͯ͡"1*ͷ࣮૷ͷมߋ͕ඞཁʹͳΔ (SBQI2-ͳΒϑϨʔϜϫʔΫ͕ղܾͯ͘͠ΕΔ
  6. w ޡղ͞Ε΍͍͢ཧ༝ w ͔͜͠͠Ε͸(SBQI2-ͷ໰୊Ͱ͸ͳ͘ɺ)BTVSBͷ࢓૊ΈͰ͢ w ·ͨ)BTVSBͰ3&45"1*ΛఏڙՄೳͰ͋ΔͨΊɺ)BTVSBͷྫΛڍ͛ͯεϚʔτ6*ʹͳΔͱݴͬͯ ͠·͏ͱɺ3&45΋ಉ͘͡εϚʔτ6*ʹͳͬͯ͠·͏ w ஫ҙ w

    )BTVSBΛ൱ఆ͍ͯ͠ΔΘ͚Ͱ͸͋Γ·ͤΜ w )BTVSBͷྫ͔Β(SBQI2-Λޡղ͢Δ͜ͱͷ໰୊ఏىΛ͍ͯ͠·͢ w )BTVSB͸దͨ͠ϢʔεέʔεͰ࢖͑͹ૉ੖Β͍͠πʔϧͰ͢ 14 (SBIQ2-ͷޡղ %# %#͔Βࣗಈੜ੒
  7. 15 (SBIQ2-ͷޡղ w ޡղ·ͱΊ w ʮ(SBQI2-͸ɺ3&45ͱൺֱͯ͠%#ͷΫΤϦʔͷ੹຿ΛΫϥΠΞϯτ͕͔࣋ͭΒεϚʔτ6*ʹͳΔʯΘ ͚Ͱ͸ͳ͍ %# %#ͷ 2VFSZͷ੹຿

    "1*Λ ૊ΈཱͯΔ੹຿ query UserOrder { user { id name order { id product { id name } } } } Ϣʔεέʔεݻ༗ͷ"1*࣮૷͸ෆཁͰɺ ΫϥΠΞϯτ͕ΫΤϦʔΛॻ͘͜ͱͰ ରԠՄೳ (SBQI2-͕ޮ཰తʹ"1*Λ ૊ΈཱͯΔ੹຿Λ୲ͬͯ͘ΕΔ (SBQI2-ͷ࢓༷ͱϑϨʔϜϫʔΫΛ αʔόͷલ໘ʹڬΉ͜ͱͰޮ཰తʹ ࣮૷Ͱ͖Δ
  8. 19 (SBIQ2-ͷޡղ w 3&45"1* w VTFS w JE w /BNFZBNBEB

    w BHFࡀ w JT"EVMUUSVF w VTFS w JE w OBNFUBOBLB w BHFࡀ w JT"EVMUGBMTF w ٯʹ(SBQI2-͸3&45Ҏ্ʹϏδωεϩδοΫΛόοΫΤϯυʹҕৡ͠΍͍͢΋ͷͰ͢ɻ w ྫ͑͹ɺVTFS͕੒ਓ͔Ͳ͏͔൑ఆ͢ΔϩδοΫ͕͋Δͱ͠·͢ɻ w ͜ͷͱ͖΋͠BHFΛݩʹΫϥΠΞϯταΠυͰϩδοΫΛॻ ͍ͯ͠·͏ͱɺϏδωεϩδοΫ͕࿙Εग़ͯ͠͠·͍·͢ɻ w ୅ΘΓʹVTFSʹJT"EVMUϑΟʔϧυΛ௥Ճͯ͠ɺϨεϙϯεΛ ฦ͢ͱ͖ʹ൑ఆ݁ՌΛؚΊͯฦ͢ͱ͠·͢ɻ w ͜ΕͰద੾ʹϏδωεϩδοΫ͸όοΫΤϯυʹҠΓ·ͨ͠ w ͔͠͠ϑϩϯτΤϯυͷը໘ʹΑͬͯ͸ɺ໊લ͔͠ඞཁͳ͍ Մೳੑ͕͋Γ·͢ɻ w ͦͷ৔߹ɺJT"EVMUͷܭࢉ͸༨ܭͳ$16ϦιʔεΛফඅ͢Δ ͜ͱʹͳΓ·͢ɻ w JT"EVMUͷܭࢉ͘Β͍ͳΒޡࠩͰ͕͢ɺ͜ͷϩδοΫͷͨΊʹ ผͷ.JDSPTFSWJDFT΍֎෦ͷ"1*͔Βऔಘ͢Δ৔߹ʹ͸ɺ໊લ Λදࣔ͢Δͨͼʹॏ͍ॲཧ͕૸Δ͜ͱʹͳΓ·͢ɻ
  9. 20 (SBIQ2-ͷޡղ query UserName { user { id name }

    } query UserAge { user { id age isAdult } } w ໊લΛදࣔ͢ΔΫΤϦʔ w ೥ྸΛදࣔ͢ΔΫΤϦʔ JT"EVMUϑΟʔϧυΛऔಘ͠ͳ͚Ε͹ɺ ॏ͍ॲཧ͕࣮ߦ͞Εͳ͍ JT"EVMU͕ඞཁͳͱ͖͚ͩऔಘ͢Δ type User { id: ID! name: String! age: Int! isAdult: Boolean! } w (SBQI2-εΩʔϚ ύϑΥʔϚϯεͷӨڹ͕ग़ͳ͍ͨΊ 6TFSʹJT"EVMUϑΟʔϧυΛ௥Ճ͢Δ͜ ͱ͕༰қʹͳΔ ·ͨJT"EVMUઐ༻ͷϋϯυϥ͕ੜ੒Ͱ͖ ΔͨΊɺطଘͷ6TFSΛҾ࣮͘૷΁ͷ Өڹ΋ͳ͍
  10. 21 (SBIQ2-ͷޡղ w ޡղ·ͱΊ w ʮ(SBQI2-͸ɺυϝΠϯ΍ϏδωεϩδοΫ͕ΫϥΠΞϯτʹ࿙Εग़͢ʯΘ͚Ͱ͸ͳ͍ ϏδωεϩδοΫ͸3&45ͱ มΘΒͣόοΫΤϯυ͕࣋ͭ %# %#ͷ

    2VFSZͷ੹຿ "1*Λ ૊ΈཱͯΔ੹຿ query UserOrder { user { id name order { id product { id name } } } } 2VFSZΛ౤͛Δ ϏδωεϩδοΫ ͦͯ͠(SBQI2-ʹΑΓόοΫΤϯυ͕ ϩδοΫΛ࣋ͪ΍͍͢࢓૊Έʹ ͳ͍ͬͯΔ
  11. 27 ΫϥΠΞϯτͷ੹຿ͷݮগ w (SBQI2-Ͱ͸ɺ"QPMMP΍3FMBZͳͲͷ(SBQI2-ΫϥΠΞϯτ͕(SBQIߏ଄ͦͷ··ʹΩϟογϡ͢Δ࢓૊Έ Λ͍࣋ͬͯ·͢ɻ w ͦͷͨΊϨεϙϯε͔Βͷม׵ॲཧ΍ΩϟογϡͷϩδοΫ͸ॻ͘ඞཁ͕͋Γ·ͤΜɻ %# query UserOrder

    { user { id name order { id product { id name } } } } Ϩεϙϯε 7JFX.PEFM 7JFX.PEFMΛ Ωϟογϡ͢ΔϩδοΫ ϨεϙϯεΛΩϟογϡ Ωϟογϡώοτ͢Ε͹ ϦΫΤετΛ౤͛ͳ͍ (SBQI2- ΫϥΠΞϯτ
  12. 30 ·ͱΊ w ޡղͨ͠(SBQI2- w ʮ(SBQI2-͸ɺ3&45ͱൺֱͯ͠%#ͷΫΤϦʔͷ੹຿ΛΫϥΠΞϯτ͕͔࣋ͭΒεϚʔτ6*ʹͳΔʯ w ʮ(SBQI2-͸ɺυϝΠϯ΍ϏδωεϩδοΫ͕ΫϥΠΞϯτʹ࿙Εग़͢ʯ %#ͷ 2VFSZͷ੹຿

    "1*Λ ૊ΈཱͯΔ੹຿ ϏδωεϩδοΫ %# Ϩεϙϯε͔Β 7JFX.PEFMʹ ม׵͢ΔϩδοΫ 7JFX.PEFMΛ Ωϟογϡ͢ΔϩδοΫ %# ϨεϙϯεΛ.PEFMʹม׵ͯ͠ Ωϟογϡ͢ΔϩδοΫ Ϩεϙϯε "1*Λ ૊ΈཱͯΔ੹຿ %#ͷ 2VFSZͷ੹຿ ϏδωεϩδοΫ .PEFM͔Β 7JFX.PEFMʹ ม׵͢ΔϩδοΫ
  13. 31 ·ͱΊ w ద੾ͳ࢖͍ํΛͨ͠(SBQI2- w (SBQI2-͸3&45ͱൺֱͯ͠ଟ͘ͷ੹຿Λݞ୅ΘΓͯ͘͠ΕΔ w ΫϥΠΞϯταΠυͷίʔυ͸γϯϓϧͰ࠷খݶͷ࣮૷ʹͳΔ %#ͷ 2VFSZͷ੹຿

    "1*Λ ૊ΈཱͯΔ੹຿ ϏδωεϩδοΫ 7JFX.PEFMΛ Ωϟογϡ͢ΔϩδοΫ %# ΫϥΠΞϯτ͸ ࠷খݶͷ࣮૷ 7JFX.PEFMΛฦ͢ ϩδοΫ %# ϨεϙϯεΛ.PEFMʹม׵ͯ͠ Ωϟογϡ͢ΔϩδοΫ Ϩεϙϯε "1*Λ ૊ΈཱͯΔ੹຿ %#ͷ 2VFSZͷ੹຿ ϏδωεϩδοΫ .PEFM͔Β 7JFX.PEFMʹ ม׵͢ΔϩδοΫ