GraphQL:@auth header 中的访问类型属性
GraphQL: Access type properties within @auth header
假设我有一个类似于以下的 GraphQL 模式:
type Posts
@model
@auth(rules: [
{allow: groups, groups: ["Employees"], mutations: [create, update, delete, get, list]}
])
{
id: ID!
name: String
groups: [String]!
}
我只想允许 Post 的 groups
属性中列出的用户拥有这些属性。我想做类似的事情:
@auth(rules: [
{allow: groups, groups: [Device.groups], mutations: [create, update, delete, get, list]}
]
有什么想法可以从哪里开始?我对 GraphQL 比较陌生,我完全有可能完全走错了方向。请帮忙。
编辑
我通过修改解析器设法获得了类似的结果。在 list
的情况下,它看起来像这样:
other code...
#foreach( $postGroup in $item.groups )
#foreach( $userGroup in $userGroups )
#if( $postGroup == $userGroup )
$util.qr($items.add($item))
#end
#end
#end
...other code
这当然是一种非常低效的方法(即嵌套的 foreach 循环),但这源于我对 Apache VLT 的了解不足,将在某个时候解决。
我仍然想知道,是否可以直接在 GraphQL 架构中执行此操作?
不幸的是,GraphQL 转换尚不支持此功能,但这是一个有趣的用例,我认为我们应该进一步研究。您能否在此处添加功能请求 https://github.com/aws-amplify/amplify-cli/issues 并提供您的用例和建议,以了解如何以通用方式最好地实现它。谢谢!
假设我有一个类似于以下的 GraphQL 模式:
type Posts
@model
@auth(rules: [
{allow: groups, groups: ["Employees"], mutations: [create, update, delete, get, list]}
])
{
id: ID!
name: String
groups: [String]!
}
我只想允许 Post 的 groups
属性中列出的用户拥有这些属性。我想做类似的事情:
@auth(rules: [
{allow: groups, groups: [Device.groups], mutations: [create, update, delete, get, list]}
]
有什么想法可以从哪里开始?我对 GraphQL 比较陌生,我完全有可能完全走错了方向。请帮忙。
编辑
我通过修改解析器设法获得了类似的结果。在 list
的情况下,它看起来像这样:
other code...
#foreach( $postGroup in $item.groups )
#foreach( $userGroup in $userGroups )
#if( $postGroup == $userGroup )
$util.qr($items.add($item))
#end
#end
#end
...other code
这当然是一种非常低效的方法(即嵌套的 foreach 循环),但这源于我对 Apache VLT 的了解不足,将在某个时候解决。
我仍然想知道,是否可以直接在 GraphQL 架构中执行此操作?
不幸的是,GraphQL 转换尚不支持此功能,但这是一个有趣的用例,我认为我们应该进一步研究。您能否在此处添加功能请求 https://github.com/aws-amplify/amplify-cli/issues 并提供您的用例和建议,以了解如何以通用方式最好地实现它。谢谢!