aws-mobile-appsync-sdk-android
aws-mobile-appsync-sdk-android copied to clipboard
Error in executing 1-N mutation
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?
Hi @watanabethais ,
Thanks for a detailed report. Pinging @awsed to take a look, as it does not appear to be an issue with the SDK.