'NestJS, GraphQL, class-validator - access request object inside validate method

I have a custom class-validator rule:

import { Injectable } from "@nestjs/common";
import { ValidatorConstraint, ValidatorConstraintInterface, ValidationArguments } from "class-validator";

@ValidatorConstraint({ name: "Foo", async: true })
@Injectable()
export class FooRule implements ValidatorConstraintInterface {    
    async validate(value: unknown, args: ValidationArguments) {
        // how to access request object from here?
    }
    
    defaultMessage(args: ValidationArguments) {
        return "NOT OK.";
    }
}

How do I access the request object inside the validate() method?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source