aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Unique Key Resolver #738

Closed amlcodes closed 5 years ago

amlcodes commented 5 years ago

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"
    }
  }
}```
mikeparisstuff commented 5 years ago

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.

kaustavghosh06 commented 5 years ago

@amlcodes Are you still blocked on this? Feel free to re-open if this is still an issue.

gaochenyue commented 4 years ago

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

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.