generic-chain
v0.0.1-development
Published
Create Middleware by chaining functions. Based on [benawad/graphql-chain](https://github.com/benawad/graphql-chain)
Downloads
4
Readme
Generic Chain
Create Middleware by chaining functions. Based on benawad/graphql-chain
Install
yarn add generic-chain
How to use
Step 1
Create middlewares
const validate: MiddlewareResolver = (
next,
ctx
) => {
if (ctx.name.length > 10) {
throw new Error("too long");
}
return next();
};
Step 2
Chain Middleware
import { chain } from "generic-chain";
// chain all your middlewares
const testMiddleware = chain([
validate,
cache,
]);
Step 3
Run the Chain
const start = testMiddleware((ctx) => {
console.log("Oh, Hello", ctx)
// this function runs after chain has ended
});
start(ctx); // provide the context.