首页 > 解决方案 > aws appsync 组合过滤器运算符

问题描述

AWS appsync / amplify 是否可以组合过滤器运算符,例如:

const filterInput = {
        or:[
          {
          and: [
                  {createdById: { eq: userID }},
                  {chatWithId: { eq: chatWithUser.id }}
                ]
          },
          {
          and:  [
                  {createdById: { eq: chatWithUser.id }},
                  {chatWithId: { eq: userID }}
                ]
          }
        ]
      }

因为对我来说这不是过滤/按预期工作。

标签: amazon-web-servicesgraphqlaws-appsyncaws-amplifyamplifyjs

解决方案


感谢您提供额外的信息。使用如下所示的 Amplify 架构:

type Chat @model { 
  id: ID! 
  createdAt: String 
  createdById: String 
  chatWithId: String 
  messsages: [Message] 
}

默认情况下,会创建一个带有存储 id 值的 HASH 键的表来存储这些值,并且无法有效地运行您尝试仅使用默认键结构运行的查询。将来,您将拥有更多可用于控制@model 表的索引结构的工具,但目前唯一的方法是通过@connection。

这是一个示例模式,可以帮助您开始构建可以更有效地查询这些关系的 API。

ChatQL React schema.graphql


推荐阅读