Querying an index with Android Amplify GraphQL


I'm trying to perform a GraphQL query against an index using Amplify and the Android SDK.

I have a query that works when tested via the AppSync dashboard. It returns the one record I can see in DynamoDB that it should match against. membersEmailByInviteCode is an index defined in the Schema.

query get { 
  membersEmailByInviteCode(email: "test@example.com" inviteCode: { eq: "CustomCode"} ) { 
    items { 

When I enable CloudWatch Logs and run the query from within the code I can see the following being sent, but I get an empty object back, which I'm guessing means that it hasn't been able to find anything.

query get($email: String!, $code: String!) { membersEmailByInviteCode(email: $email inviteCode: { eq: $code} ) { items { id } } }, Operation: null, Variables: 
    "email": "test@example.com",
    "code": "CustomCode"

Operation is null, where it is get if I run the query via the console. I can't see a way of settings this.

The Android side of things look like this

   private fun getEmailCodeRequest(email: String, code: String): GraphQLRequest<ClubMember> {

        val document = (
                "query get(\$email: String!, \$code: String!) { "
                  + "membersEmailByInviteCode(email: \$email inviteCode: { eq: \$code} ) { "
                    + "items { "
                      + "id "
                    + "} "
                  + "} "
                + "}")

        return SimpleGraphQLRequest(
            mapOf("email" to email, "code" to code),


Amplify.API.query(getEmailCodeRequest(email.text.toString(), code.text.toString()),

I have been able to create a record using GraphQL, and I'm using auth and Rest API, so my app is working OK with the Android SDK. It just I can't get this to work.

Anyone got any ideas?


asked 2 months ago18 views
1 Answer

I thought I might get a Model object populated with just the id, but what I am getting is just a JSON string back. I needed to process the JSON to get the id from it.

answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions