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-kotlinにcontributeした話
Search
Yuta Tomiyama
August 19, 2023
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
apollo-kotlinにcontributeした話
2023/08/19 TOGATTA SERVER LT #3 にて発表
Yuta Tomiyama
August 19, 2023
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
ビルドプロセスをデバッグしよう!
yt8492
2
510
モバイルアプリ開発を始めよう!
yt8492
0
130
Git勉強会
yt8492
0
230
なんでもやってみる勇気
yt8492
0
140
Android Autoが思ったよりしんどい話
yt8492
0
250
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
1k
今だからこそ知りたいKotlin Multiplatform
yt8492
0
350
State management and API calls in Jetpack Compose: Learning Apollo + Jetpack Compose through React Hooks
yt8492
0
1.4k
サーバーフレームワークの仕組みが気になったので車輪の再発明をしてみた
yt8492
0
260
Other Decks in Programming
See All in Programming
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
140
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.7k
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
130
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
信頼性の目標を誰も求めてない
shubox
0
500
不幸な GC
chencmd
0
900
Intent as Code
shoppingjaws
6
720
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
3
520
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
270
What We Talk About When We Talk About XP
m_seki
2
450
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Building the Perfect Custom Keyboard
takai
2
870
Discover your Explorer Soul
emna__ayadi
2
1.3k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
230
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
A better future with KSS
kneath
240
18k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Evolving SEO for Evolving Search Engines
ryanjones
0
280
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Transcript
apollo-kotlinに contributeした話 2023/08/19 TOGATTA SERVER LT
自己紹介 HN: マヤミト 本名: 富山雄太 GitHub: https://github.com/yt8492 趣味: Kotlin, Twitter,
同人作品 会津大卒 Androidエンジニア Twitter: yt8492
近況報告
薄い本を売ったり買ったりしてました
本題
OSSコントリビュートしてました
apollo-kotlinとは? • Kotlin向けGraphQLクライアントライブラリのデファクトスタンダード • GraphQLのサーバーとの通信やキャッシュ管理をいい感じにやってくれる • KMP対応 • 機能ごとにモジュールが分けられている(コア、ランタイム、キャッシュなど)
元々あった実装 • apollo-runtimeにはEngineのinterfaceが定義されている ◦ interfaceをimplementsすればカスタムのEngineを実装することができる • apollo-kotlinには元々デフォルトで使われるEngineが提供されている ◦ DefaultHttpEngine ◦
DefaultWebsocketEngine • DefaultEngineもKMP対応しているが、実装自体は分かれている ◦ class宣言はexpectでcommonモジュールで型の宣言だけしている ◦ 実装はactualでJVM, JS, Apple(iOS, MacOS)で分けられている ▪ JVMはOkHttp ▪ JSはKtor ▪ AppleはNSURLSession
common(expect) - DefaultHttpEngine - DefaultWebsocketEngine jvm(actual) apple(actual) js(actual) - OkHttp
- Ktor - NSURLSession
元々あった実装 • apollo-runtimeにはEngineのinterfaceが定義されている ◦ interfaceをimplementsすればカスタムのEngineを実装することができる • apollo-kotlinには元々デフォルトで使われるEngineが提供されている ◦ DefaultHttpEngine ◦
DefaultWebsocketEngine • DefaultEngineもKMP対応しているが、実装自体は分かれている ◦ class宣言はexpectでcommonモジュールで型の宣言だけしている ◦ 実装はactualでJVM, JS, Apple(iOS, MacOS)で分けられている ▪ JVMはOkHttp ▪ JSはKtor ▪ AppleはNSURLSession → Ktorを使えばcommonに全部実装共通化できるんじゃね?
common - KtorHttpEngine - KtorWebsocketEngine
今回やったこと • Ktorを使ったKMP対応のApolloのEngineを実装した ◦ KtorHttpEngine ◦ KtorWebsocketEngine • ↑を含んだ新しいapollo-kotlinのモジュールを追加した ◦
apollo-engine-ktor
手順 1. commonMainなKtorのEngineを実装する 2. commonTestに実装したKtorのEngineのテストを書く 3. JVM, JS, Appleでそれぞれ同じテストが通るか確認する
Q. 難しいんでしょう?
Q. 難しいんでしょう? A. 意外と簡単です Engine自体はただApollo側で定義されたHTTP/Websocketのリクエストをそれぞれ のEngineの形式のものに変換して実行し、レスポンスをApolloのものに変換して返す だけ
HttpEngineのinterface
KtorHttpEngine
HttpEngineがリクエストを処理するまで 1. ApolloClient.BuilderにHttpEngineが渡される 2. HttpNetworkTransport.BuilderにHttpEngineが渡される 3. ApolloClientのプロパティのNetworkInterceptorにHttpNetworkTransportが 渡される 4. リクエスト実行時にApolloClientが持つinterceptersが順番にリクエストを処理
し、最後にNetworkInterceptorの処理が走るのでそのタイミングでHttpEngine が呼び出される
感想 • デカいOSSに貢献できてうれち〜〜〜〜〜〜〜〜〜〜 • プルリクのコメントで結構いろいろ教えてくれてやりやすかった • みんなもOSSコントリビュート、しよう!