【发布时间】:2018-09-30 02:52:16
【问题描述】:
我使用 AWS Appsync 和 DynamoDB 作为它的数据源。我有 2 张桌子,一张用于照片,一张用于点赞。在 Appsync 解析器中,我只想返回超过 5 个赞的照片。如何在 Appsync 中实现这一点
架构
type Photo {
id: ID!
likes: [LikedPhoto]
}
type LikedPhoto {
id: ID!
username: String!
photoId: String!
}
查询
type Query {
listPhotos(filter: PhotoFilterInput, limit: Int, nextToken: String): PhotoConnection
}
照片解析器
数据来源:PhotoTable
{
"version": "2017-02-28",
"operation": "Scan",
"filter": #if($context.args.filter) $util.transform.toDynamoDBFilterExpression($ctx.args.filter) #else null #end,
"limit": $util.defaultIfNull($ctx.args.limit, 20),
"nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.nextToken, null)),
}
点赞解析器
数据来源:喜欢表
{
"version": "2017-02-28",
"operation": "Query",
"index": "photoId-index",
"query": {
"expression": "photoId = :photoId",
"expressionValues": {
":photoId": {
"S": "$context.source.id"
}
}
}
}
我如何为喜欢或照片编写解析器,以仅显示超过 5 个喜欢的照片。
【问题讨论】:
标签: aws-appsync