type-graphql
type-graphql copied to clipboard
GraphQLISODateTime scalar does not throw error on bad input values
Describe the Bug
The conversion function assumes that new Date("some garbage") will throw an exception for bad input values on the Date constructor. When given bad inputs the Date object will just return Invalid Date which is still a Date object, and not throw.
To Reproduce
Create an input object with a field which is type Date
Pass in in invalid date string for that fields value
The field get set to null
Expected Behavior Throws the error here https://github.com/MichalLytek/type-graphql/blob/3137ab532fbe6742d06f938d95eefddee1eea435/src/scalars/isodate.ts#L7 back to the caller.
Environment (please complete the following information):
- OS: Linux
- Node 16.17
- Package version 1.2.0-rc1
- TypeScript version 4.7
Additional Context
I've replaced the provided GraphQLISODateTime with my own copy of it and have modified the conversion function like so to fix this for us.
function convertStringToDate(dateString: string) {
const value = new Date(dateString);
if (value instanceof Date && !isNaN(value.valueOf())) {
return value;
}
throw new Error("Provided date string is invalid and cannot be parsed");
}
I think for new major release we should stop having own scalars with bugs and just use graphql-scalars package 👀
I think for new major release we should stop having own scalars with bugs and just use
graphql-scalarspackage 👀
Thanks for that, I'll actually use the one from graphql-scalars instead.
Hey @MichalLytek @brycepolly I would love to pick this up. However a little bit of guidance would be most appreciated!
Closing via 480ec1d 🔒
We now use graphql-scalars so this issue is not relevant anymore.