Graphql graph.cool双向绑定
我只是从Graphql graph.cool双向绑定,graphql,graphcool,Graphql,Graphcool,我只是从graph.cool开始,我正试图在graph.cool的帮助下构建一个graphql数据模型。 似乎我们总是需要进行双向绑定。 例如User->Posts或Posts->User. 我做了一个这样的结构: type User @model { id: ID! @isUnique name: String cart: Cart @relation(name: "UserCart") } type Category @model { id: ID! @isUnique
graph.cool
开始,我正试图在graph.cool
的帮助下构建一个graphql数据模型。
似乎我们总是需要进行双向绑定。
例如User->Posts或Posts->User.
我做了一个这样的结构:
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")
}
一切如期而至。但是当我创建cartItems时,它有一个Product属性,我不知道如何将它与创建cart的用户连接。
我们将不胜感激
CartItem
✖ A relation directive with a name must appear exactly 2 times. Relation name: 'CartItemProduct'