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
Golang と Erlang
taiyow
8
1.9k
Honoの来た道とこれから
yusukebe
19
3k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
150
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
Nuxt UI Pro、NuxtHub、Nuxt Scripts、Nuxtエコシステムをふんだんに利用して開発するコーポレートサイト@Vue Fes Japan 2024
shingangan
3
890
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
570
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
130
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
320
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How STYLIGHT went responsive
nonsquared
95
5.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Building Adaptive Systems
keathley
38
2.2k
Building Your Own Lightsaber
phodgson
102
6k
Ruby is Unlike a Banana
tanoku
96
11k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Designing for humans not robots
tammielis
249
25k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Gamification - CAS2011
davidbonilla
80
5k
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