Get Installations for a given app using graphql

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 :slight_smile:

any and all advice welcome :slight_smile:

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
      }
    }
  }
}`)