-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PageIterator should not mutate his arguments #959
Comments
@OlivierCuyp Thank you for bringing this up. Can you please provide the steps to reproduce the issue, that is, the use case which is throwing the unexpected behaviour |
@nikithauc I think, the fix would have been written faster than the example, but here it is: test.ts import 'isomorphic-fetch';
import { Client, PageIterator } from '@microsoft/microsoft-graph-client';
import { TokenCredentialAuthenticationProvider } from '@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials';
import { ClientSecretCredential } from '@azure/identity';
const fakeGraphApiResponse = {
value: [{ foo: 'bar' }]
};
const credential = new ClientSecretCredential('baz', '1', 'hush');
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['https://graph.microsoft.com/.default']
});
const client = Client.initWithMiddleware({ authProvider });
const pageIterator = new PageIterator(client, fakeGraphApiResponse, () => true);
pageIterator.iterate();
console.log(fakeGraphApiResponse); Running it gives: ❯ npx ts-node ./test.ts
{ value: [] } As you can see the ❯ npx ts-node ./test.ts
{
value: [{ foo: 'bar' }]
} |
@nikithauc since it was a quick fix, I made a PR. |
Fix released in v3.0.3 |
I apologize if this is not the right place or format for this. I haven't commented before. The callback for the PageIterator callback is not firing for me for pages after the first. I believe this may be related to the change here.
This works for the first page. However, fetchAndUpdateNextPageData() does not reset the cursor. That means that for each subsequent page, the cursor is already at the collection length, effectively skipping the callback while continuing to iterate through the pages. I believe adding this.cursor = 0; to the end of the fetchAndUpdateNextPageData() function resolves the problem for me
|
This has been fixed in 3.0.4 and merged here : #1046 Can you update to the latest version and test if this solves the issue? Thanks! |
Oops, thought I had the most recent version. Yes, that works. Thanks! |
Bug Report
Prerequisites
For more information, see the
CONTRIBUTING
guide.Description
Impure function has always unexpected behaviour.
PageIterator his mutating the response he is given, he should not.
Here is the mutation:
https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/src/tasks/PageIterator.ts#L127
Expected behavior:
The response passed to the PageIterator should be intact after iteration.
Change the Array.shift method to use Array.slice and keep a cursor index.
Actual behavior:
The response passed to the PageIterator is empty after the iteration.
SDK Version - 3.0.2
The text was updated successfully, but these errors were encountered: