Search code examples
amazon-web-servicesgraphqlaws-amplify

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.


Solution

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