0

I have a Todo AppSync Android app with these as dependencies

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'

Here's my schema

type Task @model {
  id: ID!
  title: String!
  description: String
  status: String
}
type Note @model {
  id: ID!
  content: String!
}

I am able to list and create Tasks so far. But when I try to subscribe to OnCreateTask, I get an exception saying it fail to parse the object.

Here's my code


    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")
            }
        }

Here is my stack trace:

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)

Would anyone know why the _version value is not being returned from AppSync ?

Thanks

1 Answers1

0

I've found the issue, it's because when I was creating a task on the AWS console, I didn't identify _version as a return attribute. This is what I had before

mutation create {
  createTask(input: {
    title:"sync, plkease work"
    description:"pm-v"}) { 
    id
    title
  }
}

Now Changed to

mutation create {
  createTask(input: {
    title:"sync, plkease work"
    description:"pm-v"}) { 
    id
    title
    description
    _version
    _lastChangedAt
  }
}