Skip to content
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

Simplify building middleware chain #239

Merged
merged 2 commits into from
Oct 18, 2019
Merged

Simplify building middleware chain #239

merged 2 commits into from
Oct 18, 2019

Conversation

krototype
Copy link
Contributor

Summary

Previously, if we needed to add a middleware to the middleware chain, we had to make a custom middleware chain and then add the middlewares accordingly.

Now, using getMiddlewareChain() and setMiddlewareChain() we can create the middleware in an easier way.

Sample Javascript Code:

// 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();
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);
	});

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@krototype krototype merged commit de8a55b into dev Oct 18, 2019
@nikithauc nikithauc deleted the build_middleware_chain branch September 2, 2020 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant