msgraph-sdk-javascript
Official Microsoft Graph JavaScript SDK for calling the Graph API from Node.js and the browser.
Repository Health
Technical Analysis
The Microsoft Graph JavaScript client library is Microsoft’s official wrapper around the Microsoft Graph REST API, giving Node.js and browser applications a fluent client.api(path).get()-style interface instead of hand-rolled fetch calls. It handles authentication provider wiring, request/response middleware, retries, redirects, and telemetry so callers can focus on which Graph resource (users, mail, files, Teams, etc.) they need rather than the plumbing to reach it.
Beyond the basic request builder, the SDK ships purpose-built tasks for two hard problems in the Graph API surface: chunked large-file uploads to OneDrive/SharePoint/Outlook/Print via LargeFileUploadTask, and paged collection traversal via PageIterator. A pluggable middleware chain (authentication, retry, redirect, telemetry, and a chaos-testing handler for simulating failures) lets consumers customize behavior without forking the client, and first-class authentication provider adapters exist for MSAL browser, Azure Identity token credentials, and custom providers.
What You Get
- A fluent
Client.init(...).api(path).get()/.post()/.patch()request builder covering all Graph HTTP verbs, OData query parameters, and custom headers/options - A default middleware chain (AuthenticationHandler, RetryHandler, RedirectHandler, TelemetryHandler, HTTPMessageHandler) that can be replaced or extended with custom middleware
LargeFileUploadTask/OneDriveLargeFileUploadTaskfor chunked, resumable uploads to OneDrive, SharePoint, Outlook, and the Print APIPageIteratorfor transparently walking paginated Graph collections (e.g./me/messages) without manual@odata.nextLinkhandling- Built-in authentication provider adapters for MSAL Browser, Azure Identity
TokenCredential, and any custom auth callback - A
ChaosHandlermiddleware for simulating Graph API failures (throttling, 5xx errors) in tests
Common Use Cases
- Building an SPA (Angular/React/Vanilla JS) that signs users in with MSAL and calls Microsoft Graph to read profile, mail, or calendar data
- A Node.js/Express backend service that authenticates with client credentials via Azure Identity and manages Microsoft 365 resources on behalf of an app
- Uploading large files (videos, backups) to OneDrive or SharePoint in resumable chunks instead of a single oversized request
- Iterating a user’s full mailbox or a large SharePoint list page-by-page without writing manual
@odata.nextLinkloops - Sending mail, managing calendar events, or querying directory/user data as part of an internal M365 automation tool
Under The Hood
Architecture
The SDK is layered around a small core: Client (in src/Client.ts) is a thin factory that resolves an HTTPClient from either an authProvider (wrapped via CustomAuthenticationProvider) or a fully custom middleware array, then hands out GraphRequest instances from client.api(path). GraphRequest (src/GraphRequest.ts) owns URL assembly (host, Graph API version, OData query params) and delegates the actual call to the shared HTTPClient, which runs the request through a linked chain of Middleware implementations (AuthenticationHandler, RetryHandler, an optional RedirectHandler in Node, TelemetryHandler, and a terminal HTTPMessageHandler) assembled by MiddlewareFactory.getDefaultMiddlewareChain. This chain-of-responsibility design is the extension point: swapping Client.init for Client.initWithMiddleware lets callers substitute their own chain (including the ChaosHandler for fault injection) without touching GraphRequest or Client at all. Two independent task classes, LargeFileUploadTask and PageIterator, sit outside the core request path and consume the same Client/GraphRequest surface to implement chunked uploads and pagination as composable helpers rather than special-cased branches inside the client itself.
Tech Stack
The library is written in TypeScript and built with tsc into parallel CJS and ES module outputs (tsconfig-cjs.json/tsconfig-es.json), then bundled with Rollup (rollup.config.js) for the browser script-tag distribution; Babel (@babel/preset-env, @babel/plugin-transform-runtime) handles down-leveling for older runtimes. Runtime dependencies are deliberately minimal — just @babel/runtime and tslib — with the Fetch API as the sole HTTP primitive (callers must supply a fetch polyfill like isomorphic-fetch on older Node). Authentication integrates with @azure/msal-browser and @azure/identity as peer/dev dependencies for MSAL and token-credential flows respectively, and @microsoft/microsoft-graph-types supplies Graph’s TypeScript model typings separately from this package.
Code Quality
Testing runs on Mocha with Chai assertions for Node-targeted test:cjs, plus Karma with ChromeHeadless for browser-targeted specs, and coverage is tracked via nyc; the test/ tree mirrors src/ with dedicated suites for authentication, middleware, tasks, and core request-building, including dummy/fake providers (DummyAuthenticationProvider, DummyHTTPMessageHandler) for isolating middleware behavior. ESLint (.eslintrc.json) and Prettier (.prettierrc) are enforced via Husky pre-commit hooks and lint-staged, and GitHub Actions CI (ci_validation.yml) builds and tests against Node 16/18/20 on every pull request, alongside a separate CodeQL security-analysis workflow. Errors are represented as typed GraphError/GraphClientError classes surfaced through a dedicated GraphErrorHandler rather than left as raw thrown values, and public classes/interfaces carry consistent JSDoc @module/@public/@private annotations throughout.
What Makes It Unique
Rather than being a generic HTTP client pointed at Graph, the SDK bakes in solutions to Graph-specific pain points: LargeFileUploadTask/OneDriveLargeFileUploadTask implement Graph’s resumable byte-range upload session protocol for OneDrive, SharePoint, Outlook, and Print, and PageIterator automates @odata.nextLink traversal so callers never hand-roll pagination loops. The middleware chain’s ChaosHandler is a distinctive addition for a client SDK — it lets consumers simulate Graph throttling and server errors in their own test suites to validate retry/backoff behavior without depending on the live service misbehaving. Multiple interchangeable authentication provider adapters (MSAL Browser, Azure Identity token credentials, custom callback) reflect Microsoft’s own evolving identity story being absorbed into one client rather than pushed onto every consumer.
Used by 8 apps in this directory
Activepieces
Automation · AI Assistants
Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.
Botpress
AI Assistants · AI Development · Customer Support
The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.
Jitsi Meet
Team Chat · Collaboration · Video Conferencing
Open-source, end-to-end encrypted video conferencing you can self-host or embed into any web or mobile app.
LibreChat
Developer Tools · AI Assistants
Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.
Midday
Invoicing Finance · Productivity
All-in-one AI-powered business operations platform for freelancers and solo entrepreneurs to manage invoicing, time tracking, banking, and financial intelligence.
nao
AI Development · Analytics
Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.
NocoDB
No Code Platforms · Databases · Low Code Platforms
Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.
twenty
CRM
The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.