Date object deserialization issue with Nestjs and GraphQL (using microservice)

Viewed 294

I'm querying my PG database using graphQL to get an object (MyObject) like this :

export class MyObject {
  id: string;
  description: ObjectDescription;
  date: Date;
}

class ObjectDescription {
  name: string;
  description: string;
}

class MyObjectOutput {
  output: MyObject;
}

I have apparently no problem with Nest and PG : all attributes are correctly deserialized (date => Date / description => ObjectDescription).

However, I'm using microservices (Redis) and when my graphQL resolver receives a message from a controller with the queryed object (MyObject), the date attribute is an string and not a Date object.

The weird thing is that my description attribute (ObjectDescription) is correctly deserialized.

My graphQL resolver method is something like :

public async myObjectGet() {
  
  const myObject = await this.microservice.send<MyObjectOutput>('my-object-fetch', message);
  return myObject
}

I also tried to use Nest class-transform on Date attribute

import { Type } from 'class-transformer';
... 
@Type(() => Date)
date: Date;
...

But it doesn't work either.

I'd appreciate any ideas on how to get the date attribute as a Date object and not string. Thanks !

0 Answers
Related