Is pagination of large GraphQL arrays possible?

Hi all!

I’m trying to get all the revit parameters of a particular commit. The way I have been doing it (using the graphiQL explorer) is to get the referencedObject of the commit, use that Id to get all children of that object, however, this is where it all falls apart. I can only access the first 100 child objects (the limit prevents me from getting the rest ~1250). Is there a way to paginate the children data array results or is “skip” a certain amount of entries to chain some requests?

example query:

query {
    stream(id: "xyz") {
        object(id: "xyz") {
            children(limit: 100) {
                objects {
                    data
                }
            }
        }
    }
}

Good news: yes you can!

The children query can take a parameter cursor, which can be fed the cursor of the last child retrieved in your last query.

Add cursor to your response object definition

{
  stream(id: "909c64...d") {
    object(id: "7aa5b4c0cdcd...8") {
      children( limit: 2 ) {
        cursor
        objects{id}
      }
    }
  }
}

{
  "data": {
    "stream": {
      "object": {
        "children": {
          "cursor": "004bec21262465...7",
          "objects": [
            {
              "id": "003812b2e9c937...7"
            },
            {
              "id": "004bec21262465...7"
            }
          ]
        }
      }
    }
  }
}

the cursor returned in the result matches the id of the last object returned, this can then be used in turn to start the next “page.”

{
  stream(id: "909c64...d") {
    object(id: "7aa5b4c0cdcd...8") {
      children( limit: 2, cursor: 004bec21262465...7 ) {
        cursor
        objects{id}
      }
    }
  }
}

{
  "data": {
    "stream": {
      "object": {
        "children": {
          "cursor": "01ae841d88feb1067...0",
          "objects": [
            {
              "id": "01807d066bae5f180...3"
            },
            {
              "id": "01ae841d88feb1067...0"
            }
          ]
        }
      }
    }
  }
}

1 Like

Appreciate that Jonathon, worked a charm!

2 Likes