Let's say that a user creates an order with products in a e-shop, but ordered products have their options to be selected during order process. So user has to select products with some options to buy.
In graphql there are three types: Product
, ProductOption
and 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!
}
The question is: what is the best approach of relationships between order, products and selected options?
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!
...
}