From 03749592e986347017e1cc128f4fabc3e80f56d6 Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Tue, 12 Nov 2019 15:48:44 +0530 Subject: [PATCH] Adding the Modifying middleware chain samples --- docs/CustomMiddlewareChain.md | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/CustomMiddlewareChain.md b/docs/CustomMiddlewareChain.md index 251942829..775c54104 100644 --- a/docs/CustomMiddlewareChain.md +++ b/docs/CustomMiddlewareChain.md @@ -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); + }); +```