如何在服务器端过滤 appsync 查询?

时间:2021-03-03 17:23:52

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

我在社交媒体平台上与 AWS Amplify 合作,我为用户 TimelinePost 提供了一个 graphql API。

网络应用订阅 Timeline 的创建,我正在尝试按 deleted 上的 Post 字段进行过滤。我知道如何在客户端执行此操作,但在 appsync 中过滤时遇到问题(因为我不希望用户能够访问已删除的帖子)。我会使用解析器吗?如果是这样,它会在 Amplify 中的哪个位置?

架构:

type Post 
  @model(subscriptions: { level: public })
  @key(name: "SortByTimestamp", fields:[ "type", "timestamp"], queryField: "listPostsSortedByTimestamp")
  @key(name: "BySpecificOwner", fields:[ "owner", "timestamp"], queryField: "listPostsBySpecificOwner")
  @auth(rules: [
    # {allow: owner, ownerField: "owner", provider: userPools, operations:[read, create, delete]},
    {allow: private, provider: userPools, operations:[read]},
    {allow: private, provider: iam ,operations:[create]},
  ])
{
  type: String! # Always `post`
  id: ID
  deleted: Boolean
  title: String!
  content: String!
  owner: String
  likes: Int!
  downloads: Int!
  timestamp: AWSTimestamp!
}

type Timeline 
    @model(subscriptions: { level: public })
    @auth(rules: [
      {allow: owner, ownerField: "userId", provider: userPools, operations:[read, create]},
      {allow: private, provider: iam, operations:[create]},
    ])
    @key(fields: [ "userId", "timestamp"])
{
    userId: ID!
    timestamp: AWSTimestamp!
    postId: ID!
    post: Post @connection(fields: [ "postId"])
}

0 个答案:

没有答案