Skip to content

fix(stats): split GraphQL queries to avoid resource limits#375

Open
Dendroculus wants to merge 2 commits into
stats-organization:masterfrom
Dendroculus:fix/graphql-resource-limits-upstream
Open

fix(stats): split GraphQL queries to avoid resource limits#375
Dendroculus wants to merge 2 commits into
stats-organization:masterfrom
Dendroculus:fix/graphql-resource-limits-upstream

Conversation

@Dendroculus

@Dendroculus Dendroculus commented Jul 18, 2026

Copy link
Copy Markdown

What changed

  • split GitHub statistics fetching into separate GraphQL requests for:
    • account and count statistics
    • commit contributions
    • pull-request review contributions
    • repository pagination and star totals
    • repositories contributed to
  • preserve commit-year filtering for commit totals without limiting pull-request review totals
  • treat RESOURCE_LIMITS_EXCEEDED from repositoriesContributedTo as non-fatal
  • return null when the contributed-repositories metric is unavailable
  • omit the contributed-repositories row instead of displaying an incorrect zero or failing the entire card
  • keep other GraphQL errors fatal
  • preserve owner-affiliation filtering, PAT overrides, excluded repositories, pagination, and cached-response cloning
  • update core tests, renderer tests, backend fixtures, and API snapshots

Why

GitHub's GraphQL API can reject statistics queries with:

RESOURCE_LIMITS_EXCEEDED

Testing against domdfcoding showed that repositoriesContributedTo can exceed GitHub's resource limit even when queried separately. The remaining statistics are still available, so this optional metric should not prevent the entire card from rendering.

Fixes #373

Validation

  • repository lint passed
  • complete test suite: 36 files and 572 tests passed
  • core stats fetcher tests: 15 passed
  • backend public API contract tests: 6 passed
  • core and backend TypeScript typechecks passed
  • core package build passed
  • git diff --check passed
  • live GitHub API test passed for Dendroculus
  • live GitHub API test passed for domdfcoding
  • manually verified both accounts on a self-hosted Vercel production deployment
  • Dendroculus renders with the contributed-repositories metric
  • domdfcoding renders successfully without RESOURCE_LIMITS_EXCEEDED, omitting the unavailable contributed-repositories metric

Credit

Thank you to @domdfcoding for suggesting that the query should be split into smaller requests.

Thank you to @nightt5879 for the detailed investigation in #373 and for providing the reference implementation in anuraghazra#4916.

This PR adapts and extends that approach for GitHub Stats Extended while preserving its existing pagination, owner-affiliation, PAT, repository-exclusion, and cache-handling behavior.

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

@Dendroculus is attempting to deploy a commit to the martin-mfg's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Dendroculus Dendroculus changed the title fix(stats): split GraphQL queries to avoid resource limits fix(PARTIALLY ADDRESSED stats): split GraphQL queries to avoid resource limits Jul 18, 2026
@Dendroculus Dendroculus changed the title fix(PARTIALLY ADDRESSED stats): split GraphQL queries to avoid resource limits fix(stats): split GraphQL queries to avoid resource limits Jul 18, 2026
@Dendroculus

Dendroculus commented Jul 18, 2026

Copy link
Copy Markdown
Author

Follow-up validation completed.

I tested the final implementation against both affected accounts using the live GitHub API and my self-hosted Vercel production deployment:

  • Dendroculus renders successfully with a normal numeric repositoriesContributedTo result.
  • domdfcoding renders successfully without RESOURCE_LIMITS_EXCEEDED.
  • For domdfcoding, GitHub still rejects the optional repositoriesContributedTo query, so the card now omits that unavailable metric while preserving all remaining statistics.
  • The fallback is scoped specifically to RESOURCE_LIMITS_EXCEEDED from repositoriesContributedTo; unrelated GraphQL errors continue through the existing error-handling flow.

Additional validation:

  • repository lint passed
  • complete test suite passed: 36 test files, 572 tests
  • core and backend TypeScript typechecks passed
  • core package build passed
  • backend public API contract tests passed
  • git diff --check passed

I also performed local live-API validation against several public accounts with different contribution histories. The results confirmed all relevant states:

  • positive numeric values are preserved
  • a successful zero remains 0
  • an unavailable value becomes null
  • the fallback is only used when GitHub cannot calculate the optional metric
  • every tested card still renders successfully
Local live GitHub API validation results showing positive, zero, and fallback states for repositoriesContributedTo

@Project516

Copy link
Copy Markdown

Confirming this fixes a real account (re: #373).

My profile card (user project516, ~104 public repos) has been failing with "Resource limits for this query exceeded". I traced it by running the pieces of the old bundled query directly against the GraphQL API:

  • The main query with no contributionsCollection (stars, PRs, issues, followers, repos) passes.
  • commits (totalCommitContributions) passes alone: 1485.
  • reviews (totalPullRequestReviewContributions) passes alone: 97.
  • Any two contribution aggregations in a single query fail.
  • repositoriesContributedTo fails on its own, three tries in a row.

That last one is why splitting alone isn't enough for my account: repositoriesContributedTo can't be fetched at all right now, so a per-query split would still throw. This branch handles it. When that query returns only resource-limit errors it sets the field to null instead of throwing (packages/core/src/fetchers/stats.js around line 328), and the rest of the card renders. That matches exactly what my account needs. Hope this helps get it reviewed.

Project516 pushed a commit to DeelerDev/github-stats-extended that referenced this pull request Jul 18, 2026
Splits the bundled stats query into separate requests and drops
repositoriesContributedTo to null when GitHub rejects it, so accounts
that hit the per-query resource limit still render. Applies PR stats-organization#375 from
stats-organization/github-stats-extended ahead of the upstream merge.
Revert with a reset to upstream master once stats-organization#375 lands there.
Project516 added a commit to DeelerDev/github-stats-extended that referenced this pull request Jul 18, 2026
Splits the bundled stats query into separate requests and drops
repositoriesContributedTo to null when GitHub rejects it, so accounts
that hit the per-query resource limit still render. Applies PR stats-organization#375 from
stats-organization/github-stats-extended ahead of the upstream merge.
Revert with a reset to upstream master once stats-organization#375 lands there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some usernames fail with "Resource limits for this query exceeded"

2 participants