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

@@ -8,7 +8,10 @@ import { User } from '../user/user.model';
import { UserEnvironmentsService } from './user-environments.service';
import * as E from 'fp-ts/Either';
import { throwErr } from 'src/utils';
import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard';
import { SkipThrottle } from '@nestjs/throttler';
@UseGuards(GqlThrottlerGuard)
@Resolver()
export class UserEnvironmentsResolver {
constructor(
@@ -157,6 +160,7 @@ export class UserEnvironmentsResolver {
description: 'Listen for User Environment Creation',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userEnvironmentCreated(@GqlUser() user: User) {
return this.pubsub.asyncIterator(`user_environment/${user.uid}/created`);
@@ -166,6 +170,7 @@ export class UserEnvironmentsResolver {
description: 'Listen for User Environment updates',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userEnvironmentUpdated(@GqlUser() user: User) {
return this.pubsub.asyncIterator(`user_environment/${user.uid}/updated`);
@@ -175,6 +180,7 @@ export class UserEnvironmentsResolver {
description: 'Listen for User Environment deletion',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userEnvironmentDeleted(@GqlUser() user: User) {
return this.pubsub.asyncIterator(`user_environment/${user.uid}/deleted`);
@@ -184,6 +190,7 @@ export class UserEnvironmentsResolver {
description: 'Listen for User Environment DeleteMany',
resolve: (value) => value,
})
@SkipThrottle()
@UseGuards(GqlAuthGuard)
userEnvironmentDeleteMany(@GqlUser() user: User) {
return this.pubsub.asyncIterator(