last and first not working in API V4 search query for repos?

Hello,
I ran the below query but got the same list of repos whether I use first or last. Any idea why?

{
  search(query: "atom", type: REPOSITORY, first: 10) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          nameWithOwner
        }
      }
    }
  }
}

Thanks,

Guillaume

1 Like

Hello,

I’ve been trying to run the following to get first 100 users’s total followers 

{
  search(query: "type:user", first: 100, type: USER) {
    edges {
      node {
        ... on User {
          login
          name
          createdAt
          followers {
            totalCount
          }
        }
      }
    }
  }
}

And I have the same issue as you, I’ve reviewing my code for a while but I can’t happen to find a solution. Would be glad to know if you’ve got one.

I’m not certain, but I suspect this is because you’re using a search query which has a built-in way of sorting results. For example, if you sorted by stars and wanted the last 10 results (in other words, the 10 repositories with the least stars), you could rewrite the query to this:

{
  search(query: "atom sort:stars-asc", type: REPOSITORY, first: 10) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          nameWithOwner
        }
      }
    }
  }
}

But if you wanted the repos with the most stars it would be:

{
  search(query: "atom sort:stars", type: REPOSITORY, first: 10) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          nameWithOwner
        }
      }
    }
  }
}

I hope that helps!

1 Like