Description
I've been following along the "Hello world" style notes tutorial for api and datastore.
API and DataStore seem to be working great independently but DataStore saves are not being pushed to the server. Ricardo on Twitter suggested I make this issue.
I'm adding a note with:
func addNoteWith(content: String) {
let newNote = Note(content: content)
Amplify.DataStore.save(newNote) { [unowned self] result in
switch result {
case .success(let note):
print("Saved note: \(note)")
self.notes.insert(note, at: 0)
case .failure(let error):
print("Error when saving note: \(error)")
}
}
}
This succeeds, but I do not see the note in my DynamoDB, which I expected to.
Adding a new note via the API works fine:
func addNoteWith(content: String) {
let newNote = Note(content: content)
_ = Amplify.API.mutate(of: newNote, type: .create) { event in
switch event {
case .completed(let result):
switch result {
case .success(let mutatedNote):
print("API mutate successful, created note: \(mutatedNote)")
case .failure(let error):
print("Mutated new note with error: \(error)")
}
case .failed(let error):
print("Failed to mutate new note: \(error)")
default:
print("Should never happen according to documentation")
}
}
}
These are the notes created via Amplify.API:
And these appear in the database:
But the notes created with Amplify.DataStore.save are not there, but can still be queried locally:
I've found the AWSDataStorePlugin.isSyncEnabled
and this is getting configured to true:
This is then passed to StorageEngine:
Which creates a RemoteSyncEngine:
Saving a Note successfully calls StorageEngine.syncMutation:
Which in turn successfully calls submitToSyncEngine:
This successfully goes through to:
RemoteSyncEngine.submit
AWSMutationDatabaseAdapter.submit
AWSMutationDatabaseAdapter.resolveConflictsThenSave
MutationEvent.pendingMutationEvents completes with a success.
This enters AWSMutationDatabaseAdapter.resolve with a disposition of .saveCandidate
This enters AWSMutationDatabaseAdapter.save which calls SQLiteStorageEngineAdapter.save which succeeds.
I don't have logging installed at the moment but that's the next thing I'm going to do to see if it reveals the problem.
Installed via Cocoapods:
pod 'amplify-tools'
pod 'Amplify'
pod 'AWSPluginsCore'
pod 'AmplifyPlugins/AWSAPIPlugin'
pod 'AmplifyPlugins/AWSDataStorePlugin'
Exact versions:
PODS:
- Amplify (0.10.0)
- amplify-tools (0.2.0)
- AmplifyPlugins/AWSAPIPlugin (0.10.0):
- AWSPluginsCore (= 0.10.0)
- ReachabilitySwift (~> 5.0.0)
- Starscream (~> 3.0.2)
- AmplifyPlugins/AWSDataStorePlugin (0.10.0):
- AWSPluginsCore (= 0.10.0)
- SQLite.swift (~> 0.12.0)
- AWSAuthCore (2.12.7):
- AWSCore (= 2.12.7)
- AWSCognitoIdentityProvider (2.12.7):
- AWSCognitoIdentityProviderASF (= 1.0.1)
- AWSCore (= 2.12.7)
- AWSCognitoIdentityProviderASF (1.0.1)
- AWSCore (2.12.7)
- AWSMobileClient (2.12.7):
- AWSAuthCore (= 2.12.7)
- AWSCognitoIdentityProvider (= 2.12.7)
- AWSPluginsCore (0.10.0):
- Amplify (= 0.10.0)
- AWSMobileClient (~> 2.12.2)
- ReachabilitySwift (5.0.0)
- SQLite.swift (0.12.2):
- SQLite.swift/standard (= 0.12.2)
- SQLite.swift/standard (0.12.2)
- Starscream (3.0.6)
Xcode 11.3.1
Swift 5.1
This has been tested on simulators running iOS 13.3 and a real device running 13.3.1