microsoftgraph / msgraph-sdk-serviceissues

Tracks service issues for follow up.
5 stars 0 forks source link

Unable to paginate through app role assignments for a user. #109

Open gmantri opened 3 years ago

gmantri commented 3 years ago

Describe the bug I am trying to get app role assignments for a user. A user can be assigned many app roles and I want to implement some kind of pagination there. Let's say my user has 10 app role assignments and I want to fetch 5 app role assignments at a time. When I specify $top as 5, I get the first 5 roles (which is correct) however I am expecting to get back next page request which is coming as null.

Please see my sample code below:

string userId = "9c98eb9c-6f1e-446b-ae36-a23a318db8ad"
IUserAppRoleAssignmentsCollectionRequest request = graphServiceClient.Users[userId].AppRoleAssignments.Request();
request = request.Top(5);
do
{
    IUserAppRoleAssignmentsCollectionPage result = await request.GetAsync();
   //There's some code here which does something with the result. I have omitted that for the sake of brevity.
    request = result.NextPageRequest;//result.NextPageRequest is coming as null
} while (request != null);

Because of this, I only get first 5 role assignments back.

Is this a bug in the SDK or does this operation not support pagination?

Additional context I am using Microsoft.Graph (version 4.0.0-preview.6 Nuget package.

AB#10091

MIchaelMainer commented 3 years ago

This is a service bug. I would've expected a nextlink in the response payload. It doesn't appear that paging is supported with this API. I used the PageIterator to test this.

static async Task GetAppRoleAssignments(GraphServiceClient client)
{
    var graphResponse = await client.Users[Chambele.V1.user].AppRoleAssignments.Request().GetResponseAsync();
    var response = await graphResponse.GetResponseObjectAsync();

    List<string> results = new();

    // Create the callback to process each entity returned in the pages
    Func<AppRoleAssignment, bool> processEachEvent = (a) =>
     {
         bool shouldContinue = true;

         results.Add(a.ResourceDisplayName);

         return shouldContinue;
     };

    // Create the iterator with the specified type
    var appRoleAssignmentPageIterator = PageIterator<AppRoleAssignment>.CreatePageIterator(client,
                                                                                           response.Value,
                                                           processEachEvent);

    await appRoleAssignmentPageIterator.IterateAsync();

    results.Dump();
}
gmantri commented 3 years ago

@MIchaelMainer - Thank you for looking into this. It is very much appreciated. Considering this is a service bug, do I need to report it someplace else as well? Should I keep this issue open? Please let me know.

Thanks

MIchaelMainer commented 3 years ago

We'll keep this issue open. Thank you.

petrhollayms commented 7 months ago

Thank you for reporting this issue. This appears to be an issue or limitation with the service APIs. Unfortunately, as the Microsoft Graph SDK team, we do not have ownership of the APIs that are causing you issues. We invite you to create a question about the service API to Microsoft Q&A and tagged with one of the [microsoft-graph-*] tags, that way it will get routed to the appropriate team for them to triage:

https://aka.ms/msgraphsupport or directly https://aka.ms/askgraph

For now, we will close the issue on our side but feel free to open it in the relevant repository if you think the issue is specific to SDK. Please let us know if this helps!

Note: We will close this repository on April 19, 2024.