4 minutes
Useful GitHub GraphQL Snippets
I’ve been building a lot of GitHub automation recently and I’ve found myself using the same GraphQL queries over and over again. I thought it would be useful to share some of the most useful ones here.
Queries
Repos
Get the first 100 repositories in an organization
This query will return a list of all repositories in an organization. It will return the name, description, and URL of each repository along with pagination information.
Get the next 100 repositories in an organization with pagination
This query will return the next 100 repositories in an organization. It will return the name, description, and URL of each repository along with pagination information. Replace $endCursor
with the value of endCursor
from the previous query.
Get the first 100 repositories in an organization with a topic filter
This query will return a list of the first 100 repositories in an organization that have a specific topic. It will return the name, description, and URL of each repository along with pagination information.
This query retrieves the existing branches in a repository.
Teams
This query fetches information about a specific team within an organization.
This query retrieves information about teams within an organization, including the names of the teams and their members.
This query retrieves repositories associated with a specific team, including the repository name and permission level.
Org
This query fetches the IP allow list entries for an organization, including details like ID, name, allow list value, and status.
Enterprise
This query retrieves statistics for an enterprise, including billing information and member count.
Mutations
Repos
This mutation updates the settings of a repository, such as its description and wiki enablement.
This mutation creates a branch protection rule for a repository.
This mutation updates an existing branch protection rule.
This mutation sets a topic (tag) for a repository.
Organizations
This mutation adds an IP to an organization’s IP allow list.