Skip to content

Adding the Modifying middleware chain samples #247

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

Merged
merged 1 commit into from
Nov 26, 2019
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);
});
```