This repository was archived by the owner on Sep 1, 2026. It is now read-only.
Optimize paginated matched Graph batch result accumulation - #1538
Open
Aleksandar Nikolić (alexandair) wants to merge 2 commits into
Open
Optimize paginated matched Graph batch result accumulation#1538Aleksandar Nikolić (alexandair) wants to merge 2 commits into
Aleksandar Nikolić (alexandair) wants to merge 2 commits into
Conversation
…reserve result contract
Copilot started reviewing on behalf of
Aleksandar Nikolić (alexandair)
August 28, 2026 14:47
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the private Graph batching helper Invoke-ZtGraphBatchRequest to more efficiently accumulate multi-page (@odata.nextLink) results while preserving the existing object[] result contract, and adds Pester coverage for single-page vs paginated matched results.
Changes:
- Optimize multi-page accumulation by promoting the result to
List[object]only when pagination requires repeated appends, avoiding repeated array copying. - Ensure the emitted
BatchResult.Resultis always anobject[](convert lists back viaToArray()). - Add Pester tests validating ordering, type consistency, and the expected number of underlying Graph calls for paginated vs non-paginated matched responses.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/powershell/private/graph/Invoke-ZtGraphBatchRequest.ps1 | Switch multi-page accumulation to List[object] and normalize the emitted Result back to object[]. |
| code-tests/commands/Invoke-ZtGraphBatchRequest.Tests.ps1 | Adds tests for matched batch result handling across single-page and paginated responses. |
Suppressed comments (2)
code-tests/commands/Invoke-ZtGraphBatchRequest.Tests.ps1:33
- After importing only the manifest, Invoke-ZtGraphBatchRequest will be available only inside the module scope (it is not exported by the manifest). Wrap the call in InModuleScope so the test actually exercises the private function loaded by the manifest module instance.
$result = Invoke-ZtGraphBatchRequest `
-Path 'servicePrincipals/{0}/owners' `
-ArgumentList @($argument) `
-Properties id `
-Matched
code-tests/commands/Invoke-ZtGraphBatchRequest.Tests.ps1:84
- Same as the single-page test: once the module is imported via the manifest only, invoke the private function inside InModuleScope to avoid relying on .psm1 imports that bypass the real exported surface.
$result = Invoke-ZtGraphBatchRequest `
-Path 'servicePrincipals/{0}/owners' `
-ArgumentList @($argument) `
-Properties id `
-Matched
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Aleksandar Nikolić (alexandair)
requested a review
from Anton Staykov (astaykov)
August 28, 2026 15:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the handling of paginated batch responses in
Invoke-ZtGraphBatchRequestand introduces comprehensive tests to ensure correct behavior for both single-page and multi-page responses. The main improvements focus on efficiently accumulating paged results and maintaining a consistent output type, while adding robust test coverage.Improvements to pagination handling and result consistency:
Invoke-ZtGraphBatchRequest.ps1to efficiently accumulate results from paginated responses using aList[object]only when necessary, ensuring that the output remains an object array (object[]) regardless of pagination.Resultproperty is always returned as an array, preserving the module's output contract.Test coverage enhancements:
Invoke-ZtGraphBatchRequest.Tests.ps1to verify that single-page and paginated batch responses are handled correctly, including checks for result type, content, and the number of underlying API calls.