GithubHelp home page GithubHelp logo

Comments (5)

thisisabhash avatar thisisabhash commented on June 18, 2024

Thank you posting this issue - our team will investigate and post updates on this ticket.

from amplify-swift.

lawmicha avatar lawmicha commented on June 18, 2024

Hi @ip5038, I could not reproduce this issue, but as I was trying out the code snippet, I made a few changes to get it to work.

Task {
    do
    {
        let model = MyModel.keys
        let predicate = model.post_id == "1" && model.user_id == "1"
        let request = GraphQLRequest<MyModel>.list(MyModel.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) {
                print("count \(models.count)")
            }
            print(models)
            if models.hasNextPage() {
                print("Has Next Page")
                let nextPage = try await models.getNextPage()
            } else {
                print("No pages remaining")
            }
        case .failure(let error):
            print(error)
        }
    }
    catch let error
    {
        print("Error getting model by post and user id: \(error)")
    }
}
  • I noticed you used the coding key model.self instead of MyModel.self- this wasn't compiling for me, i assume this was already updated on your end
  • Added a few more print statements. case .failure(let error) is when there's a successful network request but categorized as a failure when there is a GraphQL errors array, partial data/errors response, or transformation (decoding) error. Is your code going into this line?
  • Added a check for hasNextPage(), this checks if the response contained the nextToken, used by getNextPage() for pagination. More details here https://docs.amplify.aws/gen1/swift/build-a-backend/graphqlapi/query-data/#list-subsequent-pages-of-items

In my amplify CLI project, i also have generatemodelsforlazyloadandcustomselectionset set to true before running amplify codegen models.

from amplify-swift.

ip5038 avatar ip5038 commented on June 18, 2024

It's still not working for me.

  • It never goes into the failure case. It always goes to success case with an empty list of items. There are also no next pages.
  • I changed generatemodelsforlazyloadandcustomselectionset to true and re-ran amplify codegen models then did clean build folder and reran the app, but still won't work.'
  • The entire do-catch block is in an async function.
  • I have multiple other Amplify queries and they are .get queries that query on the id field of the object. Those queries work fine.
  • If I pass in post_id that doesn't exist in dynamodDB, it still return .success with empty list.

This amplify query works fine:
let result = try await Amplify.API.query(request: .get(AnotherModel.self, byId: "some_id"))

I have attached a screenshot of logs for the .list query that doesn't work. Everything that is highlighted orange is from printf() statements. Rest is from amplify logs
Screenshot 2024-05-17 at 3 38 10 PM

from amplify-swift.

ip5038 avatar ip5038 commented on June 18, 2024

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.

Thank you for the help!

from amplify-swift.

github-actions avatar github-actions commented on June 18, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

from amplify-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.