I'm trying to sort the content of my YAML file by date with GraphQL. I'm publishing the notifications through Netlify CMS and using React(Gatsby) as a front end. The notifications are being written to the notifications.yml file but I can't get them sorted by date; latest first. I'm rendering the contents out fine to the site but I can't find a way to sort them by date.
I have tried using "sort: { field: date, order: DESC }" in the GraphQL query but I get the error:
Unknown argument "sort" on field "file" of type "Query". Did you mean "root"? graphql/template-strings
Here's my notifications.yml:
notifications:
- date: '2019-03-16'
message: 'First notification'
title: 'One'
- date: '2019-03-17'
message: 'Second notification'
title: 'Two'
- date: 2019-03-20'
message: 'Third notification'
title: 'Three'
GraphQL query:
query={graphql`
query NotificationQuery {
notifications: file(
relativePath: { regex: "/notifications/" }
) {
childDataYaml {
notifications {
date(formatString: "MMMM D, YYYY")
message
title
}
}
}
}
}
Could you guys please help me out?