GraphQL DynamoDB 架构中的默认主键?
Default Primary Key in GraphQL DynamoDB Schema?
我正在 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"])
}
第一个字段是否自动用作主键(分区键)?
你的问题让我意识到这种行为的记录是多么糟糕。
我找到的最接近的是这篇文章:https://medium.com/@dantasfiles/exploring-the-backend-specifications-generated-by-aws-amplify-api-57be2a349fa9
如果您没有指定键,Amplify/AppSync 会为您指定,创建一个 id
字段
就像其他字段一样(即:createdAt
、updatedAt
)
Because no default @key annotation was specified, the AccountRepresentative table has the default id partition/hash key.
我正在 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"])
}
第一个字段是否自动用作主键(分区键)?
你的问题让我意识到这种行为的记录是多么糟糕。 我找到的最接近的是这篇文章:https://medium.com/@dantasfiles/exploring-the-backend-specifications-generated-by-aws-amplify-api-57be2a349fa9
如果您没有指定键,Amplify/AppSync 会为您指定,创建一个 id
字段
就像其他字段一样(即:createdAt
、updatedAt
)
Because no default @key annotation was specified, the AccountRepresentative table has the default id partition/hash key.