is typegraphql field generic object possible

is typegraphql field generic object possible


0

Hi I am a bit of a newbie in typegraphql and graphql in general

so theres a thing that i want to change but to put it simply:

Current Working Code I want to change:

@ObjectType()
export class Game {
  @Field(() => Int)
  id: number;

  @Field({ nullable: true })
  producedByUserName?: string;
  
  @Field({ nullable: true })
  producedByUserEmail?: string;
}

Code I want to achieve is something like this

@ObjectType()
export class Game {
  @Field(() => Int)
  id: number;

  producedByUserName?: string;
  producedByUserEmail?: string;

  @Field(type => Object, { name: 'producedBy', nullable: true }) // i also tried Record<string, string>
  producedBy(){
    return {
      email: this.producedByUserEmail,
      name: this.producedByUserName,
    }
  }
}

I am wondering if I could achieve something like this.

i tried the code above and its always throwing
CannotDetermineGraphQLTypeError: Cannot determine GraphQL output type for ‘producedBy’ of ‘Game’ class.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *