How to sort by multiple fields in GraphQL

Wasn't quick to find the official documentation for this, so here it is in case you're wondering.

Single field sorting

sort: { order: ASC, fields: frontmatter___season }

Multiple field sorting

You can define an array of values for both order an fields.

sort: { order: [ASC, ASC], fields: [frontmatter___season, frontmatter___episode] }

My full working query for printing a list of TV Shows ordered by season and then by the episode number.

query MyQuery { allMarkdownRemark( sort: { order: [ASC, ASC], fields: [frontmatter___season, frontmatter___episode] } ) { edges { node { id frontmatter { title } } } } }

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*