Microsoft Graph SDK for JavaScript – 2.0.0

Darrel Miller

We are excited to announce a new release of our JavaScript SDK 2.0.0 for Microsoft Graph. The version is updated to 2.0.0 because it contains a number of breaking changes. However, making the necessary changes to adopt this version should not be significant. More details can be found in our migration guide.

Removed polyfills

In the past our library has included polyfills for fetch and promise. However, doing so adds to the size of our library and many of our customers do not need these polyfills due to their target platform or the fact they already include them in their application. We have now removed the polyfills for fetch and promise. Developers who do still need the polyfills will need to include them explicitly.

New minified files

Previously we shipped two different bundles, graph-js-sdk-web.js and graph-js-sdk-core.js, with and without dependencies bundled. These files are no longer available. Now, a new file named graph-js-sdk.js will be shipped for use in any kind of application and can simply be referenced via a script tag. For developers building libraries that want to include the SDK, it is now available as an ES module in the graph-es-sdk.js file.

Getting Raw Response

In the past, if you wanted to get the raw HTTP response back it was necessary to pass a callback in the get(), put(), post(),etc method. The implementation of this approach was causing issues for node.js applications. To resolve this and provide a more consistent experience, we introduced a new ResponseType. Returning raw responses is now as simple as:

client
    .api('/me')
    .responseType(ResponseType.RAW)
    .get((err, rawResponse) => {
        console.log(rawResponse);
    });

Changes to the Authentication Provider

In anticipation for support of more authentication flows, the MSALAuthenticationProvider class has been renamed to ImplicitMSALAuthenticationProvider.

In order to create an instance of ImplicitMSALAuthenticationProvider you now must pass an instance of MSAL’s UserAgentApplication and MSALAuthenticationProviderOptions. This brings consistency with the SDKs from other platforms and ensures that an application can have easy access to the UserAgentApplication to interact with it directly. Be aware that in the v1.0.0 release of MSAL.js there were breaking changes to the way UserAgentApplication is created.

Default Content-Type for PUT method

Some users reported confusion when trying to perform PUT calls that would fail due to missing or invalid Content-Type header. To minimize these issues we decided to default the Content-Type to application/json as this is the most common case. When trying to PUT a payload other than JSON, simply use the .header method to change the Content-Type.

Definitely Typed

For developers who only need to use the Typescript types for the request and response models we have now published these types to the Definitely Typed repository under the name microsoft-graph.

Feedback

Thank you to all the community members who continue to provide us feedback on this library. We encourage you to go and upgrade to this new version of our Graph JavaScript API. You can follow these links for installation instructions, release notes and npm packages.

Feedback usabilla icon