microsoftgraph / msgraph-sdk-javascript

Microsoft Graph client library for JavaScript
https://graph.microsoft.com
MIT License
730 stars 220 forks source link

Infinite loop when using nextLink in GET /me/people response #1656

Open shelbycotton opened 3 months ago

shelbycotton commented 3 months ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

In my app, I'm using the people API to return a list of relevant people to the logged-in user. I'm then taking the nextLink in the API response to request the remaining people, but this results in an infinite loop. After taking a closer look, I noticed that the skip param value in the @odata.nextLink URL is 0, which I believe is the culprit.

Steps to Reproduce

For brevity, I'm including code to get the initial nextLink response, but I can include my looping logic if needed.

import { Client } from '@microsoft/microsoft-graph-client';

const client = Client.init({
    authProvider: (done) => done(null, 'ACCESS_TOKEN')
  });

let request = client.api('/me/people');

const properties = [
  'id',
  'displayName',
  'givenName',
  'surname',
  'scoredEmailAddresses',
  'phones'
];

request = request.select(properties);

const response = await request.get();
console.log(response['@odata.nextLink']);

The console should log https://graph.microsoft.com/v1.0/me/people?%24select=id%2cdisplayName%2cgivenName%2csurname%2cscoredEmailAddresses%2cphones&%24skip=0.

Expected behavior: The skip param in the @odata.nextLink URL should be offset by the number of returned results in order to request the following "page." If there are no more people to return, @odata.nextLink should be undefined.

Actual behavior: The @odata.nextLink URL in the response has a skip param of 0, thereby returning the same results in following requests and resulting in an infinite loop.

Usage Information

SDK Version - 3.0.7

Node Version - 20.11.1