Closed srimalaya closed 1 year ago
Thanks for the report @shri-onecup. We are looking into this.
The same insertion works fine using DataStore:
Amplify.DataStore.save(customer)
Amplify.DataStore.save(animal)
Amplify.DataStore.save(note)
DataStore uses a different request factory class that simply ignores the null field value here: https://github.com/aws-amplify/amplify-android/blob/main/aws-datastore/src/main/java/com/amplifyframework/datastore/appsync/AppSyncRequestFactory.java#L452
It looks like the change to AppSyncGraphQLRequestFactory
to require a non-null association was introduced way back in version 1.6.4
with this commit: https://github.com/aws-amplify/amplify-android/commit/da6df078ebd32bf292d640858e1fd7c949f9d5f1
I have made a fix to AppSyncGraphQLRequestFactory
that addresses this issue and allows the create snippet from the issue description to succeed. I'll continue to test the change through the day and will hopefully be able to open a PR ahead of our next release.
@mattcreaser thank you for the prompt update and fix. I’m looking forward to it being released soon.
A fix has been released. Please update to Amplify Android 2.8.4 and let us know if you have any additional questions.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Before opening, please confirm:
Language and Async Model
Kotlin - Coroutines
Amplify Categories
GraphQL API
Gradle script dependencies
Describe the bug
Please take a look at the GraphQL Schema attached below. See that it has ID fields which are optional (nullable). Also see that fields like
customer_id
,animal_id
, andmeasurement_id
are linked using@BelongsTo
relation.Here is the bug: When a mutation is being triggered, I noticed that the
@BelongsTo
relation is being enforced as not null in theAppSyncGraphQLRequestFactory.java
file. This causes a crash when I set a nested model to null. For example, if you follow the reproduction steps provided below, you can see that while saving note, customer is required but animal and measurement are supposed to be optional fields. But, when I leave either of them out, it causes an app crash.Our previous app was built using Amplify V1 and it used to work just fine on the same schema so I initially thought it was a bug with Amplify V2. However, I have tested this schema with both V1 and V2 and the result stays the same, i.e., the app crashed with NullPointerException. This functionality is important to us. For example, we want every model to be able to have many Notes. This makes it obvious that each note cannot have a value for each model that it
belongs to
.I am 100% certain that this feature used to work before on a similar schema. And I am certain it works or used to work on both iOS and JavaScript versions of our app.
My current way of handling this issue is to use a
SimpleGraphQL
request and use a custom mutation document as I would on the AppSync console, which is a huge headache to keep track of as we keep scaling the app up to use more models.Reproduction steps (if applicable)
measurement_id
which is linked toNote
using the@BelongsTo
relationshipCode Snippet
Log output
GraphQL Schema