我有一个变种来创建一个新的Event
。但是,我希望能够使用友好的ID或Slug(而不是Event
的DynamoDB主键来引用/获取id
。理想情况下,这将使用输入中的city
字段来生成段。但是每个子弹每个作者都必须是唯一的
如何根据城市名称和唯一身份(按作者)在突变中生成友好的子弹?
type Event {
id: ID!
subtitle: String!
city: String!
author: String!
created: AWSDateTime
}
#set( $attribs = $util.dynamodb.toMapValues($ctx.args.input))
#set( $attribs.author = $util.dynamodb.toDynamoDB($ctx.identity.username))
#set( $attribs.created = $util.dynamodb.toDynamoDB($util.time.nowFormatted("yyyy-MM-dd HH:mm:ssZ")))
{
"version": "2017-02-28",
"operation": "PutItem",
"key": {
"id": $util.dynamodb.toDynamoDBJson($util.autoId()),
},
"attributeValues": $util.toJson($attribs),
"condition": {
"expression": "attribute_not_exists(#id)",
"expressionNames": {
"#id": "id",
},
},
}
```