带有AWS Amplify的GraphQL-如何启用查询排序 [英] GraphQL with AWS Amplify - how to enable sorting on query

查看:317
本文介绍了带有AWS Amplify的GraphQL-如何启用查询排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始研究AWS Amplify. 我设法使用GraphQl设置了API. 基本上,在创建API的过程中,Amplify会向您询问有关API的几个问题,并指导您完成其创建过程. 在某个时候,要求您创建一个架构.我选择的架构如下:

I've recently started looking into AWS Amplify. I have managed to setup an API using GraphQl. Basically, during the API creation, Amplify ask you a few questions about the API and guides you through its creation. At some point, you are requested to create a schema. The schema I selected is as follows:

type User @model {
  id: ID!
  username: String!
  email: String
}

type Highscore @model {
  points: Int!,
  id: ID!
  ownerId: ID!,
  numRounds: Int,
  date: String, 
}

使用这种模式,Amplify能够生成允许我执行以下操作的代码:

with this schema, Amplify is able to generate code that allows me to do things such as:

  • 变异用户和高分
  • 查询所有用户
  • 查询所有高分

有人知道我该怎么做到吗?

Does anyone know how I could achieve this?

我已经研究了@key指令( https://aws-amplify.github.io/docs/cli-toolchain/graphql#key ),但将架构更新为包含

I've looked into the @key directive (https://aws-amplify.github.io/docs/cli-toolchain/graphql#key) but updating the schema to include

type Highscore @model @key((fields: ["points"] {
...
}

没有产生预期的结果.

不幸的是,Amplify使用此架构生成的代码不允许对查询进行排序.

unfortunately, the code generated by Amplify using this schema does not allow sorting of the query.

我希望能够查询所有的高分,并根据分数进行排序.

推荐答案

已提出此问题,并已在GitHub Amplify CLI回购中回答. https://github.com/aws-amplify/amplify-cli/issues/2307

This question was raised and has been responded in the GitHub Amplify CLI repo. https://github.com/aws-amplify/amplify-cli/issues/2307

这篇关于带有AWS Amplify的GraphQL-如何启用查询排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆