Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore not syncing with AppSync #340

Closed
James-Coleman opened this issue Feb 27, 2020 · 38 comments
Closed

Datastore not syncing with AppSync #340

James-Coleman opened this issue Feb 27, 2020 · 38 comments
Assignees
Labels
datastore Issues related to the DataStore category

Comments

@James-Coleman
Copy link

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:
Simulator Screen Shot - iPhone 11 Pro Max - 2020-02-27 at 16 08 36

And these appear in the database:
Screenshot 2020-02-27 at 16 08 47

But the notes created with Amplify.DataStore.save are not there, but can still be queried locally:
Simulator Screen Shot - iPhone 11 Pro Max - 2020-02-27 at 16 12 25

I've found the AWSDataStorePlugin.isSyncEnabled and this is getting configured to true:
Screenshot 2020-02-27 at 16 27 51

This is then passed to StorageEngine:
Screenshot 2020-02-27 at 16 31 19

Which creates a RemoteSyncEngine:
Screenshot 2020-02-27 at 16 32 42

Saving a Note successfully calls StorageEngine.syncMutation:
Screenshot 2020-02-27 at 16 38 37

Which in turn successfully calls submitToSyncEngine:
Screenshot 2020-02-27 at 16 40 51

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

@James-Coleman
Copy link
Author

Meant to include the following config info:

amplifyxc.config:

push=true
modelgen=true
profile=default
envName=amplify

awsconfiguration.json

{
    "UserAgent": "aws-amplify/cli",
    "Version": "0.1.0",
    "IdentityManager": {
        "Default": {}
    },
    "AppSync": {
        "Default": {
            "ApiUrl": "REDACTED",
            "Region": "eu-west-1",
            "AuthMode": "API_KEY",
            "ApiKey": "REDACTED",
            "ClientDatabasePrefix": "amplifyDatasource_API_KEY"
        }
    }
}

amplifyconfiguration.json:

{
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "amplifyDatasource": {
                    "endpointType": "GraphQL",
                    "endpoint": "REDACTED",
                    "region": "eu-west-1",
                    "authorizationType": "API_KEY",
                    "apiKey": "REDACTED"
                }
            }
        }
    }
}

Any other setup files that might be useful?

@James-Coleman
Copy link
Author

James-Coleman commented Feb 27, 2020

I've enabled verbose logging and saving a new note called "6" in the DataStore prints the following:

Click to expand
2020-02-27 17:32:37.348115+0000 AmplifyDatastoreDemo[4543:10606600] [AWSDataStorePlugin] Saving: Note(id: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", content: "6")
2020-02-27 17:32:37.348334+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.348672+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.348994+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.349319+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] insert into Note ("id", "content")
values ('8FEC3592-B3E9-43B6-99F6-BFD3F5E10594', '6')
2020-02-27 17:32:37.351087+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.351340+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.371807+0000 AmplifyDatastoreDemo[4543:10606600] [StorageEngine] save(_:completion:) syncing mutation for Note(id: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", content: "6")
2020-02-27 17:32:37.372110+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] submit(mutationEvent:): MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false)
2020-02-27 17:32:37.372459+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.372685+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.373232+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-02-27 17:32:37.373453+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-02-27 17:32:37.377660+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] disposition(for:given:) no local events, saving candidate
2020-02-27 17:32:37.377781+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] resolve(candidate:localEvents:per:storageAdapter:completionPromise:) disposition saveCandidate
2020-02-27 17:32:37.377976+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:) mutationEvent: MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false)
2020-02-27 17:32:37.378142+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select count(id) from MutationEvent where id = '75B50C20-282A-483D-867A-8D92B3662D2B'
2020-02-27 17:32:37.378658+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] insert into MutationEvent ("id", "createdAt", "inProcess", "json", "modelId", "modelName", "mutationType", "version")
values ('75B50C20-282A-483D-867A-8D92B3662D2B', '2020-02-27T17:32:37.372Z', 0, '{"id":"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594","content":"6"}', '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594', 'Note', 'create', NULL)
2020-02-27 17:32:37.380295+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '75B50C20-282A-483D-867A-8D92B3662D2B'
2020-02-27 17:32:37.380536+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '75B50C20-282A-483D-867A-8D92B3662D2B'
2020-02-27 17:32:37.381439+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): saved MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false)
2020-02-27 17:32:37.381652+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): invoking nextEventPromise with MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false)
2020-02-27 17:32:37.381766+0000 AmplifyDatastoreDemo[4543:10606600] [OutgoingMutationQueue] receive(_:)
2020-02-27 17:32:37.381876+0000 AmplifyDatastoreDemo[4543:10606600] [OutgoingMutationQueue] enqueue(_:)
2020-02-27 17:32:37.382084+0000 AmplifyDatastoreDemo[4543:10606600] [StateMachine<State, Action>] Notifying: enqueuedEvent
2020-02-27 17:32:37.382129+0000 AmplifyDatastoreDemo[4543:10608077] [SyncMutationToCloudOperation] main()
2020-02-27 17:32:37.382224+0000 AmplifyDatastoreDemo[4543:10608077] [SyncMutationToCloudOperation] sendMutationToCloud()
2020-02-27 17:32:37.382254+0000 AmplifyDatastoreDemo[4543:10606600] [StateMachine<State, Action>] resolve(requestingEvent, enqueuedEvent) -> waitingForEventToProcess
2020-02-27 17:32:37.382351+0000 AmplifyDatastoreDemo[4543:10606600] [OutgoingMutationQueue] New state: waitingForEventToProcess
2020-02-27 17:32:37.382528+0000 AmplifyDatastoreDemo[4543:10610096] [OutgoingMutationQueue] respond(to:): waitingForEventToProcess
2020-02-27 17:32:37.382609+0000 AmplifyDatastoreDemo[4543:10608077] [SyncMutationToCloudOperation] makeAPIRequest(_:) sending mutation with sync data: GraphQLRequest<MutationSync<AnyModel>>(apiName: nil, document: "mutation CreateNote($input: CreateNoteInput!) {\n  createNote(input: $input) {\n    id\n    content\n    __typename\n    _version\n    _deleted\n    _lastChangedAt\n  }\n}", variables: Optional(["input": ["id": Optional("8FEC3592-B3E9-43B6-99F6-BFD3F5E10594"), "content": Optional("6")]]), responseType: AWSPluginsCore.MutationSync<Amplify.AnyModel>, decodePath: Optional("createNote"))
2020-02-27 17:32:37.382636+0000 AmplifyDatastoreDemo[4543:10606600] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): invoking completionPromise with success(Amplify.MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false))
2020-02-27 17:32:37.382833+0000 AmplifyDatastoreDemo[4543:10610096] [API] Starting mutation 063C6468-5114-41F1-8043-4D44DAC22AC9
2020-02-27 17:32:37.387386+0000 AmplifyDatastoreDemo[4543:10606600] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) saved mutation event: MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false)
2020-02-27 17:32:37.387447+0000 AmplifyDatastoreDemo[4543:10610096] [API] Starting network task for mutation 063C6468-5114-41F1-8043-4D44DAC22AC9
2020-02-27 17:32:37.387594+0000 AmplifyDatastoreDemo[4543:10606600] [StorageEngine] syncMutation(of:mutationType:syncEngine:completion:) successfully submitted to sync engine MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false)
2020-02-27 17:32:37.388507+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
2020-02-27 17:32:37.388735+0000 AmplifyDatastoreDemo[4543:10606600] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8FEC3592-B3E9-43B6-99F6-BFD3F5E10594'
Saved note: Note(id: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", content: "6")
2020-02-27 17:32:37.389185+0000 AmplifyDatastoreDemo[4543:10606600] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) Received successful completion
2020-02-27 17:32:37.488758+0000 AmplifyDatastoreDemo[4543:10610105] [SyncMutationToCloudOperation] sendMutationToCloud received asyncEvent: completed
2020-02-27 17:32:37.489014+0000 AmplifyDatastoreDemo[4543:10610105] [SQLiteStorageEngineAdapter] delete from MutationEvent as root
where 1 = 1
  and "root"."id" = '75B50C20-282A-483D-867A-8D92B3662D2B'
2020-02-27 17:32:37.490914+0000 AmplifyDatastoreDemo[4543:10610105] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '75B50C20-282A-483D-867A-8D92B3662D2B'
2020-02-27 17:32:37.491236+0000 AmplifyDatastoreDemo[4543:10610105] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '75B50C20-282A-483D-867A-8D92B3662D2B'
2020-02-27 17:32:37.491772+0000 AmplifyDatastoreDemo[4543:10608077] [OutgoingMutationQueue] mutationEvent finished: MutationEvent(id: "75B50C20-282A-483D-867A-8D92B3662D2B", modelId: "8FEC3592-B3E9-43B6-99F6-BFD3F5E10594", modelName: "Note", json: "{\"id\":\"8FEC3592-B3E9-43B6-99F6-BFD3F5E10594\",\"content\":\"6\"}", mutationType: "create", createdAt: 2020-02-27 17:32:37 +0000, version: nil, inProcess: false); result: completed
2020-02-27 17:32:37.561453+0000 AmplifyDatastoreDemo[4543:10608077] [StateMachine<State, Action>] Notifying: processedEvent
2020-02-27 17:32:37.561625+0000 AmplifyDatastoreDemo[4543:10608077] [StateMachine<State, Action>] resolve(waitingForEventToProcess, processedEvent) -> requestingEvent
2020-02-27 17:32:37.561760+0000 AmplifyDatastoreDemo[4543:10608077] [OutgoingMutationQueue] New state: requestingEvent
2020-02-27 17:32:37.561930+0000 AmplifyDatastoreDemo[4543:10608077] [OutgoingMutationQueue] respond(to:): requestingEvent
2020-02-27 17:32:37.562049+0000 AmplifyDatastoreDemo[4543:10608077] [OutgoingMutationQueue] requestEvent()
2020-02-27 17:32:37.562187+0000 AmplifyDatastoreDemo[4543:10608077] [AWSMutationDatabaseAdapter] getNextMutationEvent(completion:)
2020-02-27 17:32:37.564943+0000 AmplifyDatastoreDemo[4543:10608077] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
LIMIT 1
2020-02-27 17:32:37.565231+0000 AmplifyDatastoreDemo[4543:10608077] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
LIMIT 1

@drochetti
Copy link
Contributor

Hi @James-Coleman

Firs of all, thank you for creating such a comprehensive issue report. This is really helpful and also motivating to see the dev community diving so deep into our code.

Secondly, my immediate recommendation would be to try the latest version of our code directly from the master branch. We will release a new version of Amplify iOS in the next days, so the master branch has tons of unreleased bug fixes, including a lot of work we did on the sync engine. of DataStore. Can you pull the pods straight from the master branch and give it a try?

    pod 'Amplify', :git => 'https://github.com/aws-amplify/amplify-ios.git'
    pod 'AWSPluginsCore', :git => 'https://github.com/aws-amplify/amplify-ios.git'
    pod 'AmplifyPlugins/AWSAPIPlugin', :git => 'https://github.com/aws-amplify/amplify-ios.git'
    pod 'AmplifyPlugins/AWSDataStorePlugin', :git => 'https://github.com/aws-amplify/amplify-ios.git'

@drochetti drochetti added the datastore Issues related to the DataStore category label Feb 27, 2020
@James-Coleman
Copy link
Author

James-Coleman commented Feb 27, 2020

@drochetti If I'm honest I was just rubber ducking with myself, trying to find where I'd gone wrong.

I updated the Podfile to point directly to the master branch as per your suggestion, deleted the Podfile.lock file, installed the pods, cleaned the project, deleted the app from the simulator and then ran it again, but it still appears to not be sending Amplify.DataStore.save() events to the server, whereas Amplify.API.mutate() is working no problem.

The stack looks the same:
Screenshot 2020-02-27 at 21 34 56

Is it worth me starting from scratch with pods from the master branch in case the setup scripts have changed?

Here's the verbose logs from save a note with the content "clean slate 4":

Click to expand
2020-02-27 21:40:06.762058+0000 AmplifyDatastoreDemo[8276:10663207] [AWSDataStorePlugin] Saving: Note(id: "FE051715-01C2-424C-9331-4291BCFBFD57", content: "clean slate 4")
2020-02-27 21:40:06.762282+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select count(id) from Note where id = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.762625+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select count(id) from Note where id = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.762881+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select count(id) from Note where id = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.763219+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] insert into Note ("id", "content")
values ('FE051715-01C2-424C-9331-4291BCFBFD57', 'clean slate 4')
2020-02-27 21:40:06.766465+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.766715+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.811094+0000 AmplifyDatastoreDemo[8276:10663207] [StorageEngine] save(_:completion:) syncing mutation for Note(id: "FE051715-01C2-424C-9331-4291BCFBFD57", content: "clean slate 4")
2020-02-27 21:40:06.811383+0000 AmplifyDatastoreDemo[8276:10663207] [AWSMutationDatabaseAdapter] submit(mutationEvent:): MutationEvent(id: "40EFA9C8-1A5B-4523-A8BD-776855C01CE5", modelId: "FE051715-01C2-424C-9331-4291BCFBFD57", modelName: "Note", json: "{\"id\":\"FE051715-01C2-424C-9331-4291BCFBFD57\",\"content\":\"clean slate 4\"}", mutationType: "create", createdAt: 2020-02-27 21:40:06 +0000, version: nil, inProcess: false)
2020-02-27 21:40:06.811699+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.811916+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.812468+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-02-27 21:40:06.812689+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-02-27 21:40:06.812953+0000 AmplifyDatastoreDemo[8276:10663207] [AWSMutationDatabaseAdapter] disposition(for:given:) no local events, saving candidate
2020-02-27 21:40:06.813063+0000 AmplifyDatastoreDemo[8276:10663207] [AWSMutationDatabaseAdapter] resolve(candidate:localEvents:per:storageAdapter:completionPromise:) disposition saveCandidate
2020-02-27 21:40:06.813254+0000 AmplifyDatastoreDemo[8276:10663207] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:) mutationEvent: MutationEvent(id: "40EFA9C8-1A5B-4523-A8BD-776855C01CE5", modelId: "FE051715-01C2-424C-9331-4291BCFBFD57", modelName: "Note", json: "{\"id\":\"FE051715-01C2-424C-9331-4291BCFBFD57\",\"content\":\"clean slate 4\"}", mutationType: "create", createdAt: 2020-02-27 21:40:06 +0000, version: nil, inProcess: false)
2020-02-27 21:40:06.813432+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select count(id) from MutationEvent where id = '40EFA9C8-1A5B-4523-A8BD-776855C01CE5'
2020-02-27 21:40:06.813970+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] insert into MutationEvent ("id", "createdAt", "inProcess", "json", "modelId", "modelName", "mutationType", "version")
values ('40EFA9C8-1A5B-4523-A8BD-776855C01CE5', '2020-02-27T21:40:06.811Z', 0, '{"id":"FE051715-01C2-424C-9331-4291BCFBFD57","content":"clean slate 4"}', 'FE051715-01C2-424C-9331-4291BCFBFD57', 'Note', 'create', NULL)
2020-02-27 21:40:06.815429+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '40EFA9C8-1A5B-4523-A8BD-776855C01CE5'
2020-02-27 21:40:06.815681+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '40EFA9C8-1A5B-4523-A8BD-776855C01CE5'
2020-02-27 21:40:06.816620+0000 AmplifyDatastoreDemo[8276:10663207] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): saved MutationEvent(id: "40EFA9C8-1A5B-4523-A8BD-776855C01CE5", modelId: "FE051715-01C2-424C-9331-4291BCFBFD57", modelName: "Note", json: "{\"id\":\"FE051715-01C2-424C-9331-4291BCFBFD57\",\"content\":\"clean slate 4\"}", mutationType: "create", createdAt: 2020-02-27 21:40:06 +0000, version: nil, inProcess: false)
2020-02-27 21:40:06.816848+0000 AmplifyDatastoreDemo[8276:10663207] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): invoking completionPromise with success(Amplify.MutationEvent(id: "40EFA9C8-1A5B-4523-A8BD-776855C01CE5", modelId: "FE051715-01C2-424C-9331-4291BCFBFD57", modelName: "Note", json: "{\"id\":\"FE051715-01C2-424C-9331-4291BCFBFD57\",\"content\":\"clean slate 4\"}", mutationType: "create", createdAt: 2020-02-27 21:40:06 +0000, version: nil, inProcess: false))
2020-02-27 21:40:06.817079+0000 AmplifyDatastoreDemo[8276:10663207] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) saved mutation event: MutationEvent(id: "40EFA9C8-1A5B-4523-A8BD-776855C01CE5", modelId: "FE051715-01C2-424C-9331-4291BCFBFD57", modelName: "Note", json: "{\"id\":\"FE051715-01C2-424C-9331-4291BCFBFD57\",\"content\":\"clean slate 4\"}", mutationType: "create", createdAt: 2020-02-27 21:40:06 +0000, version: nil, inProcess: false)
2020-02-27 21:40:06.817283+0000 AmplifyDatastoreDemo[8276:10663207] [StorageEngine] syncMutation(of:mutationType:syncEngine:completion:) successfully submitted to sync engine MutationEvent(id: "40EFA9C8-1A5B-4523-A8BD-776855C01CE5", modelId: "FE051715-01C2-424C-9331-4291BCFBFD57", modelName: "Note", json: "{\"id\":\"FE051715-01C2-424C-9331-4291BCFBFD57\",\"content\":\"clean slate 4\"}", mutationType: "create", createdAt: 2020-02-27 21:40:06 +0000, version: nil, inProcess: false)
2020-02-27 21:40:06.817670+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
2020-02-27 21:40:06.817882+0000 AmplifyDatastoreDemo[8276:10663207] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = 'FE051715-01C2-424C-9331-4291BCFBFD57'
Saved note: Note(id: "FE051715-01C2-424C-9331-4291BCFBFD57", content: "clean slate 4")
2020-02-27 21:40:06.818296+0000 AmplifyDatastoreDemo[8276:10663207] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) Received successful completion

@James-Coleman
Copy link
Author

My issue is possibly related to #265 because I noticed that my Amplify.Datastore.query is not returning objects from the server either.

@drochetti
Copy link
Contributor

My issue is possibly related to #265 because I noticed that my Amplify.Datastore.query is not returning objects from the server either.

Amplify.DataStore.query only queries from the local storage, the sync between the server and the local storage is suppose to happen in the background automatically.

@drochetti
Copy link
Contributor

I was able to reproduce the issue when creating a new app from scratch and I see the following GraphQL errors in the logs:

2020-02-27 16:13:00.808112-0800 AmplifyDataStoreDemo[49880:12249000] WebsocketDidReceiveMessage -
{
  "type":"error","id":"3F4D4DC3-3CF9-466B-85DA-5EB0DA07C133",
  "payload":{
    "errors":[{
        "message":"Validation error of type FieldUndefined: Field '_version' in type 'Todo' is undefined @ 'onDeleteTodo/_version'"
      },
      {
        "message":"Validation error of type FieldUndefined: Field '_deleted' in type 'Todo' is undefined @ 'onDeleteTodo/_deleted'"
      },
      {
        "message":"Validation error of type FieldUndefined: Field '_lastChangedAt' in type 'Todo' is undefined @ 'onDeleteTodo/_lastChangedAt'"
      }
    ]
  }
}

This seems to be related to this issue aws-amplify/amplify-js#4535
Which means the provisioned API has no syncing capabilities by default and needs to be enabled. I'll confirm the correct flow and get back to you.

@drochetti
Copy link
Contributor

Hi @James-Coleman,

I was able to identify the problem. This is related to some other issues we're tracking. Basically DataStore sync capabilities only work when your API was created with conflict resolution enabled. That is part of the "Advanced settings" when you run amplify add api.

Since you already created your API, you can run amplify update api and:

? Please select from one of the below mentioned services: GraphQL
? Choose the default authorization type for the API API key
? Enter a description for the API key: datastore-demo-key
? After how many days from now the API key should expire (1-365): 365
? Do you want to configure advanced settings for the GraphQL API Yes, I want to make some additional changes.
? Configure additional auth types? No
? Configure conflict detection? Yes
? Select the default resolution strategy Auto Merge
? Do you want to override default per model settings? No

The important setting is when you're asked Do you want to configure advanced settings for the GraphQL API, answer yes and on Configure conflict detection? also pick yes.

Now, when you execute your app again, all the local Data you had created before should be synced to the cloud and available to you in the AppSync console.

Again, thanks for reporting this, I'm talking to the CLI team in order to improve this flow for all platforms to improve the DataStore setup process.

Related PR: aws-amplify/amplify-cli#3495

@James-Coleman
Copy link
Author

@drochetti

Good news and bad news

After running the commands you suggested, I seemed to get a new table in DynamoDB called "AmplifyDataStore" where new Notes created via both API and DataStore are sent as well as my "Note" table. After some time the AmplifyDataStore table seems to get cleared out, but this might be expected?

However, I had to downgrade to the published CocoaPod version. In master branch, Notes added via DataStore were still not appearing on the web.

Even in the CocoaPod version, Notes added via API are not appearing in DataStore.query.

@ghost
Copy link

ghost commented Mar 1, 2020

@drochetti

Good news and bad news

After running the commands you suggested, I seemed to get a new table in DynamoDB called "AmplifyDataStore" where new Notes created via both API and DataStore are sent as well as my "Note" table. After some time the AmplifyDataStore table seems to get cleared out, but this might be expected?

However, I had to downgrade to the published CocoaPod version. In master branch, Notes added via DataStore were still not appearing on the web.

Even in the CocoaPod version, Notes added via API are not appearing in DataStore.query.

Facing exactly the same problem here. Saving and querying from local is fine but data sync on DynamoDB is not working.

@drochetti
Copy link
Contributor

@drochetti

Good news and bad news

After running the commands you suggested, I seemed to get a new table in DynamoDB called "AmplifyDataStore" where new Notes created via both API and DataStore are sent as well as my "Note" table. After some time the AmplifyDataStore table seems to get cleared out, but this might be expected?

The AmplifyDataStore table is a sign that the DataStore SyncEngine is working. That table is managed by AWS AppSync to deal with changes across different instances of your application (i.e. different users on iOS, or an user on iOS and another user on JS). Therefore, you don't have to worry about it getting cleared, that's the expected behavior.

However, I had to downgrade to the published CocoaPod version. In master branch, Notes added via DataStore were still not appearing on the web.

Even in the CocoaPod version, Notes added via API are not appearing in DataStore.query.

Can you clarify what you mean by "In master branch, Notes added via DataStore were still not appearing on the web"? When you say Web do you mean the DynamoDB Web Console?

@James-Coleman
Copy link
Author

James-Coleman commented Mar 2, 2020 via email

@drochetti
Copy link
Contributor

@James-Coleman and @jackatkoeln So, even after enabling the conflict resolution on the API you're still not getting the local persisted models synced to your DynamoDB. Did you see error messages like the ones I posted here #340 (comment) in your logs?

@hatunike
Copy link

hatunike commented Mar 3, 2020

I'm in a similar boat. Having worked my way through the documentation I'm experiencing similar issues.

Adding objects or even just querying objects gives :

Error adding Employee - The operation couldn't be completed. (Amplify.DataStoreError error 7.)

Amplify.API.mutate() seems to work, but not Amplify.DataStore.save()

This is after pointing at master as well as enabling conflict resolution.

(I'm also seeing the DynamoDB called "AmplifyDataStore")

@James-Coleman
Copy link
Author

James-Coleman commented Mar 4, 2020

@drochetti

I'm seeing Note objects added via both Amplify.API.mutate(of: newNote, type: .create) and Amplify.DataStore.save(newNote) added to both the AmplifyDataStore table, and the Note table.
What's missing for me is Notes being synced from DynamoDB to local DataStore. Amplify.DataStore.query() is still only returning local results.

This is with the CocoaPods version (0.10.0). As mentioned above, the master branch wasn't working for me earlier but I'll try again.

After creating a Note called "new via api" and uploading via Amplify.API.mutate(), I got the following logs, which does mention an error:

Click to expand
2020-03-04 12:37:13.426588+0000 AmplifyDatastoreDemo[96352:14593332] [API] Starting mutation 033EBCA0-E910-4614-A5B5-AC2D5E8F8830
2020-03-04 12:37:13.426896+0000 AmplifyDatastoreDemo[96352:14593332] [API] Starting network task for mutation 033EBCA0-E910-4614-A5B5-AC2D5E8F8830
API mutate successful, created note: Note(id: "D60C2FD4-F01B-417D-BC6E-BAE10C67AEA7", content: "new via api")
2020-03-04 12:37:13.816033+0000 AmplifyDatastoreDemo[96352:14590977] [API] WebsocketDidReceiveMessage - {"type":"data","id":"D7A65BE0-737F-46DB-95D0-EF92B320FFC3","payload":{"data":{"onCreateNote":null},"errors":[{"message":"Cannot return null for non-nullable type: 'Int' within parent 'Note' (/onCreateNote/_version)","path":["onCreateNote","_version"]},{"message":"Cannot return null for non-nullable type: 'AWSTimestamp' within parent 'Note' (/onCreateNote/_lastChangedAt)","path":["onCreateNote","_lastChangedAt"]}]}}
2020-03-04 12:37:13.817343+0000 AmplifyDatastoreDemo[96352:14593332] [IncomingAsyncSubscriptionEventPublisher] onCreateListener: failed
2020-03-04 12:37:13.817461+0000 AmplifyDatastoreDemo[96352:14593332] [IncomingAsyncSubscriptionEventToAnyModelMapper] receive(_:): failed
2020-03-04 12:37:13.824588+0000 AmplifyDatastoreDemo[96352:14593332] [IncomingAsyncSubscriptionEventToAnyModelMapper] The operation couldn’t be completed. (Amplify.DataStoreError error 0.)
2020-03-04 12:37:13.824818+0000 AmplifyDatastoreDemo[96352:14593332] [AWSModelReconciliationQueue] receiveCompletion: error: DataStoreError: Failed to deserialize
Caused by:
APIError: Failed to deserialize
Caused by:
DataStoreError: The key `__typename` was not found
Recovery suggestion: Check if the parsed JSON contains the expected `__typename`
2020-03-04 12:37:13.926929+0000 AmplifyDatastoreDemo[96352:14590977] [API] WebsocketDidReceiveMessage - {"type":"data","id":"64885CB4-0F8A-47F5-B438-8C0D51A73242","payload":{"data":{"onCreateNote":{"__typename":"Note","content":"new via api","id":"D60C2FD4-F01B-417D-BC6E-BAE10C67AEA7"}}}}
2020-03-04 12:37:17.582199+0000 AmplifyDatastoreDemo[96352:14590977] [API] WebsocketDidReceiveMessage - {"type":"ka"}

After creating a Note called "new via datastore" and saving with Amplify.DataStore.save(), I get the following logs which do not mention an error:

Click to expand
2020-03-04 12:41:17.223412+0000 AmplifyDatastoreDemo[96352:14590977] [AWSDataStorePlugin] Saving: Note(id: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", content: "new via datastore")
2020-03-04 12:41:17.223625+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.224677+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.224867+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.225159+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] insert into Note ("id", "content")
values ('7DC16A73-06B8-4B45-892E-AC8CBC9C0135', 'new via datastore')
2020-03-04 12:41:17.226809+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.226998+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.236386+0000 AmplifyDatastoreDemo[96352:14590977] [StorageEngine] save(_:completion:) syncing mutation for Note(id: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", content: "new via datastore")
2020-03-04 12:41:17.237650+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] submit(mutationEvent:): MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false)
2020-03-04 12:41:17.238395+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.238918+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.239527+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-03-04 12:41:17.240047+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-03-04 12:41:17.240247+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] disposition(for:given:) no local events, saving candidate
2020-03-04 12:41:17.240387+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] resolve(candidate:localEvents:per:storageAdapter:completionPromise:) disposition saveCandidate
2020-03-04 12:41:17.240560+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:) mutationEvent: MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false)
2020-03-04 12:41:17.240709+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select count(id) from MutationEvent where id = '7EEABE9A-BF57-432E-8B9A-7CFC65024F44'
2020-03-04 12:41:17.242690+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] insert into MutationEvent ("id", "createdAt", "inProcess", "json", "modelId", "modelName", "mutationType", "version")
values ('7EEABE9A-BF57-432E-8B9A-7CFC65024F44', '2020-03-04T12:41:17.237Z', 0, '{"id":"7DC16A73-06B8-4B45-892E-AC8CBC9C0135","content":"new via datastore"}', '7DC16A73-06B8-4B45-892E-AC8CBC9C0135', 'Note', 'create', NULL)
2020-03-04 12:41:17.243914+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '7EEABE9A-BF57-432E-8B9A-7CFC65024F44'
2020-03-04 12:41:17.244077+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '7EEABE9A-BF57-432E-8B9A-7CFC65024F44'
2020-03-04 12:41:17.246185+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): saved MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false)
2020-03-04 12:41:17.246343+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): invoking nextEventPromise with MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false)
2020-03-04 12:41:17.246439+0000 AmplifyDatastoreDemo[96352:14590977] [OutgoingMutationQueue] receive(_:)
2020-03-04 12:41:17.246535+0000 AmplifyDatastoreDemo[96352:14590977] [OutgoingMutationQueue] enqueue(_:)
2020-03-04 12:41:17.246798+0000 AmplifyDatastoreDemo[96352:14590977] [StateMachine<State, Action>] Notifying: enqueuedEvent
2020-03-04 12:41:17.246901+0000 AmplifyDatastoreDemo[96352:14590977] [StateMachine<State, Action>] resolve(requestingEvent, enqueuedEvent) -> waitingForEventToProcess
2020-03-04 12:41:17.246942+0000 AmplifyDatastoreDemo[96352:14599293] [SyncMutationToCloudOperation] main()
2020-03-04 12:41:17.246986+0000 AmplifyDatastoreDemo[96352:14590977] [OutgoingMutationQueue] New state: waitingForEventToProcess
2020-03-04 12:41:17.247062+0000 AmplifyDatastoreDemo[96352:14599293] [SyncMutationToCloudOperation] sendMutationToCloud()
2020-03-04 12:41:17.247109+0000 AmplifyDatastoreDemo[96352:14597748] [OutgoingMutationQueue] respond(to:): waitingForEventToProcess
2020-03-04 12:41:17.247664+0000 AmplifyDatastoreDemo[96352:14590977] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): invoking completionPromise with success(Amplify.MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false))
2020-03-04 12:41:17.247694+0000 AmplifyDatastoreDemo[96352:14599293] [SyncMutationToCloudOperation] makeAPIRequest(_:) sending mutation with sync data: GraphQLRequest<MutationSync<AnyModel>>(apiName: nil, document: "mutation CreateNote($input: CreateNoteInput!) {\n  createNote(input: $input) {\n    id\n    content\n    __typename\n    _version\n    _deleted\n    _lastChangedAt\n  }\n}", variables: Optional(["input": ["content": Optional("new via datastore"), "id": Optional("7DC16A73-06B8-4B45-892E-AC8CBC9C0135")]]), responseType: AWSPluginsCore.MutationSync<Amplify.AnyModel>, decodePath: Optional("createNote"))
2020-03-04 12:41:17.248288+0000 AmplifyDatastoreDemo[96352:14597748] [API] Starting mutation BA6E6EDB-0A36-489E-BBE5-6E0F0BD27C89
2020-03-04 12:41:17.248310+0000 AmplifyDatastoreDemo[96352:14590977] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) saved mutation event: MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false)
2020-03-04 12:41:17.248432+0000 AmplifyDatastoreDemo[96352:14590977] [StorageEngine] syncMutation(of:mutationType:syncEngine:completion:) successfully submitted to sync engine MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false)
2020-03-04 12:41:17.248492+0000 AmplifyDatastoreDemo[96352:14597748] [API] Starting network task for mutation BA6E6EDB-0A36-489E-BBE5-6E0F0BD27C89
2020-03-04 12:41:17.248645+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
2020-03-04 12:41:17.248794+0000 AmplifyDatastoreDemo[96352:14590977] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '7DC16A73-06B8-4B45-892E-AC8CBC9C0135'
Saved note: Note(id: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", content: "new via datastore")
2020-03-04 12:41:17.249076+0000 AmplifyDatastoreDemo[96352:14590977] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) Received successful completion
2020-03-04 12:41:17.572285+0000 AmplifyDatastoreDemo[96352:14590977] [API] WebsocketDidReceiveMessage - {"type":"ka"}
2020-03-04 12:41:17.618526+0000 AmplifyDatastoreDemo[96352:14599289] [SyncMutationToCloudOperation] sendMutationToCloud received asyncEvent: completed
2020-03-04 12:41:17.618805+0000 AmplifyDatastoreDemo[96352:14599289] [SQLiteStorageEngineAdapter] delete from MutationEvent as root
where 1 = 1
  and "root"."id" = '7EEABE9A-BF57-432E-8B9A-7CFC65024F44'
2020-03-04 12:41:17.619895+0000 AmplifyDatastoreDemo[96352:14599289] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '7EEABE9A-BF57-432E-8B9A-7CFC65024F44'
2020-03-04 12:41:17.620039+0000 AmplifyDatastoreDemo[96352:14599289] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '7EEABE9A-BF57-432E-8B9A-7CFC65024F44'
2020-03-04 12:41:17.621054+0000 AmplifyDatastoreDemo[96352:14599289] [OutgoingMutationQueue] mutationEvent finished: MutationEvent(id: "7EEABE9A-BF57-432E-8B9A-7CFC65024F44", modelId: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", modelName: "Note", json: "{\"id\":\"7DC16A73-06B8-4B45-892E-AC8CBC9C0135\",\"content\":\"new via datastore\"}", mutationType: "create", createdAt: 2020-03-04 12:41:17 +0000, version: nil, inProcess: false); result: completed
2020-03-04 12:41:17.621138+0000 AmplifyDatastoreDemo[96352:14599289] [StateMachine<State, Action>] Notifying: processedEvent
2020-03-04 12:41:17.621219+0000 AmplifyDatastoreDemo[96352:14599289] [StateMachine<State, Action>] resolve(waitingForEventToProcess, processedEvent) -> requestingEvent
2020-03-04 12:41:17.621308+0000 AmplifyDatastoreDemo[96352:14599289] [OutgoingMutationQueue] New state: requestingEvent
2020-03-04 12:41:17.621430+0000 AmplifyDatastoreDemo[96352:14599318] [OutgoingMutationQueue] respond(to:): requestingEvent
2020-03-04 12:41:17.621497+0000 AmplifyDatastoreDemo[96352:14599318] [OutgoingMutationQueue] requestEvent()
2020-03-04 12:41:17.621620+0000 AmplifyDatastoreDemo[96352:14599318] [AWSMutationDatabaseAdapter] getNextMutationEvent(completion:)
2020-03-04 12:41:17.621842+0000 AmplifyDatastoreDemo[96352:14599318] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
LIMIT 1
2020-03-04 12:41:17.622028+0000 AmplifyDatastoreDemo[96352:14599318] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
LIMIT 1
2020-03-04 12:41:17.776159+0000 AmplifyDatastoreDemo[96352:14590977] [API] WebsocketDidReceiveMessage - {"type":"data","id":"D7A65BE0-737F-46DB-95D0-EF92B320FFC3","payload":{"data":{"onCreateNote":{"__typename":"Note","_deleted":null,"_lastChangedAt":1583325677428,"_version":1,"content":"new via datastore","id":"7DC16A73-06B8-4B45-892E-AC8CBC9C0135"}}}}
2020-03-04 12:41:17.909946+0000 AmplifyDatastoreDemo[96352:14590977] [API] WebsocketDidReceiveMessage - {"type":"data","id":"64885CB4-0F8A-47F5-B438-8C0D51A73242","payload":{"data":{"onCreateNote":{"__typename":"Note","content":"new via datastore","id":"7DC16A73-06B8-4B45-892E-AC8CBC9C0135"}}}}
Successfully got new note: Note(id: "7DC16A73-06B8-4B45-892E-AC8CBC9C0135", content: "new via datastore")

@James-Coleman
Copy link
Author

James-Coleman commented Mar 4, 2020

After changing back to the master branch, cleaning the project and re-running (simulator only I'll admit), and Notes added with Amplify.DataStore.save() are not appearing anywhere in DynamoDB, not in the Note table nor the AmplifyDataStore table.

Here's a log from adding a note via DataStore
2020-03-04 13:17:11.216887+0000 AmplifyDatastoreDemo[99815:14651941] [AWSDataStorePlugin] Saving: Note(id: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", content: "master again")
2020-03-04 13:17:11.217043+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.217265+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.217444+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select count(id) from Note where id = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.217655+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] insert into Note ("id", "content")
values ('8AFAFB82-EBC8-46EE-8B28-029F376EBC7C', 'master again')
2020-03-04 13:17:11.218774+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.218943+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."content" as "content"
from Note as root
where 1 = 1
  and "root"."id" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.227516+0000 AmplifyDatastoreDemo[99815:14651941] [StorageEngine] save(_:completion:) syncing mutation for Note(id: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", content: "master again")
2020-03-04 13:17:11.227734+0000 AmplifyDatastoreDemo[99815:14651941] [AWSMutationDatabaseAdapter] submit(mutationEvent:): MutationEvent(id: "24190189-0388-4171-8595-90FCC1936F3C", modelId: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", modelName: "Note", json: "{\"id\":\"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C\",\"content\":\"master again\"}", mutationType: "create", createdAt: 2020-03-04 13:17:11 +0000, version: nil, inProcess: false)
2020-03-04 13:17:11.227961+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.228089+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.228443+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-03-04 13:17:11.228569+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."modelId" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
  and (
    "root"."inProcess" = 0
    or "root"."inProcess" is null
  )
ORDER BY createdAt ASC
2020-03-04 13:17:11.228753+0000 AmplifyDatastoreDemo[99815:14651941] [AWSMutationDatabaseAdapter] disposition(for:given:) no local events, saving candidate
2020-03-04 13:17:11.228833+0000 AmplifyDatastoreDemo[99815:14651941] [AWSMutationDatabaseAdapter] resolve(candidate:localEvents:per:storageAdapter:completionPromise:) disposition saveCandidate
2020-03-04 13:17:11.228955+0000 AmplifyDatastoreDemo[99815:14651941] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:) mutationEvent: MutationEvent(id: "24190189-0388-4171-8595-90FCC1936F3C", modelId: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", modelName: "Note", json: "{\"id\":\"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C\",\"content\":\"master again\"}", mutationType: "create", createdAt: 2020-03-04 13:17:11 +0000, version: nil, inProcess: false)
2020-03-04 13:17:11.229068+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select count(id) from MutationEvent where id = '24190189-0388-4171-8595-90FCC1936F3C'
2020-03-04 13:17:11.229436+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] insert into MutationEvent ("id", "createdAt", "inProcess", "json", "modelId", "modelName", "mutationType", "version")
values ('24190189-0388-4171-8595-90FCC1936F3C', '2020-03-04T13:17:11.228Z', 0, '{"id":"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C","content":"master again"}', '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C', 'Note', 'create', NULL)
2020-03-04 13:17:11.230402+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '24190189-0388-4171-8595-90FCC1936F3C'
2020-03-04 13:17:11.230539+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."createdAt" as "createdAt", "root"."inProcess" as "inProcess",
  "root"."json" as "json", "root"."modelId" as "modelId", "root"."modelName" as "modelName",
  "root"."mutationType" as "mutationType", "root"."version" as "version"
from MutationEvent as root
where 1 = 1
  and "root"."id" = '24190189-0388-4171-8595-90FCC1936F3C'
2020-03-04 13:17:11.231135+0000 AmplifyDatastoreDemo[99815:14651941] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): saved MutationEvent(id: "24190189-0388-4171-8595-90FCC1936F3C", modelId: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", modelName: "Note", json: "{\"id\":\"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C\",\"content\":\"master again\"}", mutationType: "create", createdAt: 2020-03-04 13:17:11 +0000, version: nil, inProcess: false)
2020-03-04 13:17:11.231277+0000 AmplifyDatastoreDemo[99815:14651941] [AWSMutationDatabaseAdapter] save(mutationEvent:storageAdapter:completionPromise:): invoking completionPromise with success(Amplify.MutationEvent(id: "24190189-0388-4171-8595-90FCC1936F3C", modelId: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", modelName: "Note", json: "{\"id\":\"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C\",\"content\":\"master again\"}", mutationType: "create", createdAt: 2020-03-04 13:17:11 +0000, version: nil, inProcess: false))
2020-03-04 13:17:11.231409+0000 AmplifyDatastoreDemo[99815:14651941] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) saved mutation event: MutationEvent(id: "24190189-0388-4171-8595-90FCC1936F3C", modelId: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", modelName: "Note", json: "{\"id\":\"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C\",\"content\":\"master again\"}", mutationType: "create", createdAt: 2020-03-04 13:17:11 +0000, version: nil, inProcess: false)
2020-03-04 13:17:11.231533+0000 AmplifyDatastoreDemo[99815:14651941] [StorageEngine] syncMutation(of:mutationType:syncEngine:completion:) successfully submitted to sync engine MutationEvent(id: "24190189-0388-4171-8595-90FCC1936F3C", modelId: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", modelName: "Note", json: "{\"id\":\"8AFAFB82-EBC8-46EE-8B28-029F376EBC7C\",\"content\":\"master again\"}", mutationType: "create", createdAt: 2020-03-04 13:17:11 +0000, version: nil, inProcess: false)
2020-03-04 13:17:11.231708+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
2020-03-04 13:17:11.231835+0000 AmplifyDatastoreDemo[99815:14651941] [SQLiteStorageEngineAdapter] select
  "root"."id" as "id", "root"."deleted" as "deleted", "root"."lastChangedAt" as "lastChangedAt",
  "root"."version" as "version"
from MutationSyncMetadata as root
where 1 = 1
  and "root"."id" = '8AFAFB82-EBC8-46EE-8B28-029F376EBC7C'
Saved note: Note(id: "8AFAFB82-EBC8-46EE-8B28-029F376EBC7C", content: "master again")
2020-03-04 13:17:11.232073+0000 AmplifyDatastoreDemo[99815:14651941] [StorageEngine] submitToSyncEngine(mutationEvent:syncEngine:completion:) Received successful completion

Interestingly I also got the following crash from a clean install:
Screenshot 2020-03-04 at 13 12 13
The "Customer" model is a custom one that I was going to test with, but I haven't used it apart from adding it to schema.graphql and seeing the generated code.

@moweex
Copy link

moweex commented Mar 4, 2020

Am facing the same issue with RN, datastore is not synchronized with dynamodb. i can query, update, save to the local store. but nothing is updated on dynamodb. conflict resolution is configured correctly and tables have all versioning fields.

@sebsto
Copy link

sebsto commented Mar 9, 2020

amplify update api should not be required. The Amplify Plugin should create the API with conflict detection enabled by default.

The doc suggests a different workflow : https://aws-amplify.github.io/docs/ios/datastore#datastore which does not suppose to use the amplify update api

Can we keep the doc updated with current status of the workflow ?

@hawkingbeck
Copy link

Hi All,
I have a related problem. I have essentially followed the steps shown on the amplify 'getting started' iOS page. My use case is simple at the moment. I have a single model in my GraphQL schema and have the DataStore and API plugins enabled. The following use cases work fine:

  • Save to data store
  • Query from data store
  • Observe data store
  • Subscribe to API 'on create' notifications

With this I am able to run the app on two (or more) devices and see real time data store updates whilst the app is open on the devices.

However I have an issue when the app is closed (force closed), starting with the app running concurrently on 3 devices (2 simulators and 1 iPhone 11 Pro) I force close on 1 device and then create a new 'booking' in my case. This is then saved, synced and appears on the 2 device will the app still open. After this I open the app on the third device which then takes several hours to sync data store with AppSync. I'm at a loss to how to make the sync happen when the app is either brought back from the background or opened from fresh again.

Any advice would be greatly appreciated.

FYI: I tried pulling the pods directly from the repo, however this now causes the API subscription to fail to connect.

@sbue
Copy link

sbue commented Mar 30, 2020

I've had this issue as well (in React Native)

TDLR: It seems like DataStore and API.graphql(graphqlOperation... are writing and reading to two different targets. When I write to DataStore, it doesn't show up in DynamoDB. When I write using API.graphql, it doesn't show up when I query with DataStore. Very odd and frustrating. Can answer questions if needed.

EDIT:
It seems like I got this to work very briefly in my project by doing DataStore.clear() upon user signout.
At least for my case, it seems to be related to this issue: aws-amplify/amplify-js#5076

@arnm
Copy link

arnm commented Apr 8, 2020

I am seeing this issue with web application as well...

@bharring
Copy link

bharring commented Apr 8, 2020

I'm seeing this same problem too. DataStore and API.graphql don't see the same data, and DataStore doesn't persist to DynamoDB or the backend at all, but stays on the client even after a config change.

@mreaybeaton
Copy link

Hi @James-Coleman,

I was able to identify the problem. This is related to some other issues we're tracking. Basically DataStore sync capabilities only work when your API was created with conflict resolution enabled. That is part of the "Advanced settings" when you run amplify add api.

Since you already created your API, you can run amplify update api and:

? Please select from one of the below mentioned services: GraphQL
? Choose the default authorization type for the API API key
? Enter a description for the API key: datastore-demo-key
? After how many days from now the API key should expire (1-365): 365
? Do you want to configure advanced settings for the GraphQL API Yes, I want to make some additional changes.
? Configure additional auth types? No
? Configure conflict detection? Yes
? Select the default resolution strategy Auto Merge
? Do you want to override default per model settings? No

The important setting is when you're asked Do you want to configure advanced settings for the GraphQL API, answer yes and on Configure conflict detection? also pick yes.

Now, when you execute your app again, all the local Data you had created before should be synced to the cloud and available to you in the AppSync console.

Again, thanks for reporting this, I'm talking to the CLI team in order to improve this flow for all platforms to improve the DataStore setup process.

Related PR: aws-amplify/amplify-cli#3495

I was having the same issue, but this seems to have fixed my issue. Any update improving the flow? Or at least defaulting the conflict resolution so this option doesn't need to be configured out of the box?

@Johnniexson

This comment has been minimized.

@ivenxu

This comment has been minimized.

@shravanjha

This comment has been minimized.

@small4all

This comment has been minimized.

@palpatim
Copy link
Member

@Johnniexson, @ivenxu, @shravanjha, @small4all Could you open your issues on the https://github.com/aws-amplify/amplify-js/issues repo ? This issues page is specifically for iOS, and we won't be able to provide any useful guidance for you.

@drochetti
Copy link
Contributor

drochetti commented May 29, 2020

Hey @James-Coleman we just released a stable v1.0.0. Could you try following the new DataStore tutorial and see if the new flow and stable code fixes your issues?

I appreciate your patience and the fact you tried our unstable preview and provided valuable feedback and insights with your issue report. I hope the stable release fixes things for you.

We also have a brand new Discord server for Amplify related topics. Feel free to hit me up there to talk about your use cases and challenges with the new APIs and docs. https://discord.gg/amplify

@vitzaoral
Copy link

I had similar problem, AWS DataStore was not syncing data to Cloud when I followed new DataStore tutorial. But at one time I tried write amplify update api and there was option Enable DataStore for entire API. After amplify push it added some configuration to file transform.conf.json (ResolverConfig) in Xcode project and it started work!

@arjoglekar
Copy link

Could you please share your transform.conf.json. I am also facing the same issue.

@vitzaoral
Copy link

My transform.cong.json:
As I sad, I had to enable Enable DataStore for entire API (amplify update api command)

{
    "Version": 5,
    "ElasticsearchWarning": true,
    "ResolverConfig": {
        "project": {
            "ConflictHandler": "AUTOMERGE",
            "ConflictDetection": "VERSION"
        }
    }

}

@drochetti
Copy link
Contributor

@vitzaoral thanks for the confirmation.

I'm closing this issue for now. Feel free to open a new one if you have problems with the stable version of Amplify.

@armenr
Copy link

armenr commented Apr 20, 2021

@drochetti - I'm seeing the same in my local environment.

When I write data with API.graphQL --> saves to Dynamo, no problem.
When I attempt to save with Datastore.save(new ModelName{ someProperty: 'someValue'}) --> nothing shows up in Dynamo.

I have attempted the amplify api update flow --> still doesn't help/work.

"@aws-amplify/cli": "^4.49.0"
"aws-amplify": "^3.3.27",

@anoop4real
Copy link

anoop4real commented Jan 6, 2022

I am following Tutorial ... everything works except sync.
I am developing an iOS App. Local saving and query with Datastore works but no sync ...

Unable to find suitable Auth plugin for syncEngine. Models require auth

@charlieforward9
Copy link

charlieforward9 commented Oct 24, 2022

How do you enable verbose logging as shown in this comment? I am stuck with a similar problem after switching the @auth mode from public to owner

@atierian
Copy link
Member

@charlieforward9 Amplify.Logging.logLevel = .verbose
If you're experiencing similar problems, please open a new issue and include a link to this one for context if needed.
Thanks!

@charlieforward9
Copy link

@atierian

Amplify.Logging.logLevel = .verbose

I am using Flutter and cannot get this to work. Is there an import I need to make?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore category
Projects
None yet
Development

No branches or pull requests