Api ReferenceGraphqlRepositories

Repositories (GraphQL)

Query repository data, branches, commits, and file contents via GraphQL.

The GraphQL API provides comprehensive access to repository data — metadata, branches, commits, file contents, and contributors.

Repository Object

type Repository {
  id: ID!
  name: String!
  fullName: String!
  description: String
  private: Boolean!
  archived: Boolean!
  defaultBranch: String!
  primaryLanguage: Language
  languages: [LanguageBreakdown!]!
  createdAt: DateTime!
  updatedAt: DateTime!
  pushedAt: DateTime
  owner: RepositoryOwner!
  url: String!
  cloneUrl: String!
  sshUrl: String!
 
  # Connections
  branches(first: Int, after: String): BranchConnection!
  tags(first: Int, after: String): TagConnection!
  commits(first: Int, after: String, branch: String): CommitConnection!
  mergeRequests(first: Int, after: String, state: MergeRequestState): MergeRequestConnection!
  issues(first: Int, after: String, state: IssueState): IssueConnection!
  releases(first: Int, after: String): ReleaseConnection!
  collaborators(first: Int, after: String): CollaboratorConnection!
  pipelines(first: Int, after: String): PipelineConnection!
}

Queries

Get Repository

query {
  repository(owner: "my-org", name: "my-repo") {
    name
    description
    private
    defaultBranch
    primaryLanguage {
      name
      color
    }
    languages {
      name
      percentage
      bytes
    }
    createdAt
    pushedAt
  }
}

List Branches

query {
  repository(owner: "my-org", name: "my-repo") {
    branches(first: 50) {
      nodes {
        name
        commit {
          sha
          message
          author { username }
          committedAt
        }
        protected
        aheadBehind(ref: "main") {
          ahead
          behind
        }
      }
    }
  }
}

Get Commit History

query {
  repository(owner: "my-org", name: "my-repo") {
    commits(first: 20, branch: "main") {
      nodes {
        sha
        message
        author {
          username
          email
          avatarUrl
        }
        committedAt
        parents { sha }
        stats {
          additions
          deletions
          filesChanged
        }
        signature {
          verified
          algorithm
          signer { username }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

Get File Contents

query {
  repository(owner: "my-org", name: "my-repo") {
    file(path: "src/lib.rs", ref: "main") {
      name
      path
      size
      content
      language
      lastCommit {
        sha
        message
        committedAt
      }
    }
  }
}

Get Directory Listing

query {
  repository(owner: "my-org", name: "my-repo") {
    tree(path: "src", ref: "main") {
      entries {
        name
        type  # FILE, DIRECTORY, SUBMODULE
        path
        size
        language
      }
    }
  }
}

Compare Branches

query {
  repository(owner: "my-org", name: "my-repo") {
    compare(base: "main", head: "feature/new-feature") {
      aheadBy
      behindBy
      commits {
        nodes {
          sha
          message
          author { username }
        }
      }
      files {
        nodes {
          path
          status  # ADDED, MODIFIED, DELETED, RENAMED
          additions
          deletions
          patch
        }
      }
    }
  }
}

Repository Contributors

query {
  repository(owner: "my-org", name: "my-repo") {
    contributors(first: 20, orderBy: { field: COMMITS, direction: DESC }) {
      nodes {
        user { username avatarUrl }
        commits
        additions
        deletions
      }
    }
  }
}

Mutations

Create Repository

mutation {
  createRepository(input: {
    name: "new-repo"
    organizationId: "org_01H8XYZ"
    private: true
    description: "A new repository"
    defaultBranch: "main"
    autoInit: true
    license: "MIT"
  }) {
    repository {
      id
      fullName
      url
    }
  }
}

Update Repository

mutation {
  updateRepository(input: {
    repositoryId: "repo_01H8XYZ"
    description: "Updated description"
    private: false
    archived: false
  }) {
    repository {
      fullName
      description
      private
    }
  }
}

Delete Repository

mutation {
  deleteRepository(input: {
    repositoryId: "repo_01H8XYZ"
  }) {
    success
  }
}