たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

AWS AppSync SDKでApollo clientを使う

AWS AppSync SDKは、Apollo clientを拡張したAppSync用clientライブラリである.
AppSync機能を活用したreal-time購読、オフライン対応を素のApollo clientに追加している.

概要

クライアントライブラリのお仕事は

  • 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

  1. Subscribe to any queries defined and store results in an incoming queue
  2. Run the appropriate query (If baseRefreshIntervalInSeconds has elapsed, run the Base Query otherwise only run the Delta Query)
  3. Update the cache with results from the appropriate query
  4. 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

現状の問題点

  • ほぼサポートがない
    • 未解決かつ未返答のissueがたくさん
  • 依存関係が古い

  • AppSync-Apolloに依存する機能

    • × offline mutation
      • "AppSync Queue"が独自実装
    • △ subscription
      • apollo client v3対応の非公開npmがあるのでsubのみならとれる