简体   繁体   中英

GraphQL with AWS Amplify - how to enable sorting on query

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM