AWS AppSync SDKは、Apollo clientを拡張したAppSync用clientライブラリである.
AppSync機能を活用したreal-time購読、オフライン対応を素のApollo clientに追加している.
- document: docs
- repository: awslabs/aws-mobile-appsync-sdk-js
概要
クライアントライブラリのお仕事は
- reconnection
- exponential backoff: way to retry
- retries
Subscription
Mutationに応答した、GraphQL Subscription (MQTT over WebSocket) によるサーバープッシュ
@aws_subscribe(mutations: ["",..,""]) は、ミューテーション入力の配列を受け取るため、サブスクリプションをトリガーする複数のミューテーションを指定できます。
再接続はSDKがハンドルしてくれる.
Subscription connection management is handled automatically by the AWS AppSync client SDK using MQTT over WebSockets as the network protocol between the client and service.
ref
DeltaSync
Backend側実装
- SGI/SLIで複製
- AppSync pipeline resolverで分割
オフライン時の動作
When offline→online,
to account for high velocity writes
the client will execute the resubscription along with synchronization and message processing
- Subscribe to any queries defined and store results in an incoming queue
- Run the appropriate query (If baseRefreshIntervalInSeconds has elapsed, run the Base Query otherwise only run the Delta Query)
- Update the cache with results from the appropriate query
- Drain the subscription queue and continue processing as normal
incoming queue
update cache
queue-based?
query -> stack in incoming queue -> update cache -> discard finished queue