Luis Garcia
Luis Garcia

Reputation: 125

Data modelling for ecommerce website using Amplify + GraphQL + DynamoDB

I'm using Amplify from AWS to build a small ecommerce project using React as frontend.

I'd like to know how I should write the "Product" and "Order" types in the schema in order to be able to write productId's to a product array in the Order table when users complete a purchase.

My schema.graphql file:

type Product @model {
  id: ID!
  name: String!
  price: Int!
  category: String!
  images: [String]!
}

type Order @model {
  id: ID!
  products: [Product] @connection
}

My question is about the last line, do I need to define that [Product] connection there or I can use [String] to store product id's in a simple string array?

Upvotes: 0

Views: 1542

Answers (1)

Saquibul Islam Waheed
Saquibul Islam Waheed

Reputation: 470

Point 1: In dynamoDB, you only need to define the data type of your partition key and sort key, and these can be string, number etc. For all the other attributes, you don't need to define anything.

Point 2: The dynamoDB designers prefer using a single table per application, unless it's impossible to manage data without multiple tables. Keeping this in mind, your table can be something like this.

enter image description here

Please observe: Only Id aka partition key and Sk aka sort key column is fixed here, all other columns can be anything per item. This is the beauty of DynamoDB. Refer to this document for dynamoDB supported data types.

Upvotes: 1

Related Questions