Querying an index with Android Amplify GraphQL

0

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 { 
    id 
   } 
  } 
 }

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(
            document,
            mapOf("email" to email, "code" to code),
            ClubMember::class.java,
            GsonVariablesSerializer())
    }

and

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?

Thanks

gefragt vor 2 Jahren421 Aufrufe
1 Antwort
0

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.

beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen