aws-amplify/amplify-swift

Unable to fetch graphQL list whenever app coming to foreground from background.

Santosh2332 opened this issue · 3 comments

Describe the bug

I configured amplify successfully, where fetching list of data successfully, Auth type is API_KEY.
but whenever app is going into background and coming to foreground either list is empty or getting error-1005 network connection lost.

The code i implemented is:

       let amplifyModel = UserSession.keys
       let predicate = amplifyModel.email == email
       let limit = (isFromBackground) ? 1 : 1000
       
       let request = GraphQLRequest<UserSession>.list(UserSession.self, where: predicate, limit: limit)
       Task {
           do {
               let result = try await Amplify.API.query(request: request)
               switch result {
               case .success(let data):
                   print("Successfully retrieved list of data: \(data.count)")
               case .failure(let error):
                   print("Got failed result with \(error.errorDescription)")
               }
           } catch let error as APIError {
               print("Failed to query list of amplify model: ", error)
           } catch {
               print("Unexpected error: \(error)")
           }
       }

Steps To Reproduce

Steps to reproduce the behavior:
1. Run the app
2. then go to background 
3. wait for some time come again to foreground
4. and fetch the data

Expected behavior

Like when app is in active state, and functionality working fine.
Similerly after coming back to foreground the list of data should be fetched successfully

Amplify Framework Version

2.2

Amplify Categories

API

Dependency manager

Swift PM

Swift version

Swift 5.2

CLI version

12.12.4

Xcode version

14.2

Is this a regression?

Yes

Regression additional context

No response

Platforms

iOS

OS Version

15.2

Device

iPhone XR

Specific to simulators

No response

Additional context

No response

Thanks for opening this issue.

You mentioned you're using Amplify 2.2.0, is that correct?
That version was released in Dec 2022, please update to the latest one as there's been significant bug fixes since then.

Hi @ruisebas Thank you for reply.

Amplify version 2.33.7 also getting same result, if limit is 1 (if limit 10 then data fetched in the list)

5d commented

Hi @Santosh2332 ,

With the latest Amplify version (2.33.7), could you please provide us with the verbose log, ensuring that any sensitive information is properly redacted or obscured?

You can enable verbose logging to the console by doing this before calling Amplify.configure:

Amplify.Logging.logLevel = .verbose