通过 AWS AppSync 中的突变更新 GraphQL 数据时出错
Error updating GraphQL data through mutation in AWS AppSync
我已经成功地使用突变创建了数据,但是当我更新该数据时,我收到了这个错误
Variable 'input' has coerced Null value for NonNull type 'Int!
这是我的查询模式
type SmoothstarRegisteration @model @versioned {
id: ID!
active: Boolean!
type: String!
registerationSubmitDate: String
registerationApprovedDate: String
userId: String!
videoInfoReviewed: Boolean!
registerationAttempts: Int!
registerationStatus: String
orderNum: String
orderInfo: OrderInfo @connection(name: "SmoothstarRegisterationOrder")
address: String
postCode: String
region: String
dateOfBirth: String
smoothstarModel: String
purchaseDate: String
shopName: String
ocrInfo: OCRInfo @connection(name: "SmoothstarRegisterationOCR")
privacyPolicyReviewed: Boolean!
extendedPolicyReviewed: Boolean!
termsOfUseReviewed: Boolean!
files: [RegisterationMedia!] @connection(name: "SmoothstarRegisterationMedia")
}
这是更新查询
mutation UpdateSmoothstarRegisteration(
$input: UpdateSmoothstarRegisterationInput!
) {
updateSmoothstarRegisteration(input: $input) {
id
active
type
registerationSubmitDate
registerationApprovedDate
userId
videoInfoReviewed
registerationAttempts
registerationStatus
orderNum
orderInfo {
id
active
type
orderNum
}
address
postCode
region
dateOfBirth
smoothstarModel
purchaseDate
shopName
ocrInfo {
id
active
type
customerId
customerEmail
customerPhone
orderNum
address
}
privacyPolicyReviewed
extendedPolicyReviewed
termsOfUseReviewed
files {
items {
id
version
}
nextToken
}
version
}
}
这里是调用API的代码。
return API.graphql(graphqlOperation(operation, data))
.then(response => {
console.log(`API (${name}) Response => `, response);
return response;
})
.catch(error => {
throw error;
});
在 Operation
中,我将更新查询发送到我正在放置的数据中
{ input: {
active: true
extendedPolicyReviewed: true
id: "9dfc480f-7bed-42ed-a585-820f5e8c1485"
orderNum: "ABCD1234xyz"
privacyPolicyReviewed: true
registerationAttempts: 2
registerationStatus: "registered"
registerationSubmitDate: "2019-03-31"
smoothstarRegisterationOrderInfoId: "03b6967d-4b86-4c2d-9115-fb7a40a9c474"
termsOfUseReviewed: true
type: "W"
userId: "m.daniyal.awan@gmail.com"
videoInfoReviewed: true
}}
我找到问题了,输入中缺少 expectedVersion
属性。
刚刚添加了 expectedVersion: 1
,一切顺利。该数字必须与当前数据中存在的版本条目完全一致,您必须在每次调用更新时递增它。
我已经成功地使用突变创建了数据,但是当我更新该数据时,我收到了这个错误
Variable 'input' has coerced Null value for NonNull type 'Int!
这是我的查询模式
type SmoothstarRegisteration @model @versioned {
id: ID!
active: Boolean!
type: String!
registerationSubmitDate: String
registerationApprovedDate: String
userId: String!
videoInfoReviewed: Boolean!
registerationAttempts: Int!
registerationStatus: String
orderNum: String
orderInfo: OrderInfo @connection(name: "SmoothstarRegisterationOrder")
address: String
postCode: String
region: String
dateOfBirth: String
smoothstarModel: String
purchaseDate: String
shopName: String
ocrInfo: OCRInfo @connection(name: "SmoothstarRegisterationOCR")
privacyPolicyReviewed: Boolean!
extendedPolicyReviewed: Boolean!
termsOfUseReviewed: Boolean!
files: [RegisterationMedia!] @connection(name: "SmoothstarRegisterationMedia")
}
这是更新查询
mutation UpdateSmoothstarRegisteration(
$input: UpdateSmoothstarRegisterationInput!
) {
updateSmoothstarRegisteration(input: $input) {
id
active
type
registerationSubmitDate
registerationApprovedDate
userId
videoInfoReviewed
registerationAttempts
registerationStatus
orderNum
orderInfo {
id
active
type
orderNum
}
address
postCode
region
dateOfBirth
smoothstarModel
purchaseDate
shopName
ocrInfo {
id
active
type
customerId
customerEmail
customerPhone
orderNum
address
}
privacyPolicyReviewed
extendedPolicyReviewed
termsOfUseReviewed
files {
items {
id
version
}
nextToken
}
version
}
}
这里是调用API的代码。
return API.graphql(graphqlOperation(operation, data))
.then(response => {
console.log(`API (${name}) Response => `, response);
return response;
})
.catch(error => {
throw error;
});
在 Operation
中,我将更新查询发送到我正在放置的数据中
{ input: {
active: true
extendedPolicyReviewed: true
id: "9dfc480f-7bed-42ed-a585-820f5e8c1485"
orderNum: "ABCD1234xyz"
privacyPolicyReviewed: true
registerationAttempts: 2
registerationStatus: "registered"
registerationSubmitDate: "2019-03-31"
smoothstarRegisterationOrderInfoId: "03b6967d-4b86-4c2d-9115-fb7a40a9c474"
termsOfUseReviewed: true
type: "W"
userId: "m.daniyal.awan@gmail.com"
videoInfoReviewed: true
}}
我找到问题了,输入中缺少 expectedVersion
属性。
刚刚添加了 expectedVersion: 1
,一切顺利。该数字必须与当前数据中存在的版本条目完全一致,您必须在每次调用更新时递增它。