【问题标题】:AppSync DynamoDB atomic append to existing list attribute and other list operationsAppSync DynamoDB 原子追加到现有列表属性和其他列表操作
【发布时间】:2026-01-09 17:15:01
【问题描述】:

我们在 dynamoDB 中有一个对象,其键为 id,下面是 JSON 格式的数据:

我们正在使用 Amplify API 连接到 AppSync 的前端应用程序创建、获取和更新此表。

目前,当我们想将项目添加到 objects 列表时,我们会覆盖整个内容,但我知道可以将新项目自动附加到现有数据。

我的额外问题是是否支持附加,是否支持其他列表操作,例如splice,我们如何实现它?我们是否需要更改客户端的查询,或 appsync 解析器/graphql 架构?

目前,我正在通过每次在客户端使用此命令覆盖一个新副本来更新我的数据:

import { API } from "aws-amplify";

import {
  ...
  updateTable,
  ...
} from "../graphql/mutations";

API.graphql({ query: updateTable, variables: variables })

这是dynamoDB中的数据结构

{
 "id": "something",
 "objects": [
  [
   {
    "foo": [
     "first",
     "second"
    ],
    "start": 0,
    "end": 20
   },
   {
    "bar": [
     "third",
     "fourth"
    ],
    "start":10,
    "end": 40
   },
  ]
 ],
}

【问题讨论】:

    标签: list amazon-dynamodb aws-amplify aws-appsync


    【解决方案1】:

    您可以使用list_append (list1, list2) 在更新操作中append an item to the end of a list。 DynamoDB 不支持其他列表操作。您可以通过索引access nested list itemsset #keys[0].#status=:s

    您可以将此附加逻辑添加到您的 AppSync 解析器。

    【讨论】: