[GraphQL] Fetching more than 100 results (all) with Python

Howdy, gang! :rocket:

Introduction

This is a quick article to share what I did to help a customer retrieving his 1300+ users from our GraphQL, with a single shot, using the best tool the Human Kind has at its disposal: Python.

At first, I wanted to control all aspects of the pageInfo, such as total, hasMore, etc.
And try to add very enhanced exception handlers.

But my customer urgency made me remember something: the KISS Principle.

So, I’ve created a very quick Python project, using the amazing GQL package, to explain to the customer how to retrieve all users from his account without any crazy cursor/pagination methods.

The project was made with the intention of retrieving all users at once, even if the query returns much more than 100 results.
Despite that, the functions are pretty loose (no classes, no crazy stuff), in Shell Script style.
With that said, it is very easy to customize the project to fit your use case.

This is more of an example of how I would do it.

Buckle up! :rocket:

Tutorial

Outcome:

Now you are not afraid of GraphQL Pagination anymore, I hope.

Further reading:

Tags:

<cloud: aws, azure, tanzu, gcp, on-prem, kubernetes, graphql, API, python, hacks>
<function: ci,cd>
<role: swdev,devops,secops,itexec>
<type: howto>
<category: triggers, gitops, templates>

2 Likes

Hi Gabriel,

can you help me with below. i am trying to list all applications with corresponding application ID’s. i am using below query but its returning only 100 applications not all.

query{
applications(limit: 500) {
nodes {
id
name
}
}
}