0

(I am a beginner) I am trying to do an AppSync query from my Android app with Amplify. I'm following the steps as in this page- https://aws-amplify.github.io/docs/android/api#run-a-query After executing the following code,

  public void query(){
        mAWSAppSyncClient.query(ListTodosQuery.builder().build())
                .responseFetcher(AppSyncResponseFetchers.CACHE_AND_NETWORK)
                .enqueue(todosCallback);
    } 

The GraphQL Callback response is supposed to be like:

{
  "data": {
    "listTodos": {
      "items": [
        {
          "id" : ...
        }]}}}

But I keep receiving the response as:

com.apollographql.apollo.api.Response@df0e853

It doesn't have any other data. Why is this so? Why is the response in this format?

(I tried running the listTodos query in the AppSync console and I get the right response there, with data and all the items in the DynamoDB)

jkeys
  • 3,803
  • 11
  • 39
  • 63
rS_
  • 131
  • 1
  • 1
  • 7

1 Answers1

2

com.apollographql.apollo.api.Response@df0e853 is the instance of the response object. You should be able to access response.data():

    private GraphQLCall.Callback<ListTodosQuery.Data> todosCallback = new GraphQLCall.Callback<ListTodosQuery.Data>() {
        @Override
        public void onResponse(@Nonnull Response<ListTodosQuery.Data> response) {
            Log.i("Results", response.data().listTodos().items().toString());
            // do something with response.data() here
        }
        // ...
    };
    ```
mbonnin
  • 6,893
  • 3
  • 39
  • 55
  • response.data() is always null. (the same query when run in the console gives the right data) – rS_ Oct 23 '19 at 13:47
  • 2
    Maybe there's something in response.errors() that would help you debug this? – mbonnin Oct 23 '19 at 21:47
  • Thanks for the reply. Yes, the response.hasErrors() is true. I have posted this issue in detail here: https://github.com/aws-amplify/aws-sdk-android/issues/1269 Even though I get the reponse.errors() message, I am not able to figure out where I'm going wrong. – rS_ Oct 24 '19 at 08:14