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
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
みんなでプロポーザルを書いてみた
yuriko1211
0
280
CSC509 Lecture 12
javiergs
PRO
0
160
Arm移行タイムアタック
qnighy
0
330
Outline View in SwiftUI
1024jp
1
330
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
subpath importsで始めるモック生活
10tera
0
310
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
CSC509 Lecture 13
javiergs
PRO
0
110
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Visualization
eitanlees
145
15k
Designing Experiences People Love
moore
138
23k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Why Our Code Smells
bkeepers
PRO
334
57k
Teambox: Starting and Learning
jrom
133
8.8k
A Philosophy of Restraint
colly
203
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Rails Girls Zürich Keynote
gr2m
94
13k
The Cult of Friendly URLs
andyhume
78
6k
Practical Orchestrator
shlominoach
186
10k
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