Skip to content

In case of errors on some items during sync, no items are saved #3259

Closed
@gbitaudeau

Description

@gbitaudeau

Describe the bug

If during initial sync, AppSync responds with some items on error, these items are null in items response array. The other items which are not in error are not saved in datastore. Here a redacted result for sync Model named Draw with an error on one item:

{
  "data": {
    "syncDraws": {
      "items": [
        {
          "id": "70083950-9b18-4e62-90c6-433ae933def3",
          "drawBatch": {
            "id": "e236042a-7c21-4b82-90b3-d8b73d2c6b99",
            "_deleted": true
          },
          "item": {
            "_deleted": true,
            "id": "fa986c78-ff21-46e2-82ff-8d0a218510bc"
          },
          "owner": "cb8c1cd8-f22c-4e30-8a7c-42fa3e2e16b1",
          "updatedAt": "2023-09-20T09:09:06.134Z"
        },
        null
  },
  "errors": [
    {
      "path": [
        "syncDraws",
        "items",
        17,
        "drawBatch"
      ],
      "data": null,
      "errorType": "Unauthorized",
      "errorInfo": null,
      "locations": [
        {
          "line": 10,
          "column": 7,
          "sourceName": null
        }
      ],
      "message": "Not Authorized to access drawBatch on type Draw"
    }
  ]
}

Steps To Reproduce

Steps to reproduce the behavior:
1. Consider a schema.graphql where 2 objects are linked together with `@hasMany` and `@belongsTo` and each object have the following auth policy: `@auth(rules: [{ allow: owner}])`.
2. Create on object of each type and linked then together.
3. Change the owner of the object with the `@hasMany` relationship.
4. The sync of the object type with `@belongsTo` is no longer working.

Expected behavior

DataStore's initial sync should reconcile partial GraphQL responses by saving the items in the local Database and emitting the errors to the errorHandler.

Amplify Framework Version

2.19.0

Amplify Categories

DataStore

Dependency manager

Swift PM

Swift version

5.9

CLI version

12.4.0

Xcode version

15.0

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 17.0.1

Device

iPhone

Specific to simulators

No response

Additional context

See discussion #3232 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdatastoreIssues related to the DataStore category

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions