Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 2

Authenticate React application with Github's web-exposed GraphQL API?

Hi folks,

 

I have a basic react app built with create-react-app and hosted on GitHub Pages. The purpose of the app will be to track a user's commits, PRs, etc as a sort of "scoreboard": https://github.com/amartincastro/commit-counter

 

Eventually this app will be served on a wifi-connected Raspberry Pi & display on my desk.

 

I'd like to send requests to the GitHub GraphQL API to deliver this data, and I've already written the query below.

 

 

I've created the private key to access the API, and I've found some curl requests that you can use to submit the query, but I am not sure where to include a curl request in my application. Do I need to use some 3rd party library like Axios or https://www.npmjs.com/package/react-http-request?

 

Thanks, 

 

Ariel

1 Reply
Copilot Lvl 3
Message 2 of 2

Re: Authenticate React application with Github's web-exposed GraphQL API?

Whoops. Here's the query:

 

query { 
  viewer { 
    issues {
      totalCount
    },
    repositories {
      totalCount
    },
    contributionsCollection {
      totalCommitContributions,
      totalPullRequestContributions,
      totalIssueContributions,
      commitContributionsByRepository {
        repository {
          name
        },
        contributions(last: 100, orderBy: { direction: DESC, field: OCCURRED_AT }) {
          totalCount,
          pageInfo {
            hasNextPage,
            endCursor
          },
          nodes {
            commitCount,
            occurredAt
          }
        }
      }
    }
  }
}