From 70adee104e2de3bd866d235e3ef04efce53ef12a Mon Sep 17 00:00:00 2001 From: pillaris Date: Fri, 24 Apr 2026 12:21:00 +0530 Subject: [PATCH] fix(catalog): always pair \$count=true with ConsistencyLevel: eventual in advanced mode Microsoft Graph requires \$count=true whenever the ConsistencyLevel: eventual header is present, including plain listing requests with no \$filter or \$search. The previous condition only added \$count when a filter or search was present, causing the /groups endpoint to silently return an empty value array when queryMode is set to advanced without a group filter. Signed-off-by: pillaris Co-Authored-By: Claude Sonnet 4.6 --- .../src/clientHelpers.test.ts | 18 ++++++++++++++++++ .../src/clientHelpers.ts | 9 +++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.test.ts b/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.test.ts index 3b81b24099..1819492be8 100644 --- a/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.test.ts +++ b/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.test.ts @@ -75,6 +75,24 @@ describe('requestOnePage', () => { ); }); + it('adds ConsistencyLevel and $count for advanced mode without filter', async () => { + (client.requestApi as jest.Mock).mockResolvedValue( + makeResponse(200, { value: [] }), + ); + + await requestOnePage(client, 'groups', { + query: { top: 999 }, + queryMode: 'advanced', + }); + + expect(client.requestApi).toHaveBeenCalledWith( + 'groups', + expect.objectContaining({ count: true }), + { ConsistencyLevel: 'eventual' }, + undefined, + ); + }); + it('auto-promotes to advanced mode when $search is present', async () => { (client.requestApi as jest.Mock).mockResolvedValue( makeResponse(200, { value: [] }), diff --git a/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.ts b/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.ts index 751a75059b..0c3f005f0e 100644 --- a/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.ts +++ b/plugins/catalog-backend-module-msgraph-incremental/src/clientHelpers.ts @@ -42,12 +42,9 @@ export async function requestOnePage( const { query, queryMode, nextLink, signal } = options; const appliedQueryMode = query?.search ? 'advanced' : queryMode ?? 'basic'; - // $count=true is required for advanced queries using ne/not in $filter or $search - if ( - appliedQueryMode === 'advanced' && - query && - (query.filter || query.search) - ) { + // Microsoft Graph requires $count=true whenever ConsistencyLevel: eventual is set, + // including plain listing requests with no $filter or $search. + if (appliedQueryMode === 'advanced' && query) { query.count = true; }