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 [jp]
Search
YuyaHorita
October 09, 2019
Programming
0
2.3k
Apollo_Code_Generation [jp]
YuyaHorita
October 09, 2019
Tweet
Share
More Decks by YuyaHorita
See All by YuyaHorita
mahjong-kun.pdf
horitayuya
0
86
Apollo_Code_Generation [en]
horitayuya
0
210
Difference Algorithm
horitayuya
11
5.6k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.6k
Other Decks in Programming
See All in Programming
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Done Done
chrislema
181
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Writing Fast Ruby
sferik
627
61k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Speed Design
sergeychernyshev
24
610
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
How STYLIGHT went responsive
nonsquared
95
5.2k
Designing the Hi-DPI Web
ddemaree
280
34k
A Tale of Four Properties
chriscoyier
156
23k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Navigating Team Friction
lara
183
14k
Transcript
Apollo Code Generation
Introduction ງా ༗࠸ 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 αʔόʔͰఆٛ͞ΕͨQueryใΛؚΉϑΝΠϧ > Conventionally this file is called schema.json Reference:
https://www.apollographql.com/docs/ios/downloading-schema/
*.graphql ΫΤϦఆٛϑΝΠϧ
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 Parse࣌ʹແࢹ͞ΕΔ name : undefined
`#` ͦΕ͕ࣗToken Kindʹͳ͍ͬͯͳ͍ɻ -> `/* */`ͳͲͰɺෳߦίϝϯτͷ༧ײ?
https://github.com/graphql/graphql-js/blob/master/src/language/lexer.js#L187 https://github.com/graphql/graphql-spec/issues/276 Lexerͷ࣮తʹɺݱ࣌Ͱ `#` ͰͷΈίϝϯτՄೳͷ༷
Parser Tokens to AST
query User AddressFragment NAME NAME NAME Operationએݴ name NAME Tokens
ҙຯ Operation໊ field໊ Fragment໊
( $ @ … Argumentએݴͷ։࢝ͳͲ ҙຯ Variable Directive Fragment/Inline Fragment
Spread Tokens : Argument, AliasͳͲ
NAME Token: จ຺ͱvalueʹΑͬͯҙຯ͕มΘΔ Punctuator Token: ݻఆͷҙຯ or จ຺ʹΑͬͯҙຯ͕มΘΔ ( $
: @
None
Document Hoge parseॲཧ function parseHoge ͷ໊લͰgraphql/language/parser.jsʹఆٛ = OperationDefinition OperationType Name
VariableDefinitions VariableDefinition SelectionSet VariableDefinition ࠶ؼԼ߱ߏจղੳ
Operationએݴ `query`͕͋ΓɺOperation໊ `User`ͷޙɺ `(` ͕͋ΕɺҾ(ม)ͷఆ͕ٛ࢝·Γɺ `)` ͕དྷͨΒऴྃɻ ࣍ͷ `{` ͔ΒSelectionSetͷఆ͕ٛ࢝·Γɺɺɺ
Tokens Rules +
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. *.graphql͔ΒASTΛੜ 2. schema.jsonͱরΒ͠߹Θͤͳ͕ΒɺAST͔ΒIRΛੜ 3. IR͔Βɺ.swift, .ts, .scalaΛੜ (
scalaLegacyͷํΛ͍ͬͯΔ ) 4. .ktapollo-toolingΛΘͣɺ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