after cursor: empty value sometimes OK, sometimes not

Hi there,

A bit baffled by what I’m experiencing, hopefully I’m missing something.

In a nutshell, I have 2 queries, one to get tags on a repo and another one to perform a search.

Both of them implement pagination and as such I have to pass the afterCursor parameter.

On the first call since there’s no afterCursor I simply pass a blank string and it works for tags but not for search:

query ($repoOwner: String!, $repoName: String!, $afterCursor: String!) {
  repository(owner: $repoOwner, name: $repoName) {
    name
    refs(refPrefix: "refs/tags/", first: 100, after: $afterCursor) {
      pageInfo {
        hasNextPage
        endCursor
      }
      // rest of the query here...
}

// variables:
{
  "repoOwner": "org name",
  "repoName": "repo name",
  "afterCursor": ""
}

yields expected results, while

query ($searchQuery: String!, $afterCursor: String!) {
  search(type: REPOSITORY, query: $searchQuery, first: 10, after: $afterCursor) {
    pageInfo {
      hasNextPage
      endCursor
    }
    // rest of the query here...
}

// variables:
{
  "searchQuery": "some search",
  "afterCursor": ""
}

yields error

“type”: “INVALID_CURSOR_ARGUMENTS”,

“message”: “`` does not appear to be a valid cursor.”

Do acceptable values for afterCursor depend on the connection?

Have you tried null instead of a blank string? It’s possible that the implementation slightly varies, yes. You may also want to try using two copies of the query, one with the after parameter and one without.

2 Likes

Making $afterCursor a String (not String!) and passing a null works!

Thanks!!

1 Like