Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/CustomMiddlewareChain.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,40 @@ export class MyLoggingHandler implements Middleware {
}
```
Refer [MiddlewareOptions](../src/middleware/options/IMiddlewareOptions.ts) interface to know its structure.

### Modifying the Current Middleware Chain

```js
// initialising client
const client = MicrosoftGraph.Client.init({
defaultVersion: "v1.0",
debugLogging: true,
authProvider: (done) => {
done(null, secrets.accessToken);
},
});

// getting the current middleware chain (in this case, it's the default one)
let arr = client.getMiddlewareChain();

// Initialising the Middleware chain that we created
const dummyRandomHandler = new dummyRandomHandler();

// adding the dummy handler in the array of middlewares at 3rd position
arr.splice(2, 0, dummyRandomHandler);

// setting the new middleware chain
client.setMiddlewareChain(arr);

// calling the api
client
.api("/me")
.select("displayName")
.get()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
```