1

With Github's GraphQL API I recently found "Github API: Getting topics of a Github repository" that mentions you can get a count of topics:

{
  repository(owner: "twbs", name: "bootstrap") {
    repositoryTopics(first: 10) {
      edges {
        node {
          topic {
            name
          }
        }
      }
    }
  }
}

but in the docs and in my search I'm not finding how I can query repositories that do not contain the topic template, example:

query ($github_org: String!, $repo_count: Int!) {
  organization(login: $github_org) {
    repositories(first: $repo_count, privacy: PUBLIC, isFork: false) {
      nodes {
        id
        name
        openGraphImageUrl
        createdAt
        stargazerCount
        url
        description
        repositoryTopics(first: 10, after: "template") {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

is the correct implementation to use after? In Github's GraphQL API how to exclude a repository if it contains a certain topic?

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127
  • Hey. This is not the correct use of `after`. The `after` parameter is used to pass the cursor you want to get results "after". You can get the cursors of the nodes in the page object. – David Butler May 11 '22 at 21:37

1 Answers1

0

My understanding is that with the organization query you cannot do that kind of repository filtering.

Instead, you can use the search query with something like this:

query ($repo_count: Int!) {
  search (first: $repo_count,
          type: REPOSITORY,
          query: "org:my-organization topic:my-topic") {
    nodes {
      ... on Repository {
        name
      }
    }
  }
}

The above query searches for all repositories within a given organization that have a given topic.

But you were looking for the repositories without a topic, in theory according to the documentation you should be able to do that with -topic:my-topic. Unfortunately the negation on topic doesn't work, there seems to be a bug. :-(

Francesco Feltrinelli
  • 1,589
  • 1
  • 10
  • 14