'How to keep running the same GraphQL query until x is null?
I have a Tableau GraphQL query that requires pagination:
test_1 = """
{
fieldsConnection (
first: 10,
orderBy: {field: NAME, direction: ASC}) {
nodes {
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
"""
2nd query:
test_2 = """
{
fieldsConnection (
first: 10,
next: SOME_STRING
orderBy: {field: NAME, direction: ASC}) {
nodes {
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
"""
This first query will have hasNextPage = true
and endCursor = "huge-ass-string"
. What I saw in my server is that to extract all fields of interest I need to run the query 13 times!
What I want to do is in Python, using from tableau_api_lib import TableauServerConnection as tsc
, write a function that runs the first query (test_1). If hasNextPage
is true, than run the second query (test_2) updating the next
value to be the value we got from endCursor
.
This is how I get the JSON response from my query:
response = conn.metadata_graphql_query(query = test_1)
Is this possible in Python?
Solution 1:[1]
I just implemented pagination in the query and kept looping and storing the extracted data in a DataFrame
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | datascientistwannabe |