如何使用Neo4J和Neo4J GraphQl库与@Auth创建关注/关注关系?

发布于 2025-01-25 18:42:50 字数 1367 浏览 3 评论 0原文

使用以下架构:


type Profile {
      id: ID! @id
      username: String! @unique(constraintName: "unique_email")
      follows: [Profile!]!
        @relationship(
          type: "FOLLOWS"
          properties: "BaseRelationship"
          direction: OUT
        )
      followers: [Profile!]!
        @relationship(
          type: "FOLLOWS"
          properties: "BaseRelationship"
          direction: IN
        )
    }

将其扩展为使用@Auth指令:

extend type Profile
  @auth(
    rules: [
      { operations: [CREATE, UPDATE, DELETE, UPDATE, CONNECT, DISCONNECT], allow: { username: "$jwt.name" } }
      { operations: [READ], isAuthenticated: true }
    ]
  )

我只是在尝试以下突变时才被禁止(jwt.name是code> user1):

mutation UpdateProfiles {
  updateProfiles(
    where: { username: "user1" }
    update: {
      follows: [{ connect: [{ where: { node: { username: "user2" } } }] }]
    }
  ) {
    info {
      relationshipsCreated
    }
  }
}

只需要使User1关注用户2,反之亦然。尝试将更改为 bind其中和突变的变化,但我无法正常工作。

如果我使用相同的突变,但请两个参数User1,那么User1就可以跟随自己,因此我认为无法允许传入的连接到User2是错误的。

但是,我该如何允许授权用户可以关注其他人?

Using the following schema:


type Profile {
      id: ID! @id
      username: String! @unique(constraintName: "unique_email")
      follows: [Profile!]!
        @relationship(
          type: "FOLLOWS"
          properties: "BaseRelationship"
          direction: OUT
        )
      followers: [Profile!]!
        @relationship(
          type: "FOLLOWS"
          properties: "BaseRelationship"
          direction: IN
        )
    }

And extending it to use the @auth directive:

extend type Profile
  @auth(
    rules: [
      { operations: [CREATE, UPDATE, DELETE, UPDATE, CONNECT, DISCONNECT], allow: { username: "$jwt.name" } }
      { operations: [READ], isAuthenticated: true }
    ]
  )

I am only getting forbidden when I try the following mutation (jwt.name is user1):

mutation UpdateProfiles {
  updateProfiles(
    where: { username: "user1" }
    update: {
      follows: [{ connect: [{ where: { node: { username: "user2" } } }] }]
    }
  ) {
    info {
      relationshipsCreated
    }
  }
}

Just want to make user1 follow user2 and vice versa. Tried changing allow to bind and to where and variations of the mutation but I can't get it to work.

If I use the same mutation but make both arguments user1, then user1 is able to follow himself, so I assume there is something wrong with not being able to allow the incoming connection to user2.

But how can I allow that the authorized user can follow someone else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文