@Injectable()
export class GqlThrottlerGuard extends ThrottlerGuard {
getRequestResponse(context: ExecutionContext) {
const gqlCtx = GqlExecutionContext.create(context);
const ctx = gqlCtx.getContext();
return { req: ctx.req, res: ctx.res };
}
}
Here I am getting only req from ctx, res is undefined. I am using GraphQL with express in nestjs.
This is how my context object looks like before creating a GqlExecutionContext:
ExecutionContextHost {
args: [
undefined,
{ id: 2 },
{ req: [IncomingMessage] },
{
fieldName: 'user',
fieldNodes: [Array],
returnType: User!,
parentType: Query,
path: [Object],
schema: [GraphQLSchema],
fragments: [Object: null prototype] {},
rootValue: undefined,
operation: [Object],
variableValues: {},
cacheControl: [Object]
}
],
constructorRef: [class UsersResolver],
handler: [Function: findOne],
contextType: 'graphql'
}
Error:
[Nest] 30284 - 08/01/2022, 12:54:25 am ERROR [ExceptionsHandler] Cannot read property 'ip' of undefined
TypeError: Cannot read property 'ip' of undefined
at ThrottlerGuard.getTracker (C:\Users\Mahesh\OneDrive\Desktop\graphql-server\node_modules\@nestjs\throttler\dist\throttler.guard.js:95:16)