我正在使用类验证器包来验证 GraphQL 输入类型中的链接。问题是当链接在输入字符串的末尾包含空格时验证失败。有什么方法可以在验证之前对其进行修剪吗?
import { InputType, Field, Int } from 'type-graphql';
import { IsUrl, IsOptional } from 'class-validator';
import { Project } from '../entities';
@InputType()
export default class UpdateProjectInput implements Partial<Project> {
@Field(type => Int)
id: number;
@Field({ nullable: true })
@IsUrl({}, { message: 'Link is not a valid url' })
@IsOptional()
link?: string;
}