As an app owner, how can i get a list of all installations using graphql? ( what octokit uses for get all for current )
rest api https://developer.github.com/v3/apps/#list-installations
as an added bonus it would also be awesome to get a list of repos for each installation in the graph without sending a separate request per install with an auth token for each
any and all advice welcome
eniks
May 3, 2020, 10:29pm
#2
I found it possible to get repos with my app installed with this query:
viewer {
repositories(first: 100, ownerAffiliations: OWNER) {
totalCount
nodes {
nameWithOwner
}
}
}
The trick is in proper authentication. You have to be autenticated not as application but as that particular installatin with proper installation ID.
If you are responding to webhook event, the ID would be in: payload.installation.id
.
So if you are developing your app based on probot, you would use code like this:
let github = await app.auth(context.payload.installation.id);
let response = await github.graphql(`{
viewer {
repositories(first: 100, ownerAffiliations: OWNER) {
totalCount
nodes {
nameWithOwner
}
}
}
}`)