feat: introducing rate-limiting on queries, mutations and most of the REST endpoints (HBE-111) (#46)

* feat: rate-limiting guard added and configured in app module

* feat: rate-limit annotation added in controllers and resolvers (query, mutation, not subscription)

* docs: added comments
This commit is contained in:
Mir Arif Hasan
2023-03-21 17:15:50 +06:00
committed by GitHub
parent f78354a377
commit fa8ca0569d
18 changed files with 115 additions and 4 deletions

View File

@@ -31,7 +31,10 @@ import {
} from './input-type.args';
import { ReqType } from 'src/types/RequestTypes';
import * as E from 'fp-ts/Either';
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
import { SkipThrottle } from '@nestjs/throttler';
@UseGuards(GqlThrottlerGuard)
@Resolver(() => UserCollection)
export class UserCollectionResolver {
constructor(
@@ -352,6 +355,7 @@ export class UserCollectionResolver {
description: 'Listen for User Collection Creation',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userCollectionCreated(@GqlUser() user: AuthUser) {
return this.pubSub.asyncIterator(`user_coll/${user.uid}/created`);
@@ -361,6 +365,7 @@ export class UserCollectionResolver {
description: 'Listen to when a User Collection has been updated.',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userCollectionUpdated(@GqlUser() user: AuthUser) {
return this.pubSub.asyncIterator(`user_coll/${user.uid}/updated`);
@@ -370,6 +375,7 @@ export class UserCollectionResolver {
description: 'Listen to when a User Collection has been deleted',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userCollectionRemoved(@GqlUser() user: AuthUser) {
return this.pubSub.asyncIterator(`user_coll/${user.uid}/deleted`);
@@ -379,6 +385,7 @@ export class UserCollectionResolver {
description: 'Listen to when a User Collection has been moved',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userCollectionMoved(@GqlUser() user: AuthUser) {
return this.pubSub.asyncIterator(`user_coll/${user.uid}/moved`);
@@ -388,6 +395,7 @@ export class UserCollectionResolver {
description: 'Listen to when a User Collections position has changed',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userCollectionOrderUpdated(@GqlUser() user: AuthUser) {
return this.pubSub.asyncIterator(`user_coll/${user.uid}/order_updated`);