【发布时间】:2023-01-17 21:36:39
【问题描述】:
我正在使用 AWS Amplify 开发聊天功能,我的 graphql 架构中有一个简单的 Post 模型:
type Post
...
{
id: ID!
channelId: ID @index(
name: "byChannel", sortKeyFields: ["createdAt"],
queryField: "listPostsByChannel"
)
customerId: ID @index(
name: "byCustomer", sortKeyFields: ["postType", "createdAt"]
)
text: String!
postTempId: String
postType: String
reactions: [PostReaction] @hasMany(fields: ["id"])
createdAt: AWSDateTime
updatedAt: AWSDateTime
}
我想要实现的是与其他流行的聊天应用程序类似 - 每个帖子都附有表情符号的反应,所以我创建了另一个表和 PostReaction 模型。
type PostReaction
...
{
postId: ID! @primaryKey(sortKeyFields: ["customerId", "emojiUnicode"])
customerId: String!
customerMeta: CustomerMeta
emojiUnicode: String!
createdAt: AWSDateTime
updatedAt: AWSDateTime
}
当然,每个客户可以在一个帖子中添加多个表情符号,自定义主键用于稍后处理重复。
这里有一个缺点。
表情符号将在帖子的reactions字段中以数组形式列出,即使它是许多人添加的相同表情符号。
前端需要为每个帖子合并一系列简单的反应,最好的办法是从 AppSync 查询中为每个 Post 获取结果,例如:
...
reactions: [{
emojiUnicode: "U+1F44D",
customerIds: ["ID1234", "ID5678"],
...
}, {...}]
我以为我可以在 reactions 字段中使用 JSON 对象,但 DynamoDB 对单个项目的最大大小限制为 400KB。现在这不是问题,但接下来我将向 Post 模型添加更多属性时,当同时有许多人的许多反应时,这可能是一个问题。
有没有选择如何以最简单的方式实现这一目标?
【问题讨论】:
标签: amazon-web-services graphql amazon-dynamodb aws-amplify aws-appsync