1

我正在学习 Prisma GraphQL 并尝试创建一个属于并有很多关系,但是在部署时它失败了。

场景:

  • 用户将拥有已创建评论的列表
  • 用户将有一个评论列表
  • 评论将属于作者(用户)
  • 评论将有一个用户(评论用户)

我试过的:

type User {
  id: ID! @unique
  createdAt: DateTime!
  updatedAt: DateTime!
  email: String! @unique
  password: String!
  roles: [Role!]!

  profile: Profile! @relation(name: "Profile", onDelete: CASCADE)
  addresses: [Address!]! @relation(name: "AddressAuthor", onDelete: CASCADE)
  posts: [Post!]! @relation(name: "PostAuthor", onDelete: CASCADE)
  topics: [Topic!]! @relation(name: "TopicAuthor", onDelete: CASCADE)
  subjects: [Subject!]! @relation(name: "SubjectAuthor", onDelete: CASCADE)
  votes: [Vote!]! @relatiion(name: "VoteAuthor", onDelete: CASCADE)
  notifications: [Notification!]! @relation(name: "Notification", onDelete: CASCADE)

  createdFollows: [Follow!]! @relation(name: "FollowAuthor", onDelete: CASCADE)
  followers: [Follow!]! @relation(name: "FollowedUser", onDelete: CASCADE)

  createdComments: [Comment!]! @relation(name: "CommentAuthor", onDelete: CASCADE)
  comments: [Comment!]! @relation(name: "CommentedUser")
}

type Comment {
  id: ID! @unique
  createdAt: DateTime!
  updatedAt: DateTime!
  author: User! @relation(name: "CommentAuthor")

  type: String!
  body: String!
  attachments: [Attachment!]! @relation(name: "CommentAttachment", onDelete: CASCADE)
  comments: [Comment!]! @relation(name: "CommentComment", onDelete: CASCADE)
  likes: [Like!]!
  followers: [Follow!]!

  user: User @relation(name: "CommentedUser", onDelete: CASCADE)
  post: Post
  topic: Topic
  subject: Subject
  comment: Comment @relation(name: "CommentComment")
}

但是在尝试部署它时,我得到了错误来解决和之间的Comment歧义User。那么,你能帮我如何正确定义关系吗?PostUser甚至Comment可以有很多评论。

谢谢!

4

0 回答 0