1

I can get a list of releases (with details, such as download count) using this abridged graph:

query {
  repository(owner: "UserName", name: "RepoName") {
    releases(last: 100, orderBy: { field: CREATED_AT, direction: DESC}) {
      nodes {
        releaseAssets(last: 4) {
          nodes {
            downloadCount
          }
        }
      }
    }
  }
}

The issue being that I have a limit in the pagination (100 entries).

Is there any way correctly get the total download count of the repo, maybe with number of releases without bumping into issues with the pagination limits?

Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79

1 Answers1

1

There isn't a field that sums downloadCount by release, or across releases, so the only option is to walk the graph and add them up yourself.

Release count is easier, as repository.releases has a totalCount, so you can get the total number of releases from that, and at least see whether pagination is a limit (where that totalCount is over 100). Pagination isn't so bad, here's an earlier answer I provided on that topic.

For a repo that has enough releases to need pagination. e.g. this query:

query{
  repository(owner: "microsoft", name: "typescript") {
    releases(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        releaseAssets(first: 10) {
          nodes {
            downloadCount
            name
          }
          totalCount
        }
        name
      }
      totalCount
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

ends with this response fragment:

        "totalCount": 146,
        "pageInfo": {
          "endCursor": "Y3Vyc29yOnYyOpK5MjAxOC0wMi0xMlQyMTo0MDo1NyswMDowMM4Ak_Ha",
          "hasNextPage": true
        }

So there's another page with 46 more nodes on it, which you can get at with:

query{
  repository(owner: "microsoft", name: "typescript") {
    releases(first: 100, after: "Y3Vyc29yOnYyOpK5MjAxOC0wMi0xMlQyMTo0MDo1NyswMDowMM4Ak_Ha", orderBy: {field: CREATED_AT, direction: DESC}) {
...
Chris Swan
  • 351
  • 1
  • 3
  • 8
  • Thanks! And there's no way to access the middle of the list like a trully paginated query? `PageSize = 10, Page = 3` – Nicke Manarin Dec 03 '21 at 18:49
  • The only way to get into the middle of the list is to know the cursor IDs, but there's no guarantee that the cursor IDs will remain consistent. – Chris Swan Dec 04 '21 at 07:47