Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Apollo_Code_Generation [jp]
Search
YuyaHorita
October 09, 2019
Programming
0
2.3k
Apollo_Code_Generation [jp]
YuyaHorita
October 09, 2019
Tweet
Share
More Decks by YuyaHorita
See All by YuyaHorita
mahjong-kun.pdf
horitayuya
0
86
Apollo_Code_Generation [en]
horitayuya
0
220
Difference Algorithm
horitayuya
11
5.6k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.6k
Other Decks in Programming
See All in Programming
快速入門可觀測性
blueswen
0
340
Go の GC の不得意な部分を克服したい
taiyow
2
770
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
710
Refactor your code - refactor yourself
xosofox
1
260
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
たのしいparse.y
ydah
3
120
return文におけるstd::moveについて
onihusube
1
1k
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
720
Featured
See All Featured
A better future with KSS
kneath
238
17k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
For a Future-Friendly Web
brad_frost
175
9.4k
Agile that works and the tools we love
rasmusluckow
328
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Embracing the Ebb and Flow
colly
84
4.5k
Optimising Largest Contentful Paint
csswizardry
33
3k
We Have a Design System, Now What?
morganepeng
51
7.3k
Unsuck your backbone
ammeep
669
57k
Code Reviewing Like a Champion
maltzj
520
39k
Mobile First: as difficult as doing things right
swwweet
222
9k
Transcript
Apollo Code Generation
Introduction ງా ༗࠸ iOS Engineer @CyberAgent, 2017/4 ~ 2019/5 Software
Engineer @M3, 2019/5 ~ GitHub: https://github.com/horita-yuya Twitter: https://twitter.com/horita_yuya Medium: https://medium.com/@yuyaHorita
None
schema.json *.graphql ʴ
schema.json αʔόʔͰఆٛ͞ΕͨQueryใΛؚΉϑΝΠϧ > Conventionally this file is called schema.json Reference:
https://www.apollographql.com/docs/ios/downloading-schema/
*.graphql ΫΤϦఆٛϑΝΠϧ
schema.json *.graphql ʴ
schema.json *.graphql Token AST IR →
Lexer .graphql to Tokens
User.graphql
User.graphql Tokens query User ( $ id email @ include
… AddressFragment Debug : response ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~
query User ( $ @ … AddressFragment NAME Kind Value
undefined undefined undefined undefined COMMENT Debug Parse࣌ʹແࢹ͞ΕΔ name : undefined
`#` ͦΕ͕ࣗToken Kindʹͳ͍ͬͯͳ͍ɻ -> `/* */`ͳͲͰɺෳߦίϝϯτͷ༧ײ?
https://github.com/graphql/graphql-js/blob/master/src/language/lexer.js#L187 https://github.com/graphql/graphql-spec/issues/276 Lexerͷ࣮తʹɺݱ࣌Ͱ `#` ͰͷΈίϝϯτՄೳͷ༷
Parser Tokens to AST
query User AddressFragment NAME NAME NAME Operationએݴ name NAME Tokens
ҙຯ Operation໊ field໊ Fragment໊
( $ @ … Argumentએݴͷ։࢝ͳͲ ҙຯ Variable Directive Fragment/Inline Fragment
Spread Tokens : Argument, AliasͳͲ
NAME Token: จ຺ͱvalueʹΑͬͯҙຯ͕มΘΔ Punctuator Token: ݻఆͷҙຯ or จ຺ʹΑͬͯҙຯ͕มΘΔ ( $
: @
None
Document Hoge parseॲཧ function parseHoge ͷ໊લͰgraphql/language/parser.jsʹఆٛ = OperationDefinition OperationType Name
VariableDefinitions VariableDefinition SelectionSet VariableDefinition ࠶ؼԼ߱ߏจղੳ
Operationએݴ `query`͕͋ΓɺOperation໊ `User`ͷޙɺ `(` ͕͋ΕɺҾ(ม)ͷఆ͕ٛ࢝·Γɺ `)` ͕དྷͨΒऴྃɻ ࣍ͷ `{` ͔ΒSelectionSetͷఆ͕ٛ࢝·Γɺɺɺ
Tokens Rules +
VariableDefinitions Document OperationDefinition FragmentDefinition AST OperationType VariableDefinition VariableDefinition
IR Generator AST to IR
None
None
None
VariableDefinition Type Variable Name value: string Name value: string
Type Variable Name value: id Name value: Int! VariableDefinitions VariableDefinition
VariableDefinition Type Variable Name value: withEmail Name value: Boolean!
VariableDefinitions VariableDefinition VariableDefinition + schema.json GraphQLType GraphQLType Type Variable Name
value: id Name value: Int! Type Variable Name value: withEmail Name value: Boolean!
IR
IR CompilerContext LegacyCompilerContext
Summary 1. *.graphql͔ΒASTΛੜ 2. schema.jsonͱরΒ͠߹Θͤͳ͕ΒɺAST͔ΒIRΛੜ 3. IR͔Βɺ.swift, .ts, .scalaΛੜ (
scalaLegacyͷํΛ͍ͬͯΔ ) 4. .ktapollo-toolingΛΘͣɺapollo-androidͰผ࣮?
Appendix
Lexer Lexer: https://github.com/graphql/graphql-js/blob/master/src/language/lexer.js Token Kind: https://github.com/graphql/graphql-js/blob/master/src/language/tokenKind.js
Parser Parser: https://github.com/graphql/graphql-js/blob/master/src/language/parser.js AST: https://github.com/graphql/graphql-js/blob/master/src/language/ast.js AST Kind: https://github.com/graphql/graphql-js/blob/master/src/language/kinds.js
IR Compiler: https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-codegen- core/src/compiler/index.ts