Any solution for changing inputType fields name? #1153
-
Hello I am trying to change all the fields with name Is there any solution for that? like a middleware? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I'm not sure if it is a good solution or not, but here is what I did const Ref = (field: string) => {
return (target: any, propertyKey: string) => {
Object.defineProperty(target, propertyKey, {
set: function (x) { this[field] = x },
get: function () { return this[field] },
});
return target
}
}
@InputType()
export class UserTestInput {
@Ref("_id") <============== Ref decoration
@Field(() => ObjectId, { nullable: true })
id?: ObjectId
_id: ObjectId
} This decoration will replace the field by a getter and a setter with its own name ( this might have bugs, I appreciate if you check it and comment what you think about it |
Beta Was this translation helpful? Give feedback.
-
You should be able to use getters and setters for aliasing properties, so that it's @InputType()
export class UserCreateInput {
balance!: number;
@Field(_type => Float, {
nullable: false
})
get accountBalance() {
return this.balance;
}
set accountBalance(balance: number) {
this.balance = balance;
}
} |
Beta Was this translation helpful? Give feedback.
You should be able to use getters and setters for aliasing properties, so that it's
id
outside and_id
inside.