Search code examples
strapi

Make strapi sort entries by id/createdAt by default


I'm using Strapi v4.1.7

On my local machine when I run strapi (sqlite) on dev mode and I make a api request (rest/graphql) I get the results sorted by id/createdAt from oldest ---> newest.

But when I deployed to heroku (production mode PostgreSQL) and I make the request I get the results sorted by updatedAt from oldest ---> newest.

My question is: How can I make my production version behave the same as my developement version?

in other words How can I make strapi sort entries by id/createdAt by default?


Solution

  • This seem to work for me in Strapi v4:

    sort: "createdAt:DESC"
    

    ...

    query GetVideos($page: Int!, $pageSize: Int!) {
        videos(
          pagination: { page: $page, pageSize: $pageSize }
          sort: "createdAt:DESC"
        ) {
          __typename
          data {
            __typename
            id
            attributes {
              __typename
              createdAt
              publishedAt              
              }
            }
          }
        }
      }
    `