Amplify-cli: Unique Key Resolver

Created on 20 Jan 2019  路  3Comments  路  Source: aws-amplify/amplify-cli

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" } } }

graphql-transformer question

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"

All 3 comments

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"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriatikgashi picture adriatikgashi  路  3Comments

ffxsam picture ffxsam  路  3Comments

MageMasher picture MageMasher  路  3Comments

darrentarrant picture darrentarrant  路  3Comments

jexh picture jexh  路  3Comments