如何使用Neo4J和Neo4J GraphQl库与@Auth创建关注/关注关系?
使用以下架构:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论