Slide 1

Slide 1 text

2024/5/11 TSKaigi @hokaccha TypeScriptͱGraphQLͰ࣮ݱ͢Δ ܕ҆શͳAPI࣮૷

Slide 2

Slide 2 text

Ubie, Inc @hokaccha @hokaccha Kazuhito Hokamura

Slide 3

Slide 3 text

ࠓ೔ͷ಺༰͸ͪ͜ΒͰ΋ಡΊ·͢ Ubie ςοΫϒϩά

Slide 4

Slide 4 text

ͳͥAPIʹܕΛ͚͍ͭͨͷ͔

Slide 5

Slide 5 text

Α͋͘Δ API ϦΫΤετͷίʔυ

Slide 6

Slide 6 text

any ͔ΒͷܕΩϟετͱ͸ɺفΓ 🙇҆શفئ🙏

Slide 7

Slide 7 text

فΓ͕௨͡ͳ͍ͱ਌ͷإΑΓݟͨ΍ͭ

Slide 8

Slide 8 text

֎෦I/Oʹର͢Δܕ෇͚͕ෆे෼ͩͱ ੩తܕ෇͚ͷԸܙΛे෼׆͔ͤͳ͍

Slide 9

Slide 9 text

API ʹܕΛ͚ͭΔ #ͱ͸ 1. API ͷ࢓༷ΛεΩʔϚͰఆٛ͢Δ 2. εΩʔϚ͔Β࣮૷ݴޠͷܕΛੜ੒͢Δ 3. ੜ੒͞ΕͨܕΛ࢖࣮ͬͯ૷͢Δ • ΫϥΠΞϯτͷ࣮૷ • αʔόʔͷ࣮૷

Slide 10

Slide 10 text

API ʹܕΛ͚ͭΔٕज़ • OpenAPI • gRPC • GraphQL ࠓ೔͸͜Ε

Slide 11

Slide 11 text

GraphQLͷεΩʔϚఆٛ schema.graphq

Slide 12

Slide 12 text

εΩʔϚ͔ΒܕΛੜ੒ schema.graphq generated.ts

Slide 13

Slide 13 text

ੜ੒ͨ͠ܕΛ࢖࣮ͬͯ૷͢Δ client.ts server.ts ˞ίʔυ͸Πϝʔδ

Slide 14

Slide 14 text

GraphQL Codegen

Slide 15

Slide 15 text

ΫϥΠΞϯταΠυ

Slide 16

Slide 16 text

GraphQL Codegen Client Preset

Slide 17

Slide 17 text

codegen.ts

Slide 18

Slide 18 text

🙅 εΩʔϚ͔Βੜ੒ͨ͠ܕΛ࢖͏ 🙆 ΫΤϦ͔Βੜ੒ͨ͠ܕΛ࢖͏

Slide 19

Slide 19 text

εΩʔϚ͔Βੜ੒ͨ͠ܕΛ࢖͏ εΩʔϚ ੜ੒͞Εͨܕ ΫϥΠΞϯτ࣮૷

Slide 20

Slide 20 text

εΩʔϚ͔Βੜ੒ͨ͠ܕΛ࢖͏ εΩʔϚ ੜ੒͞Εͨܕ ΫϥΠΞϯτ࣮૷ JNBHF6SM͕ܕʹ͸͋Δ͚ͲϨεϙϯεʹ͸ͳ͍

Slide 21

Slide 21 text

εΩʔϚ͔Βੜ੒ͨ͠ܕΛ࢖͏ εΩʔϚ ੜ੒͞Εͨܕ ΫϥΠΞϯτ࣮૷ JNBHF6SM͕ܕʹ͸͋Δ͚ͲϨεϙϯεʹ͸ͳ͍

Slide 22

Slide 22 text

ΫΤϦ͔Βੜ੒ͨ͠ܕΛ࢖͏

Slide 23

Slide 23 text

ΫΤϦจࣈྻ͔Β (SBQI2-$PEFHFO͕ܕΛੜ੒͢Δ

Slide 24

Slide 24 text

͜ͷ஋Λ(SBQI2-ͷΫϥΠΞϯτʹ౉͢ͱ ΫΤϦͷ݁Ռʹਖ਼͘͠ܕ͕ͭ͘

Slide 25

Slide 25 text

ೖྗ஋΋ΫΤϦ͔Β࡞ΒΕͨ ܕͰܕݕ͕ࠪޮ͘

Slide 26

Slide 26 text

TypedDocumentNode • GraphQL Codegen͕ੜ੒͢ΔΫΤϦͷܕ෇͖AST • ରԠ͢ΔΫϥΠΞϯτʹ৯ΘͤΔͱܕ͕෇͘ • ϝδϟʔͲ͜ΖͷΫϥΠΞϯτ͸ରԠ͍ͯ͠Δ • Apollo Client • urql • graphql-request ͜Ε

Slide 27

Slide 27 text

Fragment Masking

Slide 28

Slide 28 text

ͷલʹFragment Colocation

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

ը૾Λදࣔ͠ͳ͍Α͏ʹมߋ

Slide 31

Slide 31 text

ফ͠๨Εͯ΋ ؾ෇͚ͳ͍

Slide 32

Slide 32 text

ଞͷΫΤϦͰ΋ࢀর͞ΕͯΔ͔΋

Slide 33

Slide 33 text

͢΂ͯͷࢠ͕ඞཁͱ͢ΔσʔλΛτοϓϨϕϧͷ ΫΤϦ͕஌͍ͬͯΔඞཁ͕͋Δͱ͍͏ઃܭͷ࿪

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

͜ͷ'SBHNFOUఆ͔ٛΒܕΛੜ੒

Slide 37

Slide 37 text

ੜ੒͞Εͨܕ

Slide 38

Slide 38 text

Fragment Colocation • FragmentΛίϯϙʔωϯτͱಉ͡৔ॴʹஔ͘ • ίϯϙʔωϯτ͸ࣗ਎͕ؔ৺ͷ͋ΔϑΟʔϧυ͚ͩ؅ཧ͢Ε͹Α͍ • ਌͸௚઀ͷࢠͷFragment͚ͩΛ஌͍ͬͯΕ͹Α͍

Slide 39

Slide 39 text

Fragment Masking

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

͜͜Ͱ͔͠OBNFΛࢦఆͯ͠ͳ͍

Slide 42

Slide 42 text

͜͜ͰࢀরͰ͖ͯ͠·͏

Slide 43

Slide 43 text

࣮͸͜Ε͸ܕΤϥʔʹͳΔ

Slide 44

Slide 44 text

͜Μͳײ͡ʹܕΛมߋ

Slide 45

Slide 45 text

͜ͷؔ਺Λ௨͞ͳ͍ͱ'SBHNFOUͷ σʔλΛࢀরͰ͖ͳ͍

Slide 46

Slide 46 text

Fragment Masking • FragmentΛఆٛͨ͠ίϯϙʔωϯτҎ֎͔ΒFragmentͷσʔλʹ
 ΞΫηεͰ͖ͳ͍Α͏ʹ͢Δ • ͜ΕʹΑͬͯFragment Colocation͕ڧ੍ͤ͞Δ • ܕ͕ෳࡶʹͳΔͱ͍͏σϝϦοτ΋͋Δ

Slide 47

Slide 47 text

αʔόʔαΠυ

Slide 48

Slide 48 text

GraphQL Codegen TypeScript Resolvers

Slide 49

Slide 49 text

GraphQL Codegen TypeScript Resolvers 4FSWFS1SFTFU͸บ͕ڧΊ

Slide 50

Slide 50 text

ϝδϟʔͳϥΠϒϥϦʹରԠ • graphql-js • ͜Ε͕શͯͷϕʔε • Apollo Server • GraphQL Yoga

Slide 51

Slide 51 text

NestJS͚ͩগ͠ಛघ Ubie ςοΫϒϩά

Slide 52

Slide 52 text

schema.graphql

Slide 53

Slide 53 text

resolvers.ts model.ts

Slide 54

Slide 54 text

resolvers.ts model.ts %#͔ΒҾ͍ͯNPEFMͷܕΛฦ͢

Slide 55

Slide 55 text

codegen.ts

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

ܕ͕͍ͭͯΑ͔ͬͨʂ׬ʂ ͱ͸͍͔ͳ͍

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

DPNQBOZΛؚ·ͳ͍

Slide 60

Slide 60 text

DPNQBOZͷऔಘ͕ແବ

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

DPNQBOZ͕ΫΤϦʹؚ·ΕΔͱ͖͚࣮ͩߦ͞ΕΔ

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

codegen.ts 3FTPMWFSͰѻ͏ܕΛมߋͰ͖Δ

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

·ͱΊ

Slide 68

Slide 68 text

·ͱΊ • APIͷ࣮૷ʹܕΛ͚ͭͯفΓ͔Β։์͞ΕΑ͏ʂ • GraphQL CodegenͰΫϥΠΞϯτɾαʔόʔͷ࣮૷ʹܕΛ͚ͭΒΕΔʂ • ಋೖίετ͸ͦΕͳΓʹ͔͔Δ͚ͲϝϦοτ͸ѹ౗తʹେ͖͍ͧʂ

Slide 69

Slide 69 text

͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ