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
220
Difference Algorithm
horitayuya
11
5.6k
iOS11でのHEVC動画のHLS配信
horitayuya
2
1.6k
Other Decks in Programming
See All in Programming
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
820
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Haze - Real time background blurring
chrisbanes
1
510
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
380
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.2k
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
280
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
BBQ
matthewcrist
85
9.4k
Adopting Sorbet at Scale
ufuk
73
9.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Six Lessons from altMBA
skipperchong
27
3.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Building a Scalable Design System with Sketch
lauravandoore
460
33k
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