Search code examples
githubgithub-graphql

In GitHub GraphQL, what is the difference between contributionCollection->totalPullRequestContributions and user->pullRequests->totalCount?


What is the difference between these two queries in GitHub GraphQL?

query {
  user(login: "desai10") {
    contributionsCollection {
      totalPullRequestContributions
    }
  }
}

and

query{
  user(login: "desai10") {
    pullRequests {
      totalCount
    }
  }
}

?

The 1st query says I have raised 5 PRs while the 2nd one says I have raised 17 PRs (17 seems to be the correct number).

These two queries are supposed to give the same number right? What is the difference and why is it giving different results?


Solution

  • The difference is due to the way contributionsCollection is paginated. If you see the arguments to it in the GitHub doc, the from argument is defined as

    from (DateTime)

    Only contributions made at this time or later will be counted. If omitted, defaults to a year ago.

    So when you don't pass any value to it, it would default to the current year and totalPullRequestContributions would show you your pull request count for the current year (which would be 5 in your case).

    The second one, pullRequests, is a PullRequestConnection, and totalCount would give you the total count of items in the connection, which would be 17 in your case, showing your total number of pull requests.