fix: forbid creation of objects or fields with certain characters or with forbidden keywords that clashes with pg_graphql (#3957)

* fix: forbid creation of objects or fields with certain characters or with forbidden keywords that clashes with pg_graphql

* refactor: add a decorator for name validation and use it on fields
This commit is contained in:
Mohamed Houssein Douici
2024-02-24 12:32:01 +01:00
committed by GitHub
parent b1eb0577bc
commit 0fe838d320
4 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import {
registerDecorator,
ValidationOptions,
ValidationArguments,
} from 'class-validator';
export function IsValidName(validationOptions?: ValidationOptions) {
return function (object: object, propertyName: string) {
registerDecorator({
name: 'IsValidName',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
validator: {
validate(value: any) {
return /^(?!(?:not|or|and)$)[^'\"\\;.=*/]+$/.test(value);
},
defaultMessage(args: ValidationArguments) {
return `${args.property} has failed the name validation check`;
},
},
});
};
}