Skip to content

Fix broken GraphQL sorting when search is present

Problem

Due to the custom CASE ordering, search and pagination crashes after the first page for Member/User related GraphQL queries.

For example, this works:

{
  group(fullPath:"gitlab-org") {
    groupMembers(search: "in", first: 5){
      nodes {
        id
        user {
          name
        }
      }
      pageInfo {
        hasNextPage
        startCursor
        endCursor
      }
    }
  }
}

Copy the endCursor and run a query for the second page:

{
  group(fullPath:"gitlab-org") {
    groupMembers(search: "in", first: 5, after: "eyJpZCI6IjU2NTc5NDAwIiwibmFtZSI6IiJ9"){
      nodes {
        id
        user {
          name
        }
      }
      pageInfo {
        hasNextPage
        startCursor
        endCursor
      }
    }
  }
}

As the response, we get the following:

{
  "errors": [
    {
      "message": "Internal server error"
    }
  ]
}

Fix

The query uses the old GraphQL keyset pagination code, which does not work well for joined (users is joined) relations and multi-column sorting. Migration to the new keyset pagination library would solve the problem.

How: Turn the ORDER BY query generation in the User model to be compatible with the new keyset pagination library.

A few examples: