@@ -214,7 +214,7 @@ def login_internal(self, username: str, password: str, otp_answer: str = None,
214214 return self .session
215215
216216 def do_graphql_query (self , query_name : str , variables : dict , data_response_path : str , expect_type : str ,
217- filter_fn : callable = None , load_all_pages : bool = False ):
217+ filter_fn : callable = None , * , load_all_pages : bool = False ):
218218 query = {
219219 'operationName' : query_name ,
220220 'query' : self .GRAPHQL_QUERIES [query_name ],
@@ -246,8 +246,14 @@ def do_graphql_query(self, query_name: str, variables: dict, data_response_path:
246246 if key not in data :
247247 raise WSApiException (f"GraphQL query failed: { query_name } " , response_data )
248248 data = data [key ]
249- if hasattr (data , 'pageInfo' ) and hasattr (data .pageInfo , 'hasNextPage' ) and data .pageInfo .hasNextPage :
250- end_cursor = data .pageInfo .endCursor
249+ if (
250+ isinstance (data , dict )
251+ and 'pageInfo' in data
252+ and isinstance (data ['pageInfo' ], dict )
253+ and data ['pageInfo' ].get ('hasNextPage' )
254+ and 'endCursor' in data ['pageInfo' ]
255+ ):
256+ end_cursor = data ['pageInfo' ].get ('endCursor' )
251257
252258 # Ensure the data type matches the expected one (either array or object)
253259 if (expect_type == 'array' and not isinstance (data , list )) or (
@@ -266,8 +272,9 @@ def do_graphql_query(self, query_name: str, variables: dict, data_response_path:
266272 raise UnexpectedException ("Can't load all pages for GraphQL queries that do not return arrays" )
267273 if end_cursor :
268274 variables ['cursor' ] = end_cursor
269- more_data = self .do_graphql_query (query_name , variables , data_response_path , expect_type , filter , True )
270- data += more_data
275+ more_data = self .do_graphql_query (query_name , variables , data_response_path , expect_type , filter_fn , load_all_pages = True )
276+ if isinstance (data , list ) and isinstance (more_data , list ):
277+ data += more_data
271278
272279 return data
273280
0 commit comments