aws / aws/aws-appsync-community

How to create a map if not exists or update it if it does in appsync

Open
#180 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

I have come across a scenario that incase a map is not created beforehand in dynamodb the update operation fails.

I am trying to create a map(userStatus in my case) incase it doesn't exist and also update it's key value in one pass.

here is the code from my appsync request template

{
"version": "2018-05-29",
"operation": "UpdateItem",
"key": {
"topicId": $util.dynamodb.toDynamoDBJson($ctx.stash.topicId)
},
"update" : {
"expression" : "SET userStatus = if_not_exists(userStatus, :emptymap), userStatus.#idx = :userContent",
"expressionNames": {
"#idx": "$ctx.args.input.event.payload.userId"
},
"expressionValues": {
":emptymap" : $util.dynamodb.toDynamoDBJson({}),
":userContent" : $util.dynamodb.toDynamoDBJson($userStatusContent)
}
}
}

i'm getting this error "Two document paths overlap with each other; must remove or rewrite one of these paths"
Here is a code that I tried but it fails

How can I solve this?

Contributor guide

Open the contributing guide

Research direction

The relevant entry point is the AppSync UpdateItem request template shown in the issue; start by reading DynamoDB update-expression document-path rules and AppSync expressionValues handling. Reproduce the failing request with and without the userStatus map, then confirm a request-template expression that creates or updates the nested value without overlapping paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql
Domain
api, cloud, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.