We recently updated our JavaScript Graph SDK to version 1.4.0 and our Typescript Graph Types package to 1.6.0. The SDK release includes several new features and some bug fixes. The Typescript types includes updates to the models for Teams and Devices.
Page Iterator
Often collections of entities are split into pages and each page is returned with a URL to the next page. The PageIterator class simplifies consuming paged collections. Simply provide a callback method that will operate on each item in the paged collection and call the Iterate method. The PageIterator class will take care of following the NextLinks for you.
Iterate over all the messages
async function callingPattern() {
try {
// Makes request to fetch mails list. Which is expected to have multiple pages of data.
let response: PageCollection = await client.api("/me/messages").get();
// A callback function to be called for every item in the collection. This call back should return boolean indicating whether not to continue the iteration process.
let callback: PageIteratorCallback = (data) => {
console.log(data);
return true;
};
// Creating a new page iterator instance with client a graph client instance, page collection response from request and callback
let pageIterator = new PageIterator(client, response, callback);
// This iterates the collection until the nextLink is drained out.
pageIterator.iterate();
} catch (e) {
throw e;
}
}
If you want to stop the iterator before it iterates through the entire collection, you can simply return false from the callback.
Added Search query param functionality
Use the .search() function to perform a free text search over a collection of entities.
try {
let res = await client
.api("/me/people")
.search("dicaprio")
.get();
console.log(res);
} catch (error) {
throw error;
}
Bug Fixes:
- Should interface AuthProviderCallback accept null on accessToken
- OneNote Pages not being returned using contentUrl