Looks great! One thing I would suggest is to use graphQL variables instead of formatting the string, e.g:
Let's say the query starts like this:
query( $cursor: ID, $page: AssetsPage){
site(id: "insert site id here"){
assetResources(
assetPagination: {
limit: 5,
cursor: $cursor
page: $page
},
...
You can put variables at the top by defining them such as $cursor: ID etc. and then you would have a seperate json/dictionary that stores the variable values, e.g:
variables = {
"cursor": next_cursor,
"page": next_page
}
#next_cursor can be initalized as "" and next_page can be initalized as "FIRST" etc.
And then you can send this as a POST request to LS via whichever you prefer, in my case I use the requests package:
response = requests.request("POST", url, headers=headers, json={"query": query, "variables": variables})
data = response.json()
Make sure to put both the variables and query together as Json format in the post request. This keeps things easier to read and organized, and in cases like yours; you don't need to check if it's FIRST etc. just initialize the cursor as an empty string and then on the next iteration you would put the NEXT page key as the cursor etc.