在 AppSync GraphQL 转换中,我可以根据 table 中的字段设置 @auth 规则 AuthStrategy 吗?
In an AppSync GraphQL transform, can I set an @auth rule AuthStrategy based on a field in the table?
有没有一种方法可以根据 table 中的字段有条件地设置多个 AuthStrategy?
假设我有一个博客Post类型:
type Post
@model
@auth(rules: [
{ allow: owner, operations: [read, update, delete] },
])
{
id: ID!
owner: String!
visibility: Visibility!
title: String!
body: String!
whitelist: [String!]
}
enum Visibility {
PUBLIC,
PRIVATE,
PROTECTED,
SECRET
}
我希望创建者能够设置 Post 是否为:
- Public:任何人都可以看到它,无论是否登录。
- 私有:任何登录用户都可以看到它。
- 受保护:这组用户可以看到。
- 保密:只有创作者才能看到。
我知道如何对其中的每一个进行硬编码。但是以编程方式...
这甚至可能吗,还是 AppSync 转换太基础了,我需要使用自定义解析器?
事实证明,这确实需要自定义解析器——或自定义嵌套解析器——这非常简单。
这个授权场景的官方文档:https://docs.aws.amazon.com/appsync/latest/devguide/security-authorization-use-cases.html.
还有一篇关于此授权场景的精彩 Hacker Noon 文章:https://hackernoon.com/graphql-authorization-with-multiple-data-sources-using-aws-appsync-dfae2e350bf2。
有没有一种方法可以根据 table 中的字段有条件地设置多个 AuthStrategy?
假设我有一个博客Post类型:
type Post
@model
@auth(rules: [
{ allow: owner, operations: [read, update, delete] },
])
{
id: ID!
owner: String!
visibility: Visibility!
title: String!
body: String!
whitelist: [String!]
}
enum Visibility {
PUBLIC,
PRIVATE,
PROTECTED,
SECRET
}
我希望创建者能够设置 Post 是否为:
- Public:任何人都可以看到它,无论是否登录。
- 私有:任何登录用户都可以看到它。
- 受保护:这组用户可以看到。
- 保密:只有创作者才能看到。
我知道如何对其中的每一个进行硬编码。但是以编程方式...
这甚至可能吗,还是 AppSync 转换太基础了,我需要使用自定义解析器?
事实证明,这确实需要自定义解析器——或自定义嵌套解析器——这非常简单。
这个授权场景的官方文档:https://docs.aws.amazon.com/appsync/latest/devguide/security-authorization-use-cases.html.
还有一篇关于此授权场景的精彩 Hacker Noon 文章:https://hackernoon.com/graphql-authorization-with-multiple-data-sources-using-aws-appsync-dfae2e350bf2。