How do you filter appsync queries on the server-side?

Viewed 373

I'm working with AWS Amplify on a social media platform and I have a graphql API for users Timelines and Posts.

The web app subscribes to the creation of Timelines and I'm trying to filter by the deleted field on Post. I know how to do it client-side but I'm having trouble filtering in appsync (since I don't want users to be able to get access to deleted posts). Would I use a resolver? If so where would that go in Amplify?

Schema:

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 Answers
Related