在 AppSync 上,如何查询按多对多关系排序的模型?

时间:2021-04-22 10:39:47

标签: amazon-web-services graphql aws-amplify aws-appsync dynamodb-queries

我有这个架构:

type Brand @model
  @key(name: "ByName", fields: ["name"])
  @searchable
{
  id: ID!
  name: String!
  link: String
  image: String
  bio: String
  votes: [Vote] @connection(keyName: "byBrand", fields: ["id"])
}


type Vote @model
  @key(name: "byUser", fields: ["userID"]) ## BelongsTo User. Index by userId
  @key(name: "byBrand", fields: ["brandID", "userID"], queryField: "voteByBrand")
  @searchable
{
  id: ID!
  userID: String!
  userPhone: String!
  brandID: ID!
  # productTypeID: ID!
  image: String
  comment: String
  # BelongTo User
  user: User! @connection(fields: ["userID"])
  # BelongTo Brand
  brand: Brand! @connection(fields: ["brandID"])
}

我想查询所有品牌并按得票最多的品牌排序。

品牌 1 -> 20 票;品牌 2 -> 15 票;品牌 3 -> 8 票;品牌 4 -> 5 票;

在 appSync 上,似乎不可能。你能帮我吗?

0 个答案:

没有答案