I have opened github issue: https://github.com/aws-amplify/amplify-swift/issues/3707
I have a graphql query I send from swift, but it doesn't return anything. The query returns success, but the list of items is empty. If I run the same query in the appsync console, it returns a list of items. I did have latest amplify version and did run amplify codegen models, but same issue. It works sometimes on client and not other times.
MyModel is the model name. My model has an index with primary key on post_id and sort key on user_id
do
{
let model = MyModel.keys
let predicate = model.post_id == "POST_ID_TO_QUERY" && model.user_id == "USER_ID_TO_QUERY"
let request = GraphQLRequest<MyModel>.list(model.self, where: predicate, limit: 1000)
let result = try await Amplify.API.query(request: request)
switch result {
case .success(let models): // query returns .success with empty list
if (models.count > 1) {
return models[0]
}
return nil
case .failure(let error):
return nil
}
}
catch let error
{
print("Error getting model by post and user id: \(error)")
}