Open source Enterprise Grafana Cloud

GitHub GraphQL API

Query GitHub repositories, issues, pull requests, and organization data using the GitHub GraphQL API.

Before you begin

Configure the data source

  1. In Grafana, navigate to Connections > Data sources.
  2. Click Add new data source and select Infinity.
  3. Expand the Authentication section and select Bearer Token.
  4. Enter your GitHub Personal Access Token.
  5. In Allowed hosts, enter https://api.github.com.
  6. Click Save & test.

Tip

You can also use Basic Authentication with your GitHub username and PAT as the password, but Bearer Token is the recommended approach.

Query GitHub data

Use GraphQL queries to retrieve GitHub data. The GitHub GraphQL endpoint is https://api.github.com/graphql.

Basic query setup

  1. In the query editor, set Type to GraphQL.
  2. Set URL to https://api.github.com/graphql.
  3. Set Parser to Backend or UQL.
  4. Enter your GraphQL query.
  5. Set the Root selector to extract your data (for example, data.repository.issues.edges).

Query examples

List repository issues

GraphQL query:

graphql
{
  repository(owner: "grafana", name: "grafana") {
    issues(last: 20) {
      edges {
        node {
          author {
            login
          }
          state
          title
          url
        }
      }
    }
  }
}

Root selector: data.repository.issues.edges

Columns:

SelectorAlias
node.titleTitle
node.stateState
node.author.loginAuthor
node.urlURL

Organization repository summary

Query multiple repositories in an organization:

graphql
{
  repositoryOwner(login: "grafana") {
    repositories(first: 100) {
      nodes {
        name
        stargazerCount
        issues(states: OPEN) {
          totalCount
        }
        pullRequests(states: OPEN) {
          totalCount
        }
      }
    }
  }
}

Root selector: data.repositoryOwner.repositories.nodes

Columns:

SelectorAliasType
nameRepositorystring
stargazerCountStarsnumber
issues.totalCountOpen Issuesnumber
pullRequests.totalCountOpen PRsnumber

Pull request metrics

graphql
{
  repository(owner: "grafana", name: "grafana") {
    pullRequests(last: 50, states: MERGED) {
      nodes {
        title
        mergedAt
        author {
          login
        }
        additions
        deletions
      }
    }
  }
}

Root selector: data.repository.pullRequests.nodes

Use template variables

Replace hardcoded values with Grafana template variables:

graphql
{
  repository(owner: "${GithubOrg}", name: "${GithubRepo}") {
    issues(last: 20, states: OPEN) {
      edges {
        node {
          title
          state
          createdAt
        }
      }
    }
  }
}

Create dashboard variables for GithubOrg and GithubRepo to make the dashboard dynamic.

Provision the data source

Configure GitHub authentication through provisioning:

YAML
apiVersion: 1
datasources:
  - name: GitHub Infinity
    type: yesoreyeram-infinity-datasource
    jsonData:
      auth_method: bearerToken
      allowedHosts:
        - https://api.github.com
    secureJsonData:
      bearerToken: YOUR_GITHUB_PAT

Troubleshoot

IssueCauseSolution
401 Bad credentialsInvalid or expired PATGenerate a new Personal Access Token
403 ForbiddenInsufficient PAT scopesAdd required scopes (repo, read:org) to your PAT
Empty responseWrong root selectorCheck the GraphQL response structure and update selector
Rate limit exceededToo many requestsWait for rate limit reset or use a PAT with higher limits

Limitations

  • Queries are not automatically paginated. For large result sets, use cursor-based pagination in your GraphQL query.
  • GitHub API rate limits apply (5,000 requests per hour for authenticated requests).
  • For comprehensive GitHub analytics with built-in pagination, consider the GitHub data source.

Additional resources