How to sort the list in nested query result in an AWS Amplify application

How to sort the list in nested query result in an AWS Amplify application


0

I am new to GraphQL and looking for some assistance in understanding how I could go by to sort the results of a nested query.

I have a schema as below, based on the documentation here – https://docs.amplify.aws/guides/api-graphql/query-with-sorting/q/platform/js/

type Segment @model {
  id: ID!
  name: String!
  order: Float!
  type: String! @index(name: "byOrder", queryField: "segmentByOrder", sortKeyFields: ["order"])
  subsegments: [SubSegment]! @hasMany(indexName: "bySegment", fields: ["id"])
}

Querying on segmentByOrder sorts the segment list but I want to understand how I can also sort the subsegments list? My query currently looks like this –

query MyQuery {
  segmentByOrder(type: "Segment", sortDirection: ASC) {
    items {
      id
      name
      order
      subsegments {
        items {
          id
          name
          order
        }
      }
    }
  }
}

This results in the list of segments being sorted but how can I also have the subsegments sorted in this result?


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *