GraphQL request for fetching results in batches (paginated)

You can set a maximum number of results to return for your query, and if you request the cursor property back, you can use the cursor to fetch another batch of results, starting from where you left off last time.

For example, the following combination of queries gets the ID, item type and title for all Tridion Docs Publications, in batches of 4 (we use 4 here so that our response won't be too big; in an actual implementation, the number would be more something like 20 or 50).

The first query gets the first 4 items:
{
  items(
    filter: {
      namespaceIds: [2],
      itemTypes: [PUBLICATION]
    },
    first: 4
  ) {
    edges {
      cursor
      node {
        itemId
        itemType
        title
      }
    }
  }
}
The response might look something like this:
{
  "data": {
    "items": {
      "edges": [
        {
          "cursor": "MQ==",
          "node": {
            "itemId": 1429819,
            "itemType": 1,
            "title": "Flux Capacitator"
          }
        },
        {
          "cursor": "Mg==",
          "node": {
            "itemId": 1683795,
            "itemType": 1,
            "title": "Publication MP660"
          }
        },
        {
          "cursor": "Mw==",
          "node": {
            "itemId": 3017912,
            "itemType": 1,
            "title": "VX 45.2"
          }
        },
        {
          "cursor": "NA==",
          "node": {
            "itemId": 3059467,
            "itemType": 1,
            "title": "Publication MP330"
          }
        }
      ]
    }
  }
}
Note how the last item in this response has its cursor property set to NA==. The next query uses this value as the point from which to show the next 4 results:
{
  items(
    filter: {
      namespaceIds: [2],
      itemTypes: [PUBLICATION]
    },
    first: 4,
    after: "NA=="
  ) {
    edges {
      cursor
      node {
        itemId
        itemType
        title
      }
    }
  }
}