滤波器表达式只能包含非主要密钥属性

发布于 2025-01-31 19:36:58 字数 690 浏览 4 评论 0原文

我是AWS放大的新手,并为我正在研究的项目创建了一个GraphQl API,以学习它& Appsync。从本质上讲,我有一个看起来如下的模式:

type User @model {
  id: ID! @primaryKey
  boards: [Board] @hasMany
  createdAt: String!
  updatedAt: String!
}

type Board @model {
  id: ID! @primaryKey
  createdBy: User!
  title: String!
}

我正在尝试在AppSync控制台中运行以下查询:

query MyQuery {
  listUsers {
    items {
      boards {
        items {
          title
        }
      }
    }
  }
}

但是由于某些原因,我一直看到此错误:

Filter Expression can only contain non-primary key attributes: Primary key attribute: userBoardsId

我已经指定了这两个模型中的主要键,而我' m知道AppSync会生成“用户板”外键,但我不确定为什么会引起问题。

I'm new to AWS Amplify, and have created a GraphQL API for a project that I'm working on in order to learn it & AppSync. Essentially I have a schema that looks like the following:

type User @model {
  id: ID! @primaryKey
  boards: [Board] @hasMany
  createdAt: String!
  updatedAt: String!
}

type Board @model {
  id: ID! @primaryKey
  createdBy: User!
  title: String!
}

and I'm trying to run the following query in the AppSync console:

query MyQuery {
  listUsers {
    items {
      boards {
        items {
          title
        }
      }
    }
  }
}

But for some reason I keep seeing this error:

Filter Expression can only contain non-primary key attributes: Primary key attribute: userBoardsId

I've specified the primary key in both models, and I'm aware that AppSync generates the 'userBoardsId' foreign key, but I'm not sure why it's causing an issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芸娘子的小脾气 2025-02-07 19:36:58

你尝试过吗?由于板是数组,您需要添加项目

query MyQuery {
  listUsers {
    items {
      boards {
        items {
          title
        }
      }
    }
  }
}

编辑

type User @model {
  id: ID! @primaryKey
  boards: [Board] @hasMany (indexName: "byUser")
  createdAt: String!
  updatedAt: String!
}
type Board @model {
  id: ID! @primaryKey
  userID: ID! @index(name: "byUser")
  createdBy: User
  title: String!
}

Have you tried like this? Since boards is array, you need to add items

query MyQuery {
  listUsers {
    items {
      boards {
        items {
          title
        }
      }
    }
  }
}

EDIT:

type User @model {
  id: ID! @primaryKey
  boards: [Board] @hasMany (indexName: "byUser")
  createdAt: String!
  updatedAt: String!
}
type Board @model {
  id: ID! @primaryKey
  userID: ID! @index(name: "byUser")
  createdBy: User
  title: String!
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文