Skip to content
CogniSkill

LESSON 2 OF 4

Follow the chain without redefining completeness

Practice notesBooks for further learning

Prepare the lab

Use PowerShell 7. This script simulates two Graph-shaped pages. It deliberately does not import the Graph module or call Microsoft services.

$ErrorActionPreference = 'Stop'
$pages = @{
    'page-1' = @{value=@([pscustomobject]@{id='1';displayName='Ana'});'@odata.nextLink'='page-2'}
    'page-2' = @{value=@([pscustomobject]@{id='2';displayName='Ben'});'@odata.nextLink'=$null}
}
function Read-FixturePages {
    param([hashtable]$Pages,[string]$First)
    $seen = [System.Collections.Generic.HashSet[string]]::new()
    $url = $First
    $items = [System.Collections.Generic.List[object]]::new()
    while ($url) {
        if (-not $seen.Add($url)) { throw 'Repeated page link' }
        if (-not $Pages.ContainsKey($url)) { throw 'Missing page response' }
        $page = $Pages[$url]
        foreach ($item in $page.value) { $items.Add($item) }
        $url = $page['@odata.nextLink']
    }
    return $items.ToArray()
}
$result = @(Read-FixturePages -Pages $pages -First 'page-1')
$result | Select-Object id,displayName | Format-Table
if (($result.id -join ',') -ne '1,2') { throw 'Pagination test failed' }

Work through the evidence

Draw the page chain

Write page-1 → page-2 → end before execution. Count records separately from pages: two pages could contain zero, two, or hundreds of records. A page count is not a user count.

Test an empty complete result

Set page-1 value to an empty array and its next-link to null. The function should return no items without claiming that collection failed. Then remove page-1 from the fixture and verify that missing response fails explicitly.

Inject a loop

Set page-2 next-link to page-1. The function must throw Repeated page link. Explain why silently treating a repeated URL as end-of-data could conceal a broken provider or collector.

Expected baseline result

Baseline output contains IDs 1 and 2. Missing page and loop fixtures fail explicitly. A complete empty fixture returns zero records with a completed collection status, not a fabricated success after an error.

Follow the chain without redefining completeness

Microsoft Graph can return an @odata.nextLink for another page. A page's HTTP success is not the same as a complete collection. In the offline fixture, page-1 yields Ana and points to page-2, which yields Ben and terminates. The expected population is two records.

Now make the second page empty but retain a valid subsequent link to a third page. Empty page content is not a universal end condition; the pagination contract determines continuation. For a real adapter, use supported next links, preserve required headers, bound work and validate destinations before forwarding credentials. Provider paging behavior varies by endpoint.

Evidence laboratory — attempt before reading the solution

A mocked directory API returns page 1 with users U1,U2 and next link N2. The first N2 request returns 429 with Retry-After 3 seconds; the approved test harness then returns U3,U4 and next link N3. N3 returns U5 and no continuation. A faulty script stops after page 1 and labels its output “all users.” Trace the correct sequence, expected unique-user count and the completion flag. All responses here are fixtures; no live tenant call is required.

Official reference for further study

COGNISKILL BOOKS

Go deeper with a related book

This short course practises a focused skill. Related CogniSkill books offer an optional longer learning and preparation path; this course does not claim full exam coverage.

Sign in to save lesson completion. Reading position is separate from completion.

Practice notes — your working space

Save predictions, outputs and explanations as you work. Notes stay on this browser, not your account; people sharing this browser can access them. Avoid passwords and sensitive data. Export to keep a portable copy, or clear your notes before leaving a shared device.

How was this lesson?

Help us improve this lesson.