amplify-swift: DataStore fails to sync data

Describe the bug

Datastore is falling to sync data from the cloud with decoding errors.

Steps To Reproduce

1. Set up a clean project with the following auth: 
   2.1. Cognito as the primary auth and API Key as the secondary.
   2.1. Select to auto merge and resolve conflicts.
2. Complete setup and push
2. Ensure the cloud tables have data items.
3. Start the application.

Expected behavior

To pull and populate local datastore tables with data from the cloud.

Amplify Framework Version

1.17.0

Amplify Categories

API, Auth, DataStore

Dependency manager

Swift PM

Swift version

5.3.2

CLI version

7.6.3

Xcode version

12.4 (12D4e)

Relevant log output

2021-12-15 11:21:50.980256+0000 <APP_NAME>[39863:155273] [RetryableGraphQLSubscriptionOperation<MutationSync<AnyModel>>] APIError: Subscription item event failed with error
Caused by:
jsonParse(nil, Optional(Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "type", intValue: nil)], debugDescription: "Cannot initialize RealtimeConnectionProviderResponseType from invalid String value connection_error", underlyingError: nil))))

Is this a regression?

No

Regression additional context

No response

Device

iPhone 12 Pro Simulator

iOS Version

iOS 14.4

Specific to simulators

No response

Additional context

Application Log ApplicationConsolLog.log

schema.graphql schema.txt

Plugin Configuration within AppDelegate

public var syncDate: Temporal.DateTime? = Temporal.DateTime.init(Date())

do {
            try Amplify.add(plugin: AWSCognitoAuthPlugin())
            
            let apiPlugin: AWSAPIPlugin = AWSAPIPlugin(modelRegistration: AmplifyModels())
            try Amplify.add(plugin: apiPlugin)
            
            var syncExpressions: [DataStoreSyncExpression] = []
            
            //sync two weeks worth of data
            let calendar: Calendar = .iso8601
            let date: Date = calendar.date(byAdding: .day, value: -14, to: Date().startOfWeek())!
            syncDate = Temporal.DateTime.init(date)
            let mealPlanSyncExpr: DataStoreSyncExpression = DataStoreSyncExpression.syncExpression(MealPlan.schema) {
                guard let syncDate = syncDate else {
                    return QueryPredicateConstant.all
                }
                return MealPlan.keys.startDateTime.ge(syncDate)
            }
            syncExpressions.append(mealPlanSyncExpr)
            
            let userProfileSyncExpr: DataStoreSyncExpression = DataStoreSyncExpression.syncExpression(UserProfile.schema) {
                return QueryPredicateConstant.all
            }
            syncExpressions.append(userProfileSyncExpr)
            
            let datastoreConfiguration: DataStoreConfiguration = DataStoreConfiguration.custom(syncExpressions: syncExpressions, authModeStrategy: .multiAuth)
            let dataStorePlugin: AWSDataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels(),
                                                     configuration: datastoreConfiguration)
            
            try Amplify.add(plugin: dataStorePlugin)
            
            try Amplify.configure()
            logger?.log(type: .debug, category: .app, message: "Initialized Amplify")
            
        } catch {
            logger?.log(type: .error, category: .app, message: "Failed to initialize Amplify with \(error)")
        }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Closing due to inactivity, feel free to reopen if you still need help.

Small Update. Out of curiosity, I thought to download the awsconfiguration.json file from the app sync console and realised that my API Key name did not match. Unfortunately, I am unable to test if this will resolve my issue due the compilation errors

/Users/<USER_DIR>/Library/Developer/Xcode/DerivedData/<APP_NAME>-fkchuwvzgbhvchfkfrwkeviqnbqn/Build/Products/Debug-iphonesimulator/AWSMobileClientXCF.framework/Modules/AWSMobileClientXCF.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:8:8: No such module '_Concurrency'

and Existing open issue - https://github.com/aws-amplify/aws-sdk-ios/issues/3795 /Users/<USER_DIR>/Library/Developer/Xcode/DerivedData/<APP_NAME>-fkchuwvzgbhvchfkfrwkeviqnbqn/SourcePackages/checkouts/amplify-ios/AmplifyPlugins/Auth/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift:15:8: Failed to build module 'AWSMobileClientXCF' from its module interface; the compiler that produced it, 'Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)'

Not sure if this helps but I just removed the project and started from the beginning after running amplify configure and add api. Migrated my schema to use the latest syntax and structure I then ran code gen and push and I noticed the following error:

✔ Generated GraphQL operations successfully and saved at graphql Code generation failed with the following error ENOENT: no such file or directory, lstat '<PROJECT_FILE_LOCATION>/amplify/#current-cloud-backend/auth/***465c8f7a'. ✔ All resources are updated in the cloud

Xcode build produces the following error (This might be resolved if I upgrade my OS, not ideal but worth a try):

/Users/<USER>/Library/Developer/Xcode/DerivedData/<PROJECT_BUILD>/SourcePackages/checkouts/amplify-ios/AmplifyPlugins/Auth/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift:15:8: Failed to build module 'AWSMobileClientXCF' from its module interface; the compiler that produced it, 'Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)', may have used features that aren't supported by this compiler, 'Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)'