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 [en]
Search
YuyaHorita
October 09, 2019
Programming
270
0
Share
Apollo_Code_Generation [en]
YuyaHorita
October 09, 2019
More Decks by YuyaHorita
See All by YuyaHorita
mahjong-kun.pdf
horitayuya
0
110
Apollo_Code_Generation [jp]
horitayuya
0
2.5k
Difference Algorithm
horitayuya
11
6.2k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.7k
Other Decks in Programming
See All in Programming
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
110
アーキテクチャモダナイゼーションとは何か
nwiizo
19
5.4k
🦞OpenClaw works with AWS
licux
1
200
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
220
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
150
一度始めたらやめられない開発効率向上術 / Findy あなたのdotfilesを教えて!
k0kubun
4
3k
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
380
〜バイブコーディングを超えて〜 チームで実験し続けたAI駆動開発
tigertora7571
0
150
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
3
970
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
990
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
640
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
Rails Girls Zürich Keynote
gr2m
96
14k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.6k
Designing Experiences People Love
moore
143
24k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Optimizing for Happiness
mojombo
378
71k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
810
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
270
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
170
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
170
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
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