microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
674 stars 243 forks source link

delta group query call for members #2570

Open cuongngoht opened 1 week ago

cuongngoht commented 1 week ago

Describe the bug

` var deltaPage = await request.Client.Groups.Delta.GetAsDeltaGetResponseAsync(requestConfiguration => { requestConfiguration.QueryParameters.Select = ["id", "displayName", "description", "members", "deletedDateTime"]; requestConfiguration.QueryParameters.Top = 999; });

await IteratePageAsync(request.Client, deltaPage);

// Recursively fetch next pages if they exist while (deltaPage.OdataNextLink != null) { deltaPage = await GetDeltaWithUrl(request, deltaPage.OdataNextLink); }

return deltaPage;`

 <PackageReference Include="Microsoft.Graph" Version="5.56.0" />

In query list groups they always members is null although I use in graph explorer they always have values in members

Expected behavior

In groups they always responded members when I select in query

How to reproduce

` var deltaPage = await request.Client.Groups.Delta.GetAsDeltaGetResponseAsync(requestConfiguration => { requestConfiguration.QueryParameters.Select = ["id", "displayName", "description", "members", "deletedDateTime"]; requestConfiguration.QueryParameters.Top = 999; });

await IteratePageAsync(request.Client, deltaPage);

// Recursively fetch next pages if they exist while (deltaPage.OdataNextLink != null) { deltaPage = await GetDeltaWithUrl(request, deltaPage.OdataNextLink); }

return deltaPage;`

 <PackageReference Include="Microsoft.Graph" Version="5.56.0" />

In query list groups they always members is null although I use in graph explorer they always have values in members

SDK Version

5.56.0"

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ``` ```

Configuration

No response

Other information

No response

andrueastman commented 1 week ago

Thanks for raising this @cuongngoht

Any chance you can share a sample response that shows up in the graph explorer? Are the member responses with the members property or the members@delta property?

cuongngoht commented 1 week ago

Thanks for raising this @cuongngoht

Any chance you can share a sample response that shows up in the graph explorer? Are the member responses with the members property or the members@delta property? it is members@delta In graph explorer image In # code de I get all delta group changes: image

@andrueastman

w4n commented 4 days ago

I'm observing the same problem trying to get groups via the DeltaRquestBuilder as follows:

roupDeltaResponse = await _graphClient.Groups.Delta.GetAsDeltaGetResponseAsync(requestConfiguration =>
            {
                requestConfiguration.QueryParameters.Select = ["displayName","description","members"];
            });

I tried this with the default request configuration too. None of the groups in the DeltaGetResponse.Value-collection have any Members. I'm not sure how you're supposed to read any delta information with the given return values anyway since there doesn't seem to be any property dedicated to this information.

andrueastman commented 4 days ago

@w4n @cuongngoht The members property is mapped to a members property in the serializer for the json response of the payload. As the value come back from the API in a different property members@delta, the value will be found in the additionalData bag.

With the latest version of the SDK you can process this information with an example similar to this.

            var result = await graphClient.Groups.Delta.GetAsDeltaGetResponseAsync();

            // iterate through the groups
            foreach (var group in result.Value)
            {
                if (group.AdditionalData.TryGetValue("members@delta", out var membersDelta)) // get the info in the additional data bag.
                {
                    var memberListJsonString = await KiotaJsonSerializer.SerializeAsStringAsync((UntypedArray)membersDelta);
                    var membersObjectList = await KiotaJsonSerializer.DeserializeCollectionAsync<DirectoryObject>(memberListJsonString);
                }
            }
cuongngoht commented 4 days ago

@andrueastman So my question is does Ms Graph Sdk support it directly or official for it? In my project, we still used delta group query call by HTTP client response JSON and manual map by properties for resolving this case long time. But although thanks you about it. So i closed this bug or waiting for support directly from MS Graph SDK? in my opinion, the code wasn't clear and understand by the developer when I read that.

            var result = await graphClient.Groups.Delta.GetAsDeltaGetResponseAsync();

            // iterate through the groups
            foreach (var group in result.Value)
            {
                if (group.AdditionalData.TryGetValue("members@delta", out var membersDelta)) // get the info in the additional data bag.
                {
                    var memberListJsonString = await KiotaJsonSerializer.SerializeAsStringAsync((UntypedArray)membersDelta);
                    var membersObjectList = await KiotaJsonSerializer.DeserializeCollectionAsync<DirectoryObject>(memberListJsonString);
                      group.Members = membersObjectList.ToList();
                }
            }

But in my opinion, if we reuse group object in DeltaGetResponse we could create a new object to do it. I would be clear.

public List<Microsoft.Graph.Models.Group>? Value
{
    get { return BackingStore?.Get<List<Microsoft.Graph.Models.GroupDelta>?>("value"); }  // Example we create new object GroupDelta
    set { BackingStore?.Set("value", value); }
}

Because we missing some cases like owners like it

w4n commented 3 days ago

@andrueastman Thank you! I did notice that the data I was seeking was landing in AdditionalData after posting. However, I wasn't sure how to extract it properly, as I'm not familiar with Kiota.

We should probably update the docs. The C# examples for change tracking show how to run the request to the delta endpoint using the Graph SDK, but they fail to mention how to get the members@delta payload once it's done. They just show the JSON response body which - as far as I know - you can't access using the SDK.

andrueastman commented 3 days ago

But in my opinion, if we reuse group object in DeltaGetResponse we could create a new object to do it. I would be clear.

That indeed would ideally be the case.

For context, the SDK is generated from API metadata at https://graph.microsoft.com/v1.0/$metadata. Which documents that the response for the request is collection of the group object. Taking a look at the group object (in both the metadata and the docs), neither of them document the members@delta property and that's why the SDK puts the extra properties in the AdditionalData.

Ideally, the fix would be to have these properties added to the metadata. The SDK would then be generated with a property for them which would then deserialize the response information into the property and can be accessed directly.