Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Apollo_Code_Generation [en]
YuyaHorita
October 09, 2019
Programming
0
150
Apollo_Code_Generation [en]
YuyaHorita
October 09, 2019
Tweet
Share
More Decks by YuyaHorita
See All by YuyaHorita
mahjong-kun.pdf
horitayuya
0
22
Apollo_Code_Generation [jp]
horitayuya
0
1.9k
Difference Algorithm
horitayuya
10
4.7k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.3k
Other Decks in Programming
See All in Programming
Dagger + Anvil: Learning to Love Dependency Injection
vrallev
3
240
Meet Swift Regex
usamik26
0
310
Node.jsデザインパターンを読んで
mmmommm
0
1.8k
RFC 9111: HTTP Caching
jxck
0
150
#JJUG_CCC 「サポート」は製品開発? - JDBCライブラリ屋さんが実践する攻めのテクニカルサポートとJavaエンジニアのキャリアについて -
cdataj
0
410
Reactアプリケーションのテスト戦略
0906koki
10
4.6k
Modern Android Developer ~ 안내서
pluu
1
590
GitHubのユーザー名を変更した後のあれこれ
tahia910
0
120
エンジニアによる事業指標計測のススメ
doyaaaaaken
1
180
模組化的Swift架構(二) DDD速成
haifengkao
0
350
PythonユーザによるRust入門
rmizuta3
9
3.1k
Improving Developer Experience Through Tools and Techniques 2022
krzysztofzablocki
0
430
Featured
See All Featured
Web Components: a chance to create the future
zenorocha
303
40k
JazzCon 2018 Closing Keynote - Leadership for the Reluctant Leader
reverentgeek
172
8.4k
Product Roadmaps are Hard
iamctodd
34
6.5k
The Pragmatic Product Professional
lauravandoore
19
2.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
316
22k
Fashionably flexible responsive web design (full day workshop)
malarkey
396
62k
How to name files
jennybc
40
60k
Learning to Love Humans: Emotional Interface Design
aarron
261
37k
BBQ
matthewcrist
74
7.9k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
19
1.4k
4 Signs Your Business is Dying
shpigford
169
20k
Statistics for Hackers
jakevdp
781
210k
Transcript
Apollo Code Generation
Introduction Yuya Horita 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 File contains the results of an introspection query, or
query information > Conventionally this file is called schema.json Reference: https://www.apollographql.com/docs/ios/downloading-schema/
*.graphql Query definition file
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 Ignoring on parsing phase name : undefined
`#` itself is not a token kind. -> Other ways
to comment out, like `/**/`?
https://github.com/graphql/graphql-js/blob/master/src/language/lexer.js#L187 https://github.com/graphql/graphql-spec/issues/276 Reading implementation of lexer, it seems only `#`
indicates comment.
Parser Tokens to AST
query User AddressFragment NAME NAME NAME Operation definition name NAME
Tokens Semantics Operation name field name Fragment name
( $ @ … Beginning of definition of arguments, etc.
Variable Directive Fragment/Inline Fragment Spread Tokens : Argument, Alias, etc. Semantics
NAME Token: Semantics depends on syntax and value. Punctuator Token:
Semantics is fixed or depends on syntax ( $ : @
None
Document Hoge parsing operation function parseHoge is defined in graphql/language/parser.js
= OperationDefinition OperationType Name VariableDefinitions VariableDefinition SelectionSet VariableDefinition Recursive Descent Parsing
Tokens Rules + Starts with operation definition keyword `query`. The
next `User` is operation name. If `(` exists in just after `User`, variable definitions starts. It will end with `)`. Next `{` means the beginning of definition of SelectionSet ……
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. AST from *.graphql. 2. IR from ast and
schema.json. 3. .swift, .ts, .scala from IR 4. It seems .kt doesn’t use apollo-tooling. All implementations are in 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