GraphQL DynamoDB Schema中的默认主键?

问题描述 投票:1回答:1

我正在AWS Amplify中使用Graphql为一个新的DynamoDB创建第一个模式。 我注意到很多例子中没有@key指令来定义主键,比如下面的 "Product"。

type Inventory @model
  @key(name: "byWarehouseID", fields: ["warehouseID"], queryField: "itemsByWarehouseID")
  @key(fields: ["productID", "warehouseID"]) {
  productID: ID!
  warehouseID: ID!
  inventoryAmount: Int!
}

type Product @model {
  id: ID!
  name: String!
  orders: [Order] @connection(keyName: "byProduct", fields: ["id"])
  inventories: [Inventory] @connection(fields: ["id"])
}

第一个字段是否自动作为主键(分区键)?

react-native graphql amazon-dynamodb aws-amplify aws-appsync
1个回答
1
投票

你的问题让我意识到这种行为的记录有多差.我发现最接近的是在这篇文章中。https:/medium.com@dantasfilesexploring-the-backend-specifications-generated by-aws-amplify-api-57be2a349fa9。

如果你没有指定一个密钥,AmplifyAppSync会为你创建一个 id fieldLike它对其他字段的操作(即 createdAt, updatedAt)

因为没有指定默认的@key注解,所以AccountRepresentative表有默认的id partitionhash键。

© www.soinside.com 2019 - 2024. All rights reserved.