type-graphql#MiddlewareFn TypeScript Examples
The following examples show how to use
type-graphql#MiddlewareFn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: rate-limiter-middleware.ts From convoychat with GNU General Public License v3.0 | 6 votes |
RateLimit = ({
limit = 50,
window = "25min",
}: IRateLimit = {}): MiddlewareFn<any> => {
return async ({ root: parent, args, context, info }, next) => {
const error = await limiter(
{
parent,
args,
context,
info,
},
{
max: limit,
window: window,
}
);
if (error) throw new Error(error);
return next();
};
}
Example #2
Source File: typegoose-middleware.ts From convoychat with GNU General Public License v3.0 | 6 votes |
TypegooseMiddleware: MiddlewareFn = async (_, next) => {
const result = await next();
if (Array.isArray(result)) {
return result.map(item =>
item instanceof Model ? convertDocument(item) : item
);
}
if (result instanceof Model) {
return convertDocument(result);
}
return result;
}
Example #3
Source File: isAuth.ts From lireddit with MIT License | 5 votes |
isAuth: MiddlewareFn<MyContext> = ({ context }, next) => {
if (!context.req.session.userId) {
throw new Error("not authenticated");
}
return next();
}