awslabs / awslabs/aws-mobile-appsync-sdk-android
Error in executing 1-N mutation
- Dominant language
- Java
- Stars
- 106
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
I'm having problems in executing a 1-N mutation in my Android project, the service response gives me the following error:
> The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException)
But the data is successfully added into the DB.
Here is my project schema:
```
type Inspection @model @key(fields: ["id", "date"]) {
id: ID!
name: String!
date: AWSDate!
inspectionDetails: [InspectionDetail] @connection(name: "InspectionDetails")
workDetails: [WorkDetail] @connection(name: "InspectionWorkDetails")
}
type InspectionDetail @model @key(fields: ["id", "itemId"]) {
id: ID!
itemId: String!
inspection: Inspection! @connection(name: "InspectionDetails")
dateTime: AWSDateTime
result: String
}
type WorkDetail @model {
id: ID!
inspection: Inspection! @connection(name: "InspectionWorkDetails")
startDateTime: AWSDateTime
endDateTime: AWSDateTime
}
```
Checking the log in my project, I've found the following code showing the mutation:
```
V/PersistentOfflineMutationManager: Thread:[2]:addPersistentMutationObject: Adding mutation[4e71e477-ccc2-4c4a-9279-2e4a11fd0eb4]: CreateWorkDetailMutation
{"query":"mutation CreateWorkDetail($input: CreateWorkDetailInput!) { createWorkDetail(input: $input) { __typename id inspection { __typename id name date inspectionDetails { __typename nextToken } workDetails { __typename nextToken } } startDateTime endDateTime }}","variables":{"input":{"id":"504f138a-fdbf-4dc8-9947-491589b3ea2d","startDateTime":"2019-11-12T21:12:43.008Z","endDateTime":"2019-11-12T21:12:43.008Z","workDetailInspectionId":"d44a79e4-58ce-4458-bc4a-8d6e282f5404"}}}
V/AppSyncOfflineMutationManager: Thread:[2]: Added mutation[4e71e477-ccc2-4c4a-9279-2e4a11fd0eb4] to Persistent
```
```
mutation CreateWorkDetail($input: CreateWorkDetailInput!) {
createWorkDetail(input: $input) {
__typename
id
inspection {
__typename
id
name
date
inspectionDetails {
__typename
nextToken
}
workDetails {
__typename
nextToken
}
}
startDateTime
endDateTime
}
}
```
I've copied the mutation above in the AppSync Queries console to test, and it gives me same error and the data is added in the DB.
```
{
"data": {
"createWorkDetail": null
},
"errors": [
{
"path": [
"createWorkDetail",
"inspection"
],
"data": null,
"errorType": "DynamoDB:AmazonDynamoDBException",
"errorInfo": null,
"locations": [
{
"line": 5,
"column": 3,
"sourceName": null
}
],
"message": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: x)"
}
]
}
```
Removing the "inspection" column in mutation, the error disappears...
Maybe am I not modeling the schema correctly?
Contributor guide
Research direction
Start with the provided schema and logged CreateWorkDetail mutation, then compare the Inspection key declaration with the connection lookup used when resolving inspection. Reproduce the mutation in the AppSync Queries console; done means the related inspection is returned without the DynamoDB key-schema error while the WorkDetail remains created.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, aws, graphql, java
- Domain
- api, databases, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100