Skip to content

Saving nested models in Android may raise GraphQL error for iOS devices that subscribe to the same models #663

@HuiSF

Description

@HuiSF

This issue is caused by that platform libraries generating incompatible selection set making mutation requests.
In most cases, especially when nested models are involved, iOS platform cannot receive subscription updates from mutations made in other platforms, such as amplify-js (Amplify Studio), amplify-android.

Describe the bug
Saving nested models in Android may raise GraphQL error for iOS devices that subscribe to the same models. It happens when saving nested models in Android, and receiving subscription message in iOS.

Expand for details
This is due to Android doesn't populate nested models by default, when saving object, service side GraphQL validation may fail due to missing fields in the request sent from Android. The error may be emitted to all model subscriptions in different devices.

Two possible causes:

  1. In Android, nested models (has-one, belongs-to) are not populated with data
  2. When saving an object with creating association with other models, complete objects of other models see to be required, but no associating only by id field

Android sent mutation that caused the error

{
  "query": "mutation CreateComment($input: CreateCommentInput!) {\n  createComment(input: $input) {\n    _deleted\n    _lastChangedAt\n    _version\n    content\n    id\n    post {\n      id\n    }\n  }\n}\n",
  "variables": {
    "input": {
      "id": "2a7693b3-0591-4941-901e-fb355c962f72",
      "postID": "a4930282-77ea-468d-88e2-c042a8e575a5",
      "content": "tetetet"
    }
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Run amplify_datastore with API sync in 1 Android emulator and 1 iOS simulator
  2. Save a new "Comment" in Android emulator
  3. Observe iOS simulator logs
  4. See error
2021-06-22 12:59:28.065189-0700 Runner[5863:11863431] [StarscreamAdapter] websocketDidReceiveMessage: - {"id":"13C8F47B-5693-4925-9818-9A404031CC15","type":"data","payload":{"data":{"onCreateComment":{"id":"8360f342-5515-4a49-98e1-906211efd408","content":"Test","post":null,"__typename":"Comment","_version":1,"_deleted":null,"_lastChangedAt":1624391967947}},"errors":[{"message":"Cannot return null for non-nullable type: 'Int' within parent 'Post' (/onCreateComment/post/rating)","path":["onCreateComment","post","rating"]},{"message":"Cannot return null for non-nullable type: 'String' within parent 'Post' (/onCreateComment/post/title)","path":["onCreateComment","post","title"]},{"message":"Cannot return null for non-nullable type: 'Person' within parent 'Post' (/onCreateComment/post/author)","path":["onCreateComment","post","author"]},{"message":"Cannot return null for non-nullable type: 'Int' within parent 'Post' (/onCreateComment/post/_version)","path":["onCreateComment","post","_version"]},{"message":"Cannot return null for non-nullable type: 'AWSTimestamp' within parent 'Post' (/onCreateComment/post/_lastChangedAt)","path":["onCreateComment","post","_lastChangedAt"]}]}}

Expected behavior
iOS should receive correct subscription message.

Platform
Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply):
[ x ] Android
[ x ] iOS

Metadata

Metadata

Assignees

Labels

bugSomething is not working; the issue has reproducible steps and has been reproduceddatastoreIssues related to the DataStore Categoryrequires-android-fixThis issue is the result of an underlying Amplify Android issue that needs to be fixed.requires-ios-fixThis issue is the result of an underlying Amplify iOS issue that needs to be fixed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions