Get status data for list of GitHub logins (users) using GraphQL in efficent way

Viewed 158

What I would like to do is to get specific data from Status for a group of 10-40 GitHub users from the organization. I would like to get the data in one batch. Currently, my solution queries the data using for loop in the code and a query below:

{
    user(login: "user1") {
    status {
         indicatesLimitedAvailability
         updatedAt
         createdAt
}

The disadvantage of this solution is I have to use sleep not to trigger API calls per minute limit in GitHub.

Would it be possible to transform the query to something like this (pseudocode):

{
    user(login: "user1", "user2", "user3", ...) {
    status {
         indicatesLimitedAvailability
         updatedAt
         createdAt
}

And some kind of list in the response?

1 Answers

You can use the following query:

{
  nodes(ids: ["node_id1", "node_id2"]) {
    ... on User {
      status {
        indicatesLimitedAvailability
        updatedAt
        createdAt
      }
    }
  }
}

Where node_id is the id of the users you want to query for.

You can obtain these using the following query:

{
  user(login: "username") {
    id
  }
}

Or you could get all members in an organisation with the following query

{
  organization(login: "org_name") {
    membersWithRole(first: 100) {
      nodes {
        login
        id
      }
    }
  }
}
Related