I am just starting with graph.cool
, I am trying to build a graphql data modal with the help of graph.cool
.
It seems like we always need to make two way bindings.
For example User -> Posts or Posts -> User.
I made a structure like this:
type User @model {
id: ID! @isUnique
name: String
cart: Cart @relation(name: "UserCart")
}
type Category @model {
id: ID! @isUnique
name: String!
image: String
description: String
subCategories: [SubCategory!]! @relation(name: "CategoriesSubCategories")
}
type SubCategory @model {
id: ID! @isUnique
name: String!
products: [Product!]! @relation(name: "SubCategoryProduct")
category: Category! @relation(name: "CategoriesSubCategories")
}
type Product @model {
id: ID! @isUnique
name: String
image: String
description: String
basePrice: Int
subCategory: SubCategory @relation(name: "SubCategoryProduct")
}
type Cart @model {
id: ID! @isUnique
cartItems: [CartItem!]! @relation(name: "CartItems")
user: User! @relation(name: "UserCart")
}
type CartItem @model {
id: ID! @isUnique
quantity: Int
#i need to do two way binding for this
product: Product @relation(name: "CartItemProduct")
# -----
cart: Cart! @relation(name: "CartItems")
}
Everything is as expected. but when I created the cartItems, It has a property of Product and I don't know how to connect it with the user who created the cart. Help would be appreciated.
CartItem
✖ A relation directive with a name must appear exactly 2 times. Relation name: 'CartItemProduct'