In my NestJS project I'm creating a GraphQL endpoint for a service that returns a dictonary object:
{
[key: number]: MyDataDto
}
In my .interfaces.ts
file I would like to have something like:
interface ArrayAsObject<T> {
[key: number]: T
}
@ObjectType()
export class MyDataDtoAsDictionary implements ArrayAsObject<MyDataDto> {
@Field(() => MyDataDto)
[key: number]: MyDataDto
}
But it gives me an error on the line with @Field
Decorators are not valid here. (ts1206)
If I remove the @Field
decorator it throws:
Type MyDataDtoAsDictionary must define one or more fields.
What is the right way to decorate that kind of object for GraphQL resolver?