Amazon web services AppSync查询排序字段:";ceatedAt";设置为降序

Amazon web services AppSync查询排序字段:";ceatedAt";设置为降序,amazon-web-services,graphql,aws-appsync,Amazon Web Services,Graphql,Aws Appsync,在下面的schema.graphql中,当我查询userPosts时,它返回10篇文章,从最早的文章到最新的文章 type User @model { id: String! posts: [Post] @connection(name: "UserPosts", sortField: "createdAt") } 如何将此顺序设置为DESC,以使其返回最新的10篇文章而不是最旧的文章?当您使用Amplify CLI创建@model类型时,它会使用名为listPosts的查询生成您的架

在下面的schema.graphql中,当我查询userPosts时,它返回10篇文章,从最早的文章到最新的文章

type User @model {
  id: String!
  posts: [Post] @connection(name: "UserPosts", sortField: "createdAt")
}

如何将此顺序设置为DESC,以使其返回最新的10篇文章而不是最旧的文章?

当您使用Amplify CLI创建
@model
类型时,它会使用名为
listPosts
的查询生成您的架构。此查询有多个参数,其中一个参数为
sortDirection
,类型为
ModelSortDirection

ModelSortDirection是一种枚举类型,具有以下形状:

enum ModelSortDirection {
    ASC
    DESC
}
您可以传递
DESC
。此外,如果编辑
posts
Resolver,则可以从的API模式页面查看此参数的使用方式。它使用DynamoDB对从数据源返回的行进行排序

  "scanIndexForward":   #if( $context.args.sortDirection )
    #if( $context.args.sortDirection == "ASC" )
true
    #else
false
    #end

谢谢你的回答。我在哪里可以看到解析器?我可以在我的代码库中的任何地方找到“`` scanIndexForward”:#if($context.args.sortDirection)#if($context.args.sortDirection==“ASC”)true#else false#end``更新了我的答案。对不起,我错过了。您可以登录到AppSync控制台并单击API的架构页面。你应该看到这个页面上的解析器部分,在那里你可以找到编辑这个解析器的链接。明白了!非常感谢。您的意思是将
enum ModelSortDirection{ASC DESC}
添加到schema.graphql中,然后运行
放大推送
?您不需要这样做。它是由放大cli生成的