假设用户在电子商店中创建了包含产品的订单,但订购的产品在订单处理过程中有可供选择的选项。所以用户必须选择有一些选项的产品来购买。在 graphql 中有三种类型Product
:ProductOption
和Order
。
type Product implements Node {
id: ID!
name: String!
options: [ProductOptionsConnection!]!
}
type ProductOption implements Node {
id: ID!
name: String!
product: Product!
}
type ProductOptionsConnection {
edges: [ProductOptionEdge!]!
totalCount: Int!
...
}
type ProductOptionEdge {
node: ProductOption!
}
type Order implements Node {
id: ID!
createdAt: DateTime!
products: OrderProductsConnection!
}
问题是:订单、产品和选定选项之间关系的最佳方法是什么?
1:
type OrderProductsConnection {
edges: [OrderProductEdge!]!
totalCount: Int!
...
}
type OrderProductEdge {
node: Product!
selectedOptions: [OrderProductOptionsConnection!]!
addedAt: DateTime
}
type OrderProductOptionsConnection {
edges: [OrderProductOptionEdge!]!
totalCount: Int!
...
}
type OrderProductOptionEdge {
node: ProductOption
}
2:
type OrderProductsConnection {
edges: [OrderProductEdge!]!
totalCount: Int!
...
}
type OrderProductEdge {
node: OrderProduct!
}
type OrderProduct { // implements Node??
product: Product!
selectedOptions: OrderProductOptionsConnection!
addedAt: DateTime!
}
type OrderProductOptionsConnection {
edges: [OrderProductOptionEdge]!
}
type OrderProductOptionEdge {
node: OrderProductOption!
}
type OrderProductOption { // implements Node??
option: ProductOption!
...
}