#✅ - GraphQL query works in console but not on client

3 messages · Page 1 of 1 (latest)

gleaming mantle
#

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)")
        }
GitHub

Describe the bug 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 cons...

gleaming mantle
#

The issue was in my logic. Query was returning only 1 item but my if-statement conditional check was if (count > 1) which failed even though there was an item. Switching my logics to if (count >= 1) fixed the issue.

It is fixed now!!

crisp widgetBOT
#

✅ - GraphQL query works in console but not on client