How can i get all users repos?


#1

Hi
i am very new in graphql. How can i get all repos by user (not only first 30). I tried it out through orderBy, but there are only time related fields to do sorting(not id.


#2

In general, I would recommend you read something like: http://graphql.org/learn/pagination/

But it roughly looks like this: pagination occurs via cursors. Since we (intentionally) limit your query to 30 records at a time, you need to keep track of the cursor, and, make a secondary request with the after argument, passing in the endCursor.

For example, here’s me grabbing the names of my first thirty repositories:

{
  viewer {
    repositories(first: 30) {
      pageInfo {
        hasNextPage
        endCursor
      }
      edges {
        node {
          name
        }
      }
    }
  }
}

The response here would be:

{
  "data": {
    "viewer": {
      "repositories": {
        "pageInfo": {
          "hasNextPage": true,
          "endCursor": "ODM0NzQ2Ng=="
        },
        "edges": [
          {
            "node": {
              "name": "Earthbound-Battle-Backgrounds"
            }
          },
          {
            "node": {
              "name": "ADC-Zipcode-Sorter"
            }
          },
          {
            "node": {
              "name": "ColoredLogcatPlusPlus"
            }
          },
...

Since hasNextPage is true, I know that I have more data to fetch. endCursor represents the last item in my list. So, I’ll make a second request, slightly different than the first, making sure to pass in endCursor as my starting point:

{
  viewer {
    repositories(first: 30, after: "ODM0NzQ2Ng==") {
      pageInfo {
        hasNextPage
        endCursor
      }
      edges {
        node {
          name
        }
      }
    }
  }
}

The response would be:

{
  "data": {
    "viewer": {
      "repositories": {
        "pageInfo": {
          "hasNextPage": true,
          "endCursor": "MTI3NzA2MTY="
        },
        "edges": [
          {
            "node": {
              "name": "html-proofer"
            }
          },
          {
            "node": {
              "name": "platform-sandbox"
            }
          },
          {
            "node": {
              "name": "biscotto"
            }
          },
...

I’ve got more pages of results (hasNextPage is true), so again, I’ll keep requesting more records in the same way.

I hope this helps!


#3

thanks a lot


#4

This helps a lot. Thank you!