GtiHub GraphQL API query

Hi campers,

I am starting out with graphQL. I want to use the GitHub graphQL API to fetch some information from my account. I have the query below.

{
  viewer {
    login
    name
    avatarUrl
    url
    repositories(first: 20, orderBy: {field: UPDATED_AT, direction: DESC}) {
      nodes {
        ... on Repository {
          name
          description
          updatedAt
          forks {
            totalCount
          }
          licenseInfo {
            name
          }
          primaryLanguage {
            name
          }
        }
      }
    }
  }
}

My interest is in getting the total number of forks for a repository under my account (not sure I am using the right term).
image
The above query returns 0 for totalCount field. How do I fetch this fork count?

Hey there,

yes, you are on the right track.
I think forkCount is better suited for your idea: Returns how many forks there are of this repository in the whole network.

Your number is 0, because probably no one forked your repo.

I don’t know what exactly counts as a fork (if you fork a repo and another user forks from you, where does the fork belong to?), so you should research this.

I would use the Github API Explorer and use the Documentation Explorer on the right side.

1 Like