NestJS-GraphQL-TypeORM-PostgresQL icon indicating copy to clipboard operation
NestJS-GraphQL-TypeORM-PostgresQL copied to clipboard

Same class used for Entity and DTO, but it has some custom properties exposed to API but not stored in DB.

Open leartbeqiraj1 opened this issue 2 months ago • 3 comments

Hello friend. Good work on this repo. I am facing an issue and would like to know your thoughts.

Let's say I have below class:

@ObjectType()
@Entity()
export class User {
  @Field(() => ID)
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Field(() => String)
  @Column()
  username: string;

  @Column()
  yearOfBirth: number;

  @Field(() => Number)
  age: number;
}

When I create new users, I store their year of birth in database, but clients can query user's age directly (which I calculate it in graphql resolver before returning the response to the client). However this doesn't work with your setup since your code iterates through every field and transforms it into Select query before executing it into the DB.

When I run below query: query User($input: GetOneInput!) { user(input: $input) { id username age } }

I get below error: "message": "Property "age" was not found in "User". Make sure your query is correct."

How would you approach this?

Thank you in advance.

leartbeqiraj1 avatar May 05 '24 12:05 leartbeqiraj1