I'm following the official nestjs documentation and using the throttler globally, but when I try to make a graphql request, it keeps throwing this error. It works for plain http requests though.
@Injectable()
export class GqlThrottlerGuard extends ThrottlerGuard {
getRequestResponse(context: ExecutionContext) {
if (context.getType() === 'http') {
const ctx = context.switchToHttp();
return { req: ctx.getRequest(), res: ctx.getResponse() };
}
const gqlCtx = GqlExecutionContext.create(context);
const ctx = gqlCtx.getContext();
return { req: ctx.req, res: ctx.res };
}
@Module({
imports: [
ThrottlerModule.forRoot([
{
ttl: 60000,
limit: 10,
},
]),
],
providers: [
{
provide: APP_GUARD,
useClass: GqlThrottlerGuard,
},
// ....
],
})
export class AppModule {
constructor() {
}
}