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