AppSync查询报错:Unsupported element '$[query][scanIndexForward]'
解决AWS AppSync中DynamoDB Resolver设置scanIndexForward报错的问题
问题出在你把scanIndexForward参数放错了位置——它是DynamoDB Query操作的顶层参数,不能嵌套在query对象里。
修正后的Resolver代码如下:
export function request(ctx) { const { chatId, limit, nextToken } = ctx.args; return { version: '2017-02-28', operation: 'Query', query: { expression: 'chatId = :chatId', expressionValues: { ':chatId': { S: chatId } } }, limit: limit || 50, nextToken, scanIndexForward: false // 移到顶层,和limit、nextToken同级 } }
原因说明:
- 在AWS AppSync的DynamoDB resolver请求格式中,
scanIndexForward是控制排序方向的独立参数,用于指定是否按排序键升序(true)或降序(false)返回结果。 - 你之前把它放在
query对象内部,不符合AppSync对DynamoDB请求的格式要求,所以触发了Unsupported element '$[query][scanIndexForward]'错误。
这样修改后,就能通过设置scanIndexForward: false实现按createdAt降序获取消息,同时正常分页。
内容的提问来源于stack exchange,提问作者Muhammad Adnan
相关产品推荐
相关产品推荐

