1

I am having trouble figuring out how to pass a parameter to a query. In this case, I want to get a user by name field. I know I can pass an id, but how do I pass another field? Do I need to create a secondary index?

        private AWSAppSyncClient mAWSAppSyncClient;
        mAWSAppSyncClient.query(GetUserQuery.builder().build())
                .responseFetcher(AppSyncResponseFetchers.CACHE_AND_NETWORK)
                .enqueue(userCallback);


query GetUser($id: ID!) {
  getUser(id: $id) {
    id
    userId
    name
    ...
  }
}

1 Answer 1

1

Use ListUsers (ListXXXX) to query with multiple parameters.

Example - query by name = "aaa":

ModelStringFilterInput modelStringFilterInput = ModelStringFilterInput.builder().eq("aaa").build();
ModelUserFilterInput modelUserFilterInput = ModelUserFilterInput.builder().name(modelStringFilterInput).build();
mAWSAppSyncClient.query(ListUsersQuery.builder().filter(modelUserFilterInput).build())
        .responseFetcher(AppSyncResponseFetchers.CACHE_AND_NETWORK)
        .enqueue(userCallback);


private GraphQLCall.Callback<ListUsersQuery.Data> userCallback = new GraphQLCall.Callback<ListUsersQuery.Data>() {
    @Override
    public void onResponse(@Nonnull Response<ListUsersQuery.Data> response) {
        Log.d(TAG, response.data().listUsers().items().toString());
    }

    @Override
    public void onFailure(@Nonnull ApolloException e) {
        Log.d(TAG, e.toString());
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.