【问题标题】:In an AppSync GraphQL transform, can I set an @auth rule AuthStrategy based on a field in the table?在 AppSync GraphQL 转换中,我可以根据表中的字段设置 @auth 规则 AuthStrategy 吗?
【发布时间】:2020-04-10 08:05:47
【问题描述】:

有没有办法根据表中的字段有条件地设置多个 AuthStrategy?

假设我有一个博客帖子类型:

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
}

我希望创建者能够设置帖子是否为:

  1. 公开:任何人都可以看到,无论是否登录。
  2. 私人:任何登录的用户都可以看到它。
  3. 受保护:这组用户可以看到它。
  4. 秘密:只有创作者才能看到。

我知道如何硬编码这些。但是以编程方式...

这是否可能,或者 AppSync 转换太基础了,我需要使用自定义解析器?

【问题讨论】:

    标签: amazon-web-services graphql aws-appsync


    【解决方案1】:

    事实证明,这确实需要一个自定义解析器(或自定义嵌套解析器),这非常简单。

    关于这个授权场景的官方文档: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

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 2020-04-10
      • 2022-07-04
      • 1970-01-01
      • 2012-01-28
      • 2020-04-25
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      相关资源
      最近更新 更多