GraphQL with AWS Amplify - how to enable sorting on query

走远了吗. 提交于 2020-07-22 05:17:32

问题


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, 
}

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

  • mutate users and highscores
  • query all Users
  • query all Highscores

Does anyone know how I could achieve this?

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"] {
...
}

did not produce the expected result.

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

I would like to be able to query all Highscores, and sort it according to the number of points.


回答1:


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



来源:https://stackoverflow.com/questions/57954689/graphql-with-aws-amplify-how-to-enable-sorting-on-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!