graph.cool двусторонние привязки - PullRequest
0 голосов
/ 23 февраля 2019

Я только начинаю с graph.cool, я пытаюсь построить модал данных graphql с помощью graph.cool.Кажется, нам всегда нужно делать двусторонние привязки.Например, User -> Posts or 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, и я не знаю, как связать его с пользователем, создавшим корзину.Помощь будет оценена.

CartItem
    ✖ A relation directive with a name must appear exactly 2 times. Relation name: 'CartItemProduct'
...