Skip to content

@IsDateString decorator not producing error for field "3333" #1748

Description

@BorisPT

Description

In a NestJS project, with GraphQL
Decorating a field with @IsDateString does not throw an error if input is "3333".
Will throw error for "6363737398" for instance.

Minimal code-snippet showcasing the problem

@InputType()
export class CreateLessonInput{

    // this throws an error when the input is wrong
    @MinLength(1)
    @Field()
    name : string;
    
    // this does not throw an error if startDate is "3333", for instance
    @IsDateString({strict : true})
    @Field()
    startDate : string;

    @IsDateString({strict : true})
    @Field()    
    endDate : string;

}

// ----------- ---------- 

Example of query in Playground:

mutation CreateLesson($creationInput: CreateLessonInput!) {
  createLesson(inputForCreation: $creationInput) {
    id
    name
  }
}

where variables are
{"creationInput": {
  "name": "History", 
  "startDate": "3333", 
  "endDate": "2023-12-28T16:07:06.383Z" 
} }

Expected behavior

Validation should return an invalid IsoString as output, since it's not a valid date.

Actual behavior

Error is not thrown

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions