Issue on pagination & sorting

System Information
  • Strapi Version: v4.5.3
  • Operating System: MacOS Catalina
  • Database: MariaDB
  • Node Version: v16.15.1
  • NPM Version:
  • Yarn Version: 1.22.19

Hello,

I’ve had an issue when I try to combine sorting and pagination on my GraphQL requests from a NextJS front. Basically, I am trying to query the backend to fetch all records sorted by creation date from the newest to the latest, and THEN paginate them.

My query looks like this :

query getDocuments {
documents (
  sort:"updatedAt:asc"
  pagination: {page: ${page}, pageSize: 10}
){
  meta {pagination {total page pageCount}}
    data {
      id
      attributes {
        name
        category
        updatedAt
        creator {data {attributes {username}}}
      }
    }
}
}

My issue is : the pagination occurs BEFORE the sorting. Example :

If I have 4 docs like so :

  • Document 1
  • Document 2
  • Document 3
  • Document 4

I want them sorted by date and 2 by page, which would give me :

  • Document 4
  • Document 3
    And
  • Document 2
  • Document 1

But the way GraphQL works gives me this instead :

  • Document 2
  • Document 1
    Then
  • Document 4
  • Document 3

It paginates first, then sorts.

I’ve been looking for some answers here and elsewhere but haven’t found a clue. Did you observe this behavior ? Is it intended ? Is it GraphQL itself working this way or Strapi ?

Thanks in advance,

Hugs