Im getting an error for DateTime field when subscription gets triggered
{"message":"Unable to serialize value '2020-04-07T09:25:08.132Z' as it's not instance of 'Date'","locations":[{"line":12,"column":3}],"path":["newMessage","sentOn"],"
extensions":{"code":"INTERNAL_SERVER_ERROR"}}
unlike TypeGraphQL DateTime
serialize(value: Date) {
if (!(value instanceof Date)) {
throw new Error(`Unable to serialize value '${value}' as it's not instance of 'Date'`);
}
return value.toISOString();
},
GraphqlDateTime "graphql-iso-date" DateTime
serialize (value) {
if (value instanceof Date) {
if (validateJSDate(value)) {
return serializeDateTime(value)
}
},
export const serializeDateTime = (dateTime: Date): string => {
return dateTime.toISOString()
}
I dont seem to find any difference
TypeGraphQL DateTime is throwing an error, "graphql-iso-date" DateTime is returning undefined -> null in response.
But this works fine while querying the data from the db and just sending it directly
Maybe you use some redis-based graphql subscription that seralize the payload.
You can see that here:
https://github.com/MichalLytek/type-graphql/blob/395357541cc4ca286a94fcad41a99c87b06df5b9/examples/redis-subscriptions/recipe.resolver.ts#L56-L71
For others ending up here who work with UTC DateTime strings the package graphql-scalars can be used.
Most helpful comment
TypeGraphQL DateTime is throwing an error, "graphql-iso-date" DateTime is returning undefined -> null in response.
Maybe you use some redis-based graphql subscription that seralize the payload.
You can see that here:
https://github.com/MichalLytek/type-graphql/blob/395357541cc4ca286a94fcad41a99c87b06df5b9/examples/redis-subscriptions/recipe.resolver.ts#L56-L71