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-kotlinにcontributeした話
Search
Yuta Tomiyama
August 19, 2023
Programming
0
97
apollo-kotlinにcontributeした話
2023/08/19 TOGATTA SERVER LT #3 にて発表
Yuta Tomiyama
August 19, 2023
Tweet
Share
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
なんでもやってみる勇気
yt8492
0
53
Android Autoが思ったよりしんどい話
yt8492
0
170
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
780
今だからこそ知りたいKotlin Multiplatform
yt8492
0
260
State management and API calls in Jetpack Compose: Learning Apollo + Jetpack Compose through React Hooks
yt8492
0
1.2k
サーバーフレームワークの仕組みが気になったので車輪の再発明をしてみた
yt8492
0
180
Compose for Webを始めよう
yt8492
0
370
Compose Multiplatform 1.0.0
yt8492
0
150
Kotlin/NativeからCの標準ライブラリを呼び出そう
yt8492
0
390
Other Decks in Programming
See All in Programming
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1k
Immutable ActiveRecord
megane42
0
140
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
230
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
110
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
250
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
100
Spring gRPC について / About Spring gRPC
mackey0225
0
220
Introduction to kotlinx.rpc
arawn
0
700
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
5
390
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
140
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
42
7.2k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
30
4.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
240
Speed Design
sergeychernyshev
27
790
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
A Modern Web Designer's Workflow
chriscoyier
693
190k
Docker and Python
trallard
44
3.3k
BBQ
matthewcrist
87
9.5k
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コントリビュート、しよう!