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; }