Gatsby Blog with Contentful CMS, how to sort blog posts by date

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Gatsby Blog with Contentful CMS, how to sort blog posts by date



My query looks like this(i have left some variables out):


allContentfulBlog(
filter: node_locale: eq: "en-US"
sort: fields: [node___date], order: DESC
)
edges
node
id
date(formatString: "DD MMMM, YYYY")





Terminal error:



GraphQL Error Argument "sort" has invalid value fields:
[node___date], order: DESC. In field "fields": In element #0:
Expected type "ContentfulBlogConnectionSortByFieldsEnum", found
node___date.



For sorting this i tried all arguments i saw in tutorials or could think of. I think its something regarding Contentful and it's data format that goes into my gatsby app.



Terminal screenshot



terminal screenshot
Browser screenshot



browser output




1 Answer
1



This did the trick:



sort: fields: [date], order: DESC



I found it in a Gatsby-Contentful-Starter; I had the false impression the syntax needs to be something like fieldName___argumentByWichToSort





For figuring out the right queries I can highly recommend the included GraphiQL interface. :) With this you have a powerful autocompletion at hand. gatsbyjs.org/tutorial/part-five/#introducing-graphiql
– stefan judis
Aug 6 at 7:56






@stefanjudis GraphiQL doesn't work with arguments like filter or sort, nor suggests them when you press Ctrl + Enter
– index.jsx
Aug 9 at 4:06







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS