Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
alexbjorlig
Helper IV
Helper IV

How to make List.Generate work with cursor based pagination

I'm developing a custom power bi connector consuming a GraphQl API, and my objective is to use the List.Generate to support cursor based pagination. My code is inspired by this Github comment. The code looks like this:

 

 

GeneratedList =
            List.Generate(
                () => [res = getPage(queryName, query, operationName, [pagination = [first = 100]])],
                each Comparer.Equals(Comparer.FromCulture("en-us"), [res][hasNextPage], true ),
                each [ res = getPage(queryName, query, operationName, [pagination = [first = 100, after = [res][endCursor]]] ) ],
                each [res][edges]
            )

 

 

The above works if the initial page has more than 100 items. But if all items can be returned in the initial call, then it does not work, an empty list is returned. Why is this the case? I checked the queries that are returned from the API and they seem to work perfect with hasNextPage property.

 

Update - and solution

According to this comment from Ben Gribaud, test function is also used for the initial result. With that in mind the working code looks like this:

 

 

        GeneratedList =
            List.Generate(
                () => [res = getPage(queryName, query, operationName, [pagination = [first = 11]])],
                each [res]<>null and [res][edges]<>null and List.Count([res][edges]) > 0,
                each [ res = if Comparer.Equals(Comparer.FromCulture("en-us"), [res][hasNextPage], false ) then null else getPage(queryName, query, operationName, [pagination = [first = 23, after = [res][endCursor]]] ) ],
                each [res][edges]
            )

 

 

 

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @alexbjorlig ,

Thanks for sharing your solution here, it will help the others in the community find the solution easily if they face the same problem with yours. Much appreciated!

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.