android - AWS Appsync - 无法解析订阅 - _version 的预期非空值
问题描述
我有一个 Todo AppSync Android 应用程序,这些应用程序作为依赖项
implementation 'com.amazonaws:aws-android-sdk-appsync:2.9.+'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
这是我的架构
type Task @model {
id: ID!
title: String!
description: String
status: String
}
type Note @model {
id: ID!
content: String!
}
到目前为止,我能够列出和创建任务。但是当我尝试订阅 OnCreateTask 时,我收到一个异常,说它无法解析对象。
这是我的代码
private fun subscribeOnCreate() {
val subscription: OnCreateTaskSubscription = OnCreateTaskSubscription.builder().build()
onCreateSubscriptionWatcher = mAWSAppSyncClient.subscribe(subscription)
onCreateSubscriptionWatcher.execute(onCreateSubscriptionCallback)
}
val onCreateSubscriptionCallback: AppSyncSubscriptionCall.Callback<OnCreateTaskSubscription.Data> =
object : AppSyncSubscriptionCall.Callback<OnCreateTaskSubscription.Data> {
override fun onResponse(response: Response<OnCreateTaskSubscription.Data?>) {
Log.i("Subscription", response.data().toString())
query()
}
override fun onFailure(@Nonnull e: ApolloException) {
Log.e("Subscription", e.toString())
}
override fun onCompleted() {
Log.i("Subscription", "Subscription completed")
}
}
这是我的堆栈跟踪:
2020-05-21 10:13:18.773 16259-16472/com.wwm.todo E/SubscriptionObject: Failed to parse: {"data":{"onCreateTask":{"id":"1cbcfdd9-c124-4fca-8544-6f983757bc13","title":"math","__typename":"Task"}}}
java.lang.NullPointerException: corrupted response reader, expected non null value for _version
at com.apollographql.apollo.internal.response.RealResponseReader.checkValue(RealResponseReader.java:264)
at com.apollographql.apollo.internal.response.RealResponseReader.readInt(RealResponseReader.java:67)
at com.amazonaws.amplify.generated.graphql.OnCreateTaskSubscription$OnCreateTask$Mapper.map(OnCreateTaskSubscription.java:340)
at com.amazonaws.amplify.generated.graphql.OnCreateTaskSubscription$Data$Mapper$1.read(OnCreateTaskSubscription.java:167)
有谁知道为什么 AppSync 没有返回 _version 值?
谢谢
解决方案
我发现了问题,这是因为当我在 AWS 控制台上创建任务时,我没有将 _version 标识为返回属性。这是我以前的
mutation create {
createTask(input: {
title:"sync, plkease work"
description:"pm-v"}) {
id
title
}
}
现在改为
mutation create {
createTask(input: {
title:"sync, plkease work"
description:"pm-v"}) {
id
title
description
_version
_lastChangedAt
}
}
推荐阅读
- java - Android中是否有任何有效的方法来缩小文件中的大图像并将其保存到新文件而不会出现OOM异常
- java - 如何与批处理进行通信?
- spark-java - Spark 可以支持每条路由多少个并发请求?
- php - Symfony 中的简单查询返回 null
- header - Zip 是否使用字典进行压缩?是否可以提取该字典并将其转储到文本文件中?
- youtube-api - Youtube API - 允许订阅用户,但次日取走
- java - 在我的 txt 文件的每一行添加一个空格
- regex - 条件正则表达式模板
- typescript - 在 @ngrx/store 中进行计算的记忆选择器
- javascript - 基于列值更改的备用表行背景颜色