msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

[Client bug]: Graph SDK does not de-serialize next links to strongly typed requests in batch requests, but does in non-batched requests

Open will-bartlett opened this issue 3 years ago • 1 comments

I was experimenting with batching in the Graph API and SDK.

I'm creating a request to get members of a group:

var request = GraphClient.Groups[groupId].Members.Request();

When I send this request using the non-batch method:

var response = await request.GetAsync();
Console.WriteLine($"response.NextPageRequest is {response.NextPageRequest == null ? "null" : "not null"}");

The NextPageRequest property is populated as expected.

When I combine it into a batch request:

var batchRequestContent = new BatchRequestContent();
var batchRequestId = batchRequestContent.AddBatchRequestStep(request);
var batchResponse = await GraphClient.Batch.Request().PostAsync(batchRequestContent);
var batchItemResponse = await batchResponse.GetResponseByIdAsync<GroupMembersCollectionWithReferencesResponse>(batchRequestId);
var itemResponse = batchItemResponse.Value;
Console.WriteLine($"itemResponse.NextPageRequest is {itemResponse.NextPageRequest == null ? "null" : "not null"}");

The NextPageRequest property is always null. To correct this, I have added some extra code

const string nextLinkKey = "@odata.nextLink";
if (batchItemResponse.AdditionalData.TryGetValue(nextLinkKey, out object nextLinkObj) && nextLinkObj is string nextLinkString) { itemResponse.InitializeNextPageRequest(GraphClient, nextLinkString); }

Which fixes up this issue.

This feels like a bug - batching should return the same objects, just in a collection, not different objects, or require different steps.

I am using version 3.19.0, the latest from nuget.org, running on Windows.

I am a Microsoft employee - you can feel free to reach to me directly on Teams with any questions. AB#7230

will-bartlett avatar Nov 08 '20 06:11 will-bartlett

This is a new scenario for batch support where we need to support the creation of a *CollectionPage with NextPageRequest populated with the request to get the next page.

MIchaelMainer avatar Nov 12 '20 21:11 MIchaelMainer

With the latest Kiota previews, handling the responses for collections are now consistent with the API response shape and provide the same experience when making calls for batch and non-batch endpoints as documented at https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/feature/5.0/docs/upgrade-to-v5.md#collections.

Closing this one for now.

andrueastman avatar Oct 04 '22 07:10 andrueastman