Skip to content

Instantly share code, notes, and snippets.

@SteveL-MSFT
Last active October 29, 2023 03:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SteveL-MSFT/b91ee277ea2737faf19e8962b2d7f0b7 to your computer and use it in GitHub Desktop.
Save SteveL-MSFT/b91ee277ea2737faf19e8962b2d7f0b7 to your computer and use it in GitHub Desktop.
GraphQL Query Example
$query = @"
query {
organization(login: "powershell") {
name
url
repository(name: "powershell") {
name
pullRequests(last: 20, states: [OPEN]) {
edges {
node {
title
comments(last: 20) {
edges {
node {
author {
login
}
}
}
}
}
}
}
}
}
}
"@
$body = @{query=$query} | ConvertTo-Json
$data = Invoke-RestMethod https://api.github.com/graphql -Authentication OAuth -Token (Get-Secret GitHub) -Body $body -Method Post
$data.data.organization.repository.pullRequests.edges.node | Format-Table title,
@{
label = "comments";
expression = {
$_.comments.edges.count
}
},
@{
label = "authors";
expression = {
[string]::Join(",", (
$_.comments.edges.node.author.login | Select-Object -Unique | Sort-Object
))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment