I'm creating my first schema for a new DynamoDB using graphql in AWS Amplify. I noticed many examples where there is no @key directive to define the primary key such as "Product" below:
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"])
}
Is the first field automatically used as the primary key (partition key)?
Your question made me realize how poorly documented is this behavior. The closest I found is in this article: https://medium.com/@dantasfiles/exploring-the-backend-specifications-generated-by-aws-amplify-api-57be2a349fa9
If you don't specify a key Amplify/AppSync does that for you, creating an id
field
Like it does with other fields (i.e: createdAt
, updatedAt
)
Because no default @key annotation was specified, the AccountRepresentative table has the default id partition/hash key.