我正在开发一个使用AWS AppSync的消息应用程序。
我有以下消息类型..。
type Message
@model
@auth(
rules: [
{ allow: groups, groups: ["externalUser"], operations: [] }
]
) {
id: ID!
channelId: ID!
senderId: ID!
channel: Channel @connection(fields: ["channelId"])
createdAt: AWSDateTime!
text: String
}我还订阅了onCreatemessage。我需要过滤的结果,只有渠道,用户在其中。因此,我从权限表中获得了一个通道列表,并将以下内容添加到响应映射模板中。
$extensions.setSubscriptionFilter({
"filterGroup": [
{
"filters" : [
{
"fieldName" : "channelId",
"operator" : "in",
"value" : $context.result.channelIds
}
]
}
]
})
$util.toJson($messageResult)而且效果很好。但是,如果用户在5个以上的通道中,我会得到以下错误。
{
"message": "Connection failed: {"errors":[{"message":"subscription exceeds maximum value limit 5 for operator `in`.","errorCode":400}]}"
}我是vtl的新手。所以我的问题是,我怎样才能把这个过滤器分解成多个或多个过滤器呢?
发布于 2022-10-12 16:44:41
根据创建增强订阅筛选器,“一个过滤器中的多个规则是使用和逻辑计算的,而滤波器组中的多个过滤器是使用OR逻辑计算的”。
因此,据我所知,您只需要将$context.result.channelIds分成5组,并为每个组向filters数组添加一个对象。
下面是一个VTL模板,它将为您完成此任务:
#set($filters = [])
#foreach($channelId in $context.result.channelIds)
#set($group = $foreach.index / 5)
#if($filters.size() < $group + 1)
$util.qr($filters.add({
"fieldName" : "channelId",
"operator" : "in",
"value" : []
}
))
#end
$util.qr($filters.get($group).value.add($channelId))
#end
$extensions.setSubscriptionFilter({
"filterGroup": [
{
"filters" : $filters
}
]
})您可以看到这个模板在这里运行:https://mappingtool.dev/app/appsync/042769cd78b0e928db31212f5ee6aa17
(注意:第15行的映射工具错误是动态填充$filters数组的结果。你可以安全地忽略它们。)
https://stackoverflow.com/questions/73325863
复制相似问题