index.jsx
index.jsx

Reputation: 163

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

Upvotes: 1

Views: 1607

Answers (1)

index.jsx
index.jsx

Reputation: 163

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

Upvotes: 3

Related Questions