首页 > 解决方案 > 具有跨多对多关系过滤的 Amplify/DynamoDB 请求数据表

问题描述

我尝试通过多对多关系过滤来请求表,但在放大 graphql 或 dynamoDB 上似乎是不可能的。

我有三个关系表。品牌、主题、产品类型。

我的问题是:如何通过 topicId 和 ProductTypeID 过滤来选择所有品牌?

无论解决方案如何,dynamoDb sdk、弹性@searchable 数据、扫描 dynamo db、partiQL,直接在 graphql 解析器上。我随便拿。

这是我的graphql架构:

type Topic @model
  @key(name: "topicByName", fields: ["name"])
  @searchable
{
  id: ID!
  name: String!
  color: String
  icon: String
  brands: [BrandTopic] @connection(keyName: "byTopic", fields: ["id"])
}

type BrandTopic @model
  @key(name: "byTopic", fields: ["topicID", "brandID"])
  @key(name: "byBrand", fields: ["brandID", "topicID"])
{
  id: ID!
  topicID: ID!
  brandID: ID!
  topic: Topic! @connection(fields: ["topicID"])
  brand: Brand! @connection(fields: ["brandID"])
}

type ProductType @model
  @key(name: "productTypesByName", fields: ["name"])
  @searchable
{
  id: ID!
  name: String!
  color: String
  icon: String
  brands: [BrandProductType] @connection(keyName: "byProductType", fields: ["id"])
}

type BrandProductType @model(queries: null)
  @key(name: "byProductType", fields: ["productTypeID", "brandID"])
  @key(name: "byBrand", fields: ["brandID", "productTypeID"])
{
  id: ID!
  productTypeID: ID!
  brandID: ID!
  productType: ProductType! @connection(fields: ["productTypeID"])
  brand: Brand! @connection(fields: ["brandID"])
}

type Brand @model
  @key(name: "ByName", fields: ["name"])
  @searchable
{
  id: ID!
  name: String!
  link: String
  image: String
  bio: String
  topics: [BrandTopic] @connection(keyName: "byBrand", fields: ["id"])
  productTypes: [BrandProductType] @connection(keyName: "byBrand", fields: ["id"])
  createdAt: AWSDateTime! #important to keep it to have filter with keys
  updatedAt: AWSDateTime! #important to keep it to have filter with keys
}

标签: amazon-dynamodbaws-amplifydynamodb-queriesaws-elasticsearch

解决方案


推荐阅读