【发布时间】:2021-09-24 22:37:29
【问题描述】:
我有这些表:
Table blocked_users
id (pk) | initiator_id (fk) | target_id (fk)
1 | a | b
Table post
id (pk) | author_profile (fk)
1 | a
2 | b
3 | c
4 | d
我正试图了解正确的选择权限,我尝试了很多组合,但我无法获得所需的结果 -> 获取帖子并排除我已阻止或他们拥有的用户阻止了我。
这是我尝试过的众多权限之一:
blocked_by_me 是blocked_users.initiator_id → author_profile.id
been_blocked_by 是blocked_users.target_id → author_profile.id
{
"_and": [
{ "deleted_at": { "_is_null": true } },
{ "author_profile": { "deleted_at": { "_is_null": true } } },
{
"_and": [
{
"author_profile": {
"been_blocked_by": {
"initiator_id": {
"_eq": "X-Hasura-User-Id"
}
}
}
},
{
"author_profile": {
"blocked_by_me": {
"initiator_id": {
"_eq": "X-Hasura-User-Id"
}
}
}
}
]
}
]
}
我尝试过的众多查询之一:(对帖子没有权限)
query GetPosts(
$created_at: order_by = desc
$limit: Int! = 12
$offset: Int! = 0
) {
post(
limit: $limit
offset: $offset
order_by: { created_at: $created_at }
where: {
_not: {
author_profile: {
_or: [
{
been_blocked_by: { initiator_id: { _eq: "a" } }
blocked_by_me: { target_id: { _neq: "b" } }
}
]
}
}
_and: {
deleted_at: { _is_null: true }
author_profile: { deleted_at: { _is_null: true } }
}
}
) {
author_profile {
id
first_name
}
}
}
通过上面的查询,如果用户发布了帖子,并且该用户的id 在blocked_users 上不存在,则查询不会返回该用户的帖子,换句话说,查询只返回在blocked_users 上至少有一条记录的用户的帖子(未被我阻止或该用户没有阻止我)。
【问题讨论】:
标签: postgresql graphql hasura