Closed17

appsync でとってきたデータの中身がおかしい

tkttkt
  • aws から dynamodb を覗いた時のデータ
  • aws appsync 経由で dynamodb から取得したデータ

上記は一致している

  • android appsync から取得したデータ

これがなぜか違っていて、存在しないはずの数ヶ月前のデータが取得されている
データソースに対して追加、削除しようが変わらない

tkttkt

取得に使っているコードはこれ
https://zenn.dev/tktcorporation/scraps/c1c9a87afb431e#comment-45e4c6af356663

suspend fun getListPost(client: AWSAppSyncClient): List<ListPostQuery.Item> {
    return suspendCoroutine { continuation ->
        val query = ListPostQuery.builder().build()
        val caller = client.query(query)
        caller.enqueue(object : GraphQLCall.Callback<ListPostQuery.Data>() {
            override fun onFailure(e: ApolloException) {
                throw e
            }

            override fun onResponse(response: Response<ListPostQuery.Data>) {
               val result = response.data()!!.listPost()!!.items()!!
               continuation.resume(result)
            }
        })
    }
}
tkttkt

mutate する場合は対象の table に対して書き込めている

tkttkt

別テーブルで query 投げても変なデータが返ってくる

tkttkt
client.clearCaches()
val caller = client.query(query)

これでとってきてる中身が変わった

tkttkt

clearCashes の挙動が知りたい

tkttkt

この制御は appsync なのか、graphql なのか、android のライブラリなのか

tkttkt

Clears the different client databases on the local device based on the ClearCacheOptions object passed in.

ローカルにキャッシュ領域を持ってる?

tkttkt

ローカルのキャッシュ消去であれば、消すタイミングは慎重にしないとダメそう
(オフラインでも使いたいから)

tkttkt
/**
   * Sets the {@link ResponseFetcher} strategy for an GraphQLCall object.
   *
   * @param fetcher the {@link ResponseFetcher} to use.
   * @return The GraphQLCall object with the provided CacheControl strategy
   */
  @Nonnull
  AppSyncQueryCall<T> responseFetcher(@Nonnull ResponseFetcher fetcher);

キャッシュ消さずにいい感じに更新してくれる方法探し

tkttkt
import com.amazonaws.mobileconnectors.appsync.fetcher.AppSyncResponseFetchers.NETWORK_ONLY

val caller = client.query(query).responseFetcher(NETWORK_ONLY)

これでいけるかな

tkttkt

clearCaches しないで NETWORK_ONLY だけでやってみたら、キャッシュが残ったまんまっぽい?

このスクラップは2021/04/16にクローズされました