appsync request resolver is not working as I think it is intended. I cannot find any documentation at all about attribute_not_exists or much about conditions in resolvers. my current resolver should only succeed if both keys, id and netlifyid are unique.
I end up succeeding anyways currently. condition expression is not being resolved correctly
{
"version": "2017-02-28",
"operation": "PutItem",
"key": {
"id": $util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.args.input.id, $util.autoId())),
"netlifyId": $util.dynamodb.toDynamoDBJson($context.arguments.input.netlifyId)
},
"attributeValues": $util.dynamodb.toMapValuesJson($context.args.input),
"condition": {
"expression": "attribute_not_exists(#id) AND attribute_not_exists(#netlifyId)",
"expressionNames": {
"#id": "id",
"#netlifyId": "netlifyId"
}
}
}
It throws only if the values that you are trying to put are different. For example, if I have a field Mutation.createBlog
with this template:
{
"version": "2017-02-28",
"operation": "PutItem",
"key": {
"id": $util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.args.input.id, $util.autoId()))
},
"attributeValues": $util.dynamodb.toMapValuesJson($context.args.input),
"condition": {
"expression": "attribute_not_exists(#id)",
"expressionNames": {
"#id": "id"
}
}
}
and I run
mutation {
createBlog(input:{
id:2,
name:"hi"
}) {
id
name
}
}
followed by
# This does not fail and returns { id: 2, name: "a blog" }
mutation {
createBlog(input:{
id:2,
name:"a blog"
}) {
id
name
}
}
however if I run
# This does fail
mutation {
createBlog(input:{
id:2,
name:"another blog"
}) {
id
name
}
}
If you are seeing something different please let me know.
@amlcodes Are you still blocked on this? Feel free to re-open if this is still an issue.
@mikeparisstuff I still don't get why name:"a blog" doesn't fail but name:"another blog" fails. They are both different values from the first the one name:"hi"
Most helpful comment
@mikeparisstuff I still don't get why name:"a blog" doesn't fail but name:"another blog" fails. They are both different values from the first the one name:"hi"