Skip to content
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
microsoft:devfrom
alexandair:dev
Open

Optimize paginated matched Graph batch result accumulation#1538
Aleksandar Nikolić (alexandair) wants to merge 2 commits into
microsoft:devfrom
alexandair:dev

Conversation

@alexandair

Copy link
Copy Markdown
Collaborator

This pull request enhances the handling of paginated batch responses in Invoke-ZtGraphBatchRequest and 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:

  • Modified Invoke-ZtGraphBatchRequest.ps1 to efficiently accumulate results from paginated responses using a List[object] only when necessary, ensuring that the output remains an object array (object[]) regardless of pagination.
  • Ensured that after accumulating results from multiple pages, the final Result property is always returned as an array, preserving the module's output contract.

Test coverage enhancements:

  • Added a new test suite Invoke-ZtGraphBatchRequest.Tests.ps1 to verify that single-page and paginated batch responses are handled correctly, including checks for result type, content, and the number of underlying API calls.

Copilot AI lite review requested due to automatic review settings August 28, 2026 14:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Result is always an object[] (convert lists back via ToArray()).
  • 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.

Comment thread code-tests/commands/Invoke-ZtGraphBatchRequest.Tests.ps1
@alexandair Aleksandar Nikolić (alexandair) changed the title Enhance Invoke-ZtGraphBatchRequest to handle multi-page results Optimize paginated matched Graph batch result accumulation Sep 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants