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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Making the RBS Parser Faster
soutaro
0
380
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
140
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
110
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
280
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
220
「話せることがない」を乗り越える 〜日常業務から登壇テーマをつくる思考法〜
shoheimitani
4
810
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
560
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
340
Vibe NLP for Applied NLP
inesmontani
PRO
0
430
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
6.5k
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
130
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
The Curse of the Amulet
leimatthew05
1
11k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
From π to Pie charts
rasagy
0
160
New Earth Scene 8
popppiees
3
2.1k
Deep Space Network (abreviated)
tonyrice
0
120
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
130
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
130
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
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