Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GitHub API v4 GraphQL to find all open issues belonging to repositories owned by the user

Can someone please point me in the right direction for listing all open issues that are in repos owned by the user? Thanks in advance.

like image 653
Will Stone Avatar asked Mar 02 '18 23:03

Will Stone


People also ask

How do I use GraphQL with GitHub API?

To communicate with GitHub's GraphQL API, fill in the header name with "Authorization" and the header value with "bearer [your personal access token]". Save this new header for your GraphiQL application. Finally, you are ready to make requests to GitHub's GraphQL API with your GraphiQL application.

What is GitHub GraphQL API?

To create integrations, retrieve data, and automate your workflows, use the GitHub GraphQL API. The GitHub GraphQL API offers more precise and flexible queries than the GitHub REST API. Overview.

How do you call API in GraphQL?

To use the explorer, we'll head to studio.apollographql.com/dev and create an account (using either GitHub or your email). Finally, choose a name for your graph, select the “Development” graph type, add your localhost endpoint (Apollo Server's default is http://localhost:4000), and click “Create Graph”. And that's it!

What does GraphQL do?

GraphQL is a query language and server-side runtime for application programming interfaces (APIs) that prioritizes giving clients exactly the data they request and no more. GraphQL is designed to make APIs fast, flexible, and developer-friendly.


2 Answers

I think I've figured it out. Please let me know if there's a more optimal answer.

query {
  search(first: 100, type: ISSUE, query: "user:will-stone state:open") {
    issueCount
    pageInfo {
      hasNextPage
      endCursor
    }
    edges {
      node {
        ... on Issue {
          createdAt
          title
          url,
          repository {
            name
          }
        }
      }
    }
  }
}
like image 65
Will Stone Avatar answered Oct 01 '22 20:10

Will Stone


Your answer is probably the most efficient way in terms of pagination, but another approach you could take is to iterate over all of the user's owned repositories, and for each of those repositories fetch their issues with something like:

query($userLogin: String!) {
  user(login: $userLogin) {
    repositories(affiliations: [OWNER], last: 10) {
      edges {
        node {
          issues(states: [OPEN], last: 10) {
            edges {
              node {
                createdAt
                title
                url
                repository {
                  name
                }
              }
            }
          }
        }
      }
    }
  }
}
like image 45
bswinnerton Avatar answered Oct 01 '22 21:10

bswinnerton