Fetching data from the GitHub graphql API
Over the past few years, GitHub has been enabling developers to build on our platform as 3rd party integrators. This enablement does not come without limitations such as rate-limiting and token access. Open Sauced originally started as a way to try out the GitHub GraphQL API with a production-ready application.
Implementation approach
Open Sauced is exclusively powered by the public data from open source repos. Not only is the data drawn from open sourced repos, the onboarding flow for Open Sauced walks the user through creating their own open sourced repo in order to track their own contributions.
OneGraph
OneGraph is the tool used to consume the GitHub GraphQL API through one consistent GraphQL interface.
Persisted queries
Persisted queries are an advanced GraphQL feature that allow clients to pre-register queries with the server. In a typical workflow, the client will send the query to the server as part of a build process and the server will send back an id for the query. When the client wants to run the query, it sends the id instead of the full query string.
Developers use persisted queries because they reduce the amount of bandwidth sent from the client to the server and they improve security by locking down the queries that can be sent to the server.
OneGraph makes this all easy to do, and you can read up more on that in their documentation.
Goals repository
Each Open Sauced user leverages their own GitHub repository as a database. The repository is generated during sign up and is the companion for finding open source contributions to make. All data in this repository is a mirror of the data you see on the opensauced.pizza dashboard.
The repo open-sauced/goals-template is used as a template repo to generate the user's open-sauced-goals
repo.
data.json The Open Sauced goal data in this list is populatated using the goals-caching.yml. Each opened issue in the goals repo full name is stored along with star, forks, and issues count. This is needed for rendering the user's open sauced dashboard.
stars.json The Open Sauced recommendation data is stored using the logged in user's starred repositories. This data is accessible via the GitHub API and stored publically in goals repo for easy rendering. The list is populatated using the goals-caching.yml. Plans are being developed to power platform wide recommendations using this data, this is pending the reviewing of the GitHub TOCs.
Use of API in components
The following table shows which components (src/components/*.js
) use which API functions (src/lib/apiGraphQL.js', 'src/lib/persistedGraphQL.js
), and what they do.
Component | API Function | Persisted/Dynamic | Mutation |
---|---|---|---|
AddRepoForm | api.createGoal Add goal through form input | Dynamic | x |
Contributions | api.persistedInteractionsFetch Contributions list for the user | Persisted | |
CreateGoals | api.fetchOwnerId Need the repo owner ID first | Dynamic | |
CreateGoals | api.createOpenSaucedGoalsRepo Create from template | Dynamic | x |
DangerZone | api.updateGoal Remove the goal | Dynamic | x |
Issues | api.persistedIssuesByLabelFetch Fetch Goal's issues labeled good first issue (First 5) | Persisted | |
Issues | api.persistedIssuesFetch Fetch Goal's all issues (First 5) | Persisted | |
Issues | api.persistedRepositoryIssuesByLabelFetch Fetch Goal's all issues (Paginated) | Persisted | |
Issues | api.persistedRepositoryIssuesFetch Fetch Goal's issues labeled good first issue (Paginated) | Persisted | |
NoteForm | api.updateGoal Updates Notes | Dynamic | x |
RecommendedRepoList | api.createGoal Add goal based on recommendations list | Dynamic | x |
Repository | api.persistedRepoDataFetch Gather partial data for goal | Persisted | |
Repository | api.fetchGoalQuery Gather partial data for goal | Dynamic | |
Repository | api.persistedForkFetch Look at whether user has this repo forked | Persisted | |
Repository | api.persistedForkFetch Initiate forking the repo for the user | Persisted | |
RepositoryGoals | api.persistedViewerStars Fetch repos starred by the user | Persisted | |
AdminStatsBar | api.fetchRateLimit Shows administrator the status of rate limiting | Dynamic | |
AdminStatsBar | api.persistedDeploymentFetch Shows administrator deployment status | Persisted | |
AdminStatsBar | api.fetchRepoCount Shows administrator the user count, based on count of open-sauced-goals repos | Dynamic |