Gatsby Category Count

Whilst rebuilding this blog I wanted to recategorise all of the existing posts. Before doing so, I wanted to see what all of my existing categories were and how many posts I had in each category.

Using graphql and the GraphQL explorer I could run a query to group by frontmatter___category and return the total count

{
allMarkdownRemark {
group(field: frontmatter___category) {
fieldValue
totalCount
}
}
}