Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Apollo_Code_Generation [en]
Search
YuyaHorita
October 09, 2019
Programming
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Apollo_Code_Generation [en]
YuyaHorita
October 09, 2019
Transcript
36 slides
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
More Decks by YuyaHorita
See All by YuyaHorita
mahjong-kun.pdf
horitayuya
0
130
Apollo_Code_Generation [jp]
horitayuya
0
2.6k
Difference Algorithm
horitayuya
11
6.5k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.8k
Other Decks in Programming
See All in Programming
マルチプロダクトSaaSの アプリ一覧を速くする——複数プロダクトにまたがる「権限行脚」を減らすまで #techramen26conf
mktakuya
1
180
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
6.3k
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
210
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
AI Augmentation Techniques with Liberty
ivargrimstad
1
560
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
270
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
120
読みやすい!と評判(?)の発表の準備にかける私のこだわり
shoheimitani
0
160
Kotlin JVM用に作られたライブラリのKMPを前提とした再設計
jsoizo
0
230
眠らない開発チームの作り方
biwakonbu
0
100
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
860
Building the Perfect Custom Keyboard
takai
2
970
Speed Design
sergeychernyshev
33
2.3k
Facilitating Awesome Meetings
lara
57
7.2k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.9k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
690
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Building Adaptive Systems
keathley
44
3.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k