GraphQL queries - brownfield-team/anacapa-github-linker GitHub Wiki

This page is for storing example GraphQL queries that may be useful

You can try these out in the GraphQl Explorer here: https://docs.github.com/en/graphql/overview/explorer

Getting Comments, Labels, Code Review, etc. for Pull Requests

Documentation:

There are many more that could be added!

{
  repository(name: "f22-5pm-courses", owner: "ucsb-cs156-f22") {
    pullRequests(first: 50) {
      pageInfo {
        startCursor
        hasNextPage
        endCursor
      }
      nodes {
        projectCards(first: 50) {
          totalCount
          nodes {
            column {
              name
              project {
                name
                url
                number
              }
            }
          }
        }
        timelineItems(
          itemTypes: [UNLABELED_EVENT, LABELED_EVENT, REVIEW_REQUESTED_EVENT]
          first: 50
        ) {
          pageInfo {
            startCursor
            hasNextPage
            endCursor
          }
          nodes {
            __typename
            ... on ReviewRequestedEvent {
              id
              actor {
                login
                ... on User {
                  databaseId
                  email
                  name
                }
              }
              createdAt
            }
            ... on LabeledEvent {
              id
              actor {
                login
                ... on User {
                  databaseId
                  email
                  name
                }
              }
              createdAt
              label {
                id
                name
              }
            }
            ... on UnlabeledEvent {
              id
              actor {
                login
                ... on User {
                  databaseId
                  email
                  name
                }
              }
              createdAt
              label {
                id
                name
              }
            }
          }
        }
        labels(first: 50) {
          totalCount
          edges {
            node {
              color
              id
              name
              description
            }
          }
        }
        comments(first: 50) {
          edges {
            node {
              body
              bodyText
              author {
                login
              }
              createdAt
              lastEditedAt
              reactions(first: 50) {
                totalCount
                edges {
                  node {
                    createdAt
                  }
                }
              }
            }
          }
        }
        assignees(first: 50) {
          pageInfo {
            startCursor
            hasNextPage
            endCursor
          }
          totalCount
          nodes {
            id
            login
            name
          }
        }
        id
        closed
        closedAt
        createdAt
        mergedAt
        merged
        url
        number
        title
        body
        author {
          login
        }
        databaseId
        milestone {
          id
        }
        state
        changedFiles
        reviewDecision
      }
    }
  }
}   

Getting Issue Comments

# Type queries into this side of the screen, and you will 
# see intelligent typeaheads aware of the current GraphQL type schema, 
# live syntax, and validation errors highlighted within the text.

# We'll get you started with a simple query showing your username!
query {
            repository(owner: "wsu-cpts489-fa21", name: "tp-go-lakers") {
                issues(first: 50 ) {
                    pageInfo { ...pageInfoFields }
                    totalCount
                    nodes {
                        ... issueFields
                        author { ... actorFields }
                        timelineItems(itemTypes: [ISSUE_COMMENT], first: 50) {
                            pageInfo { ...pageInfoFields }
                            totalCount
                            nodes { 
                               ...issueCommentEventFields
                            }
                        } 
                    }                 
                }
            }
        }      
        
fragment pageInfoFields on PageInfo {
            startCursor
            hasNextPage
            endCursor
          }
          
fragment issueFields on Issue {
      number
      url
      title
      createdAt
      state
    }
    
    
 fragment actorFields on Actor {
          login
          ... on User {
            databaseId
            email
            name
          }
        }
        
fragment issueCommentEventFields on Comment {
          id
          createdAt
          updatedAt
  			  body
  				bodyText
          author{
            login
            }
        }

Getting Comments for PRs

{
  repository(name: "f22-5pm-courses", owner: "ucsb-cs156-f22") {
    pullRequests(first: 50) {
      pageInfo {
        startCursor
        hasNextPage
        endCursor
      }
      nodes {
        projectCards(first: 50) {
          totalCount
          nodes {
            column {
              name
              project {
                name
                url
                number
              }
            }
          }
        }
        comments(first: 50) {
          edges {
            node {
              body
              bodyText
              author {
              	login
              }
						  createdAt
              lastEditedAt
            }
          }
        }
        assignees(first: 50) {
          pageInfo {
            startCursor
            hasNextPage
            endCursor
          }
          totalCount
          nodes {
            id
            login
            name
          }
        }
        id
        closed
        closedAt
        createdAt
        mergedAt
        merged
        url
        number
        title
        body
        author {
          login
        }
        databaseId
        milestone {
          id
        }
        state
        changedFiles
        reviewDecision
      }
    }
  }
}