$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Apollo_Code_Generation [en]
Search
YuyaHorita
October 09, 2019
Programming
0
260
Apollo_Code_Generation [en]
YuyaHorita
October 09, 2019
Tweet
Share
More Decks by YuyaHorita
See All by YuyaHorita
mahjong-kun.pdf
horitayuya
0
100
Apollo_Code_Generation [jp]
horitayuya
0
2.5k
Difference Algorithm
horitayuya
11
6k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.7k
Other Decks in Programming
See All in Programming
React Native New Architecture 移行実践報告
taminif
1
150
AIコーディングエージェント(skywork)
kondai24
0
170
20 years of Symfony, what's next?
fabpot
2
360
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
110
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
420
関数実行の裏側では何が起きているのか?
minop1205
1
700
dotfiles 式年遷宮 令和最新版
masawada
1
770
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
350
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.4k
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
420
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.5k
MAP, Jigsaw, Code Golf 振り返り会 by 関東Kaggler会|Jigsaw 15th Solution
hasibirok0
0
240
Featured
See All Featured
Scaling GitHub
holman
464
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Raft: Consensus for Rubyists
vanstee
141
7.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
70k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
100
How GitHub (no longer) Works
holman
316
140k
RailsConf 2023
tenderlove
30
1.3k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.7k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
730
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
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