Hasuraを活用するためのTips集
by
KazukiHayase
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
HasuraΛ׆༻͢ΔͨΊͷTipsू 2022/08/30 ։ൃ2෦ ૣً
Slide 2
Slide 2 text
ࣗݾհ ● ૣً ● ग़ཧSaa S ○ ϓϩδΣΫτϦʔμʔ ○ ϑϧελοΫΤϯδχΞ ● ࠷ۙͷϚΠϒʔϜ ○ ݸਓ։ൃ࠶։͠·ͨ͠ ■ Cloud Run(gqlgen) + Firestore(Datastore mode ) ■ Next.js + Rela y ○ Ҿͬӽ͠४උத
Slide 3
Slide 3 text
ΞδΣϯμ ● Hasuraͱ ● HasuraΛ׆༻͢ΔͨΊͷTipsू ○ Upsertͷ׆༻ ○ τϥϯβΫγϣϯ ○ ϦϨʔγϣϯΛؚΜͩMutatio n ○ σΟϨΫςΟϒʹΑΔ੍ޚ ● ͓ΘΓʹ
Slide 4
Slide 4 text
ΞδΣϯμ ● Hasuraͱ ● HasuraΛ׆༻͢ΔͨΊͷTipsू ○ Upsertͷ׆༻ ○ τϥϯβΫγϣϯ ○ ϦϨʔγϣϯΛؚΜͩMutatio n ○ σΟϨΫςΟϒʹΑΔ੍ޚ ● ͓ΘΓʹ
Slide 5
Slide 5 text
Hasuraͱ ● DBͷεΩʔϚ͔ΒGraphQLαʔόʔΛੜͰ͖ΔΦʔϓϯιʔε ● DB͑͋͞Εαʔόʔཱ͕ͯΒΕΔͷͰ࣮ίετ͕֨ஈʹݮΔ
Slide 6
Slide 6 text
ΧελϜϩδοΫʹ͍ͭͯ ● ΧελϜϩδοΫΛՃ͢Δํ๏ΛHasuraఏڙ͍ͯ͠Δ ○ Actio n ○ Remote Schem a ● ҙ֎ͱΧελϜϩδοΫΛ࣮͍ͨ͠໘ଟ͍ ● ࣮ͨͩ͠ίετɺϝϯςφϯείετ͕૿Ճ͢Δ
Slide 7
Slide 7 text
HasuraͷػೳΛ׆༻͢Δ͜ͱͰ ΧελϜϩδοΫͷ࣮ΛݮΒ͢͜ͱ͕Ͱ͖Δ
Slide 8
Slide 8 text
ΞδΣϯμ ● Hasuraͱ ● HasuraΛ׆༻͢ΔͨΊͷTipsू ○ Upsertͷ׆༻ ○ τϥϯβΫγϣϯ ○ ϦϨʔγϣϯΛؚΜͩMutatio n ○ σΟϨΫςΟϒʹΑΔ੍ޚ ● ͓ΘΓʹ
Slide 9
Slide 9 text
Upsertͷ׆༻ on_conflictΛࢦఆ͢Δ͜ͱͰUpsertͰ࣮ߦ
Slide 10
Slide 10 text
Upsert༻࣌ͷҙ ● σʔλ͕ଘࡏ͢Δ͔Θ͔Βͳ͍߹ͷΈ༻͢Δ ○ ϕʔεͷMutationInsertͳͷͰશͯͷඞਢύϥϝʔλΛ͢ඞཁ͕͋Δ ○ Updateͷ༻ͱͯ͑͠ͳ͍ ● σʔλ͕ଘࡏ͢Δ͜ͱ͕Θ͔͍ͬͯΔ߹UpdateΛ༻͢Δ
Slide 11
Slide 11 text
ΞδΣϯμ ● Hasuraͱ ● HasuraΛ׆༻͢ΔͨΊͷTipsू ○ Upsertͷ׆༻ ○ τϥϯβΫγϣϯ ○ ϦϨʔγϣϯΛؚΜͩMutatio n ○ σΟϨΫςΟϒʹΑΔ੍ޚ ● ͓ΘΓʹ
Slide 12
Slide 12 text
τϥϯβΫγϣϯ Hasura1ͭͷϦΫΤετʹෳͷMutationؚ͕·Ε͍ͯΔ߹ɺ ֤Mutation1ͭτϥϯβΫγϣϯͰॱ൪ʹ࣮ߦ͞ΕΔ ͲΕ͔ҰͭͰࣦഊͨ͠߹શͯͷMutation͕ϩʔϧόοΫ͞ΕΔ
Slide 13
Slide 13 text
τϥϯβΫγϣϯͷྫ deletePost͕ࣦഊͯ͠SampleMutationશମ͕ϩʔϧόοΫ͞ΕΔ ϩʔϧόοΫ͞ΕΔͷͰtaggingsআ͞Ε͍ͯͳ͍
Slide 14
Slide 14 text
ΞδΣϯμ ● Hasuraͱ ● HasuraΛ׆༻͢ΔͨΊͷTipsू ○ Upsertͷ׆༻ ○ τϥϯβΫγϣϯ ○ ϦϨʔγϣϯΛؚΜͩMutatio n ○ σΟϨΫςΟϒʹΑΔ੍ޚ ● ͓ΘΓʹ
Slide 15
Slide 15 text
ϦϨʔγϣϯΛؚΜͩMutation MutationͷΈཱͯ࣍ୈͰ༷ʑͳϦϨʔγϣϯΛؚΜͩσʔλͷ࡞͕Մೳ ● 1: 1 ● 1: N ● N:N
Slide 16
Slide 16 text
1:1ͷϦϨʔγϣϯ profileͱͦΕʹඥͮ͘userΛ࡞ userͱͦΕʹඥͮ͘profileΛ࡞͠Α͏ͱ͢ΔͱΤϥʔ
Slide 17
Slide 17 text
ΦϒδΣΫτͷ࡞ॱং σϑΥϧτͰ1:1ͷϦϨʔγϣϯԼهͷॱ൪ͰΦϒδΣΫτ͕࡞͞ΕΔ 1. ࢠΦϒδΣΫτΛ࡞ͯ͠idΛऔಘ 2. FKΧϥϜʹ 1 Ͱऔಘͨ͠idΛઃఆͯ͠ΦϒδΣΫτΛ࡞ ※ ϦϨʔγϣϯ࡞࣌ͷinsertion_orderͷઃఆͰॱ൪มߋՄೳ
Slide 18
Slide 18 text
1:NͷϦϨʔγϣϯ ߘͱͦΕʹඥ͍͍ͮ͘ͶΛ࡞
Slide 19
Slide 19 text
ΦϒδΣΫτͷ࡞ॱং 1:NͷϦϨʔγϣϯԼهͷॱ൪ͰΦϒδΣΫτ͕࡞͞ΕΔ 1. ΦϒδΣΫτΛ࡞ͯ͠idΛऔಘ 2. FKΧϥϜʹ 1 Ͱऔಘͨ͠idΛઃఆͯ͠ࢠΦϒδΣΫτΛ࡞
Slide 20
Slide 20 text
N:NͷϦϨʔγϣϯ ߘͱͦΕʹඥͮ͘λάΛ࡞
Slide 21
Slide 21 text
ߴͳN:NͷϦϨʔγϣϯ ߘͱͦΕʹඥͮ͘λάΛ࡞ɺλάͷ࡞Upsert λά͕͢Ͱʹଘࡏ͢Δ߹ͦͷλά ͱඥ͚ɺλά͕ଘࡏ͠ͳ͍߹λ άΛ࡞ͯ͠ඥ͚ͱ͍ͬͨෳࡶͳ Mutation࣮Մೳ
Slide 22
Slide 22 text
ΞδΣϯμ ● Hasuraͱ ● HasuraΛ׆༻͢ΔͨΊͷTipsू ○ Upsertͷ׆༻ ○ τϥϯβΫγϣϯ ○ ϦϨʔγϣϯΛؚΜͩMutatio n ○ σΟϨΫςΟϒʹΑΔ੍ޚ ● ͓ΘΓʹ
Slide 23
Slide 23 text
σΟϨΫςΟϒʹΑΔ੍ޚ Hasuraඪ४σΟϨΫςΟϒ͕ར༻Մೳ σΟϨΫςΟϒΛ׆༻͢Δ͜ͱͰQuery, Mutationͷදݱͷ෯͕͕Δ
Slide 24
Slide 24 text
σΟϨΫςΟϒʹΑΔ੍ޚ @includeͰऔಘ͢ΔϑΟʔϧυΛ੍ޚ @skipͰ࣮ߦ͢ΔMutationΛ੍ޚ
Slide 25
Slide 25 text
σΟϨΫςΟϒʹΑΔ੍ޚ ؔ࿈ͷͳ͍MutationͰ͋ΕϦΫΤετͷׂͰରԠՄೳ ಉ͡τϥϯβΫγϣϯͰMutationͷ࣮ߦΛ੍ޚ͍ͨ͠߹ σΟϨΫςΟϒͰͷ੍ޚ͕༗ޮ
Slide 26
Slide 26 text
͓ΘΓʹ ● HasuraΛ׆༻͢Δ͜ͱͰόοΫΤϯυͷ࣮ΛݮΒ͢͜ͱ͕Ͱ͖Δ ● ଞʹHasuraͷػೳ͚ͩͰ࣮ݱͰ͖Δ͜ͱੵۃతʹ׆༻͢Δͷ͕ ྑ͍ͱࢥ͍·͢ʂ