Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Types to be decorated with @ObjectType() #523

Closed
cyberprodigy opened this issue Jan 15, 2020 · 1 comment
Closed

Allow Types to be decorated with @ObjectType() #523

cyberprodigy opened this issue Jan 15, 2020 · 1 comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists Wontfix ❌ This will not be worked on

Comments

@cyberprodigy
Copy link

Is your feature request related to a problem? Please describe.
In order to reduce required code it would be great to be able to decorate TypeScript types with @ObjectType()

Describe the solution you'd like
Say I have class ApplicationForm

@ObjectType()
class ApplicationForm {
   @Field(() => Int)
   public id: number;

   @Field(() => String)
   public title: string;

   @Field(() => String)
   public description: string;
} 

Then I want to use TS utility Omit on ApplicationForm to create SampleApplicationForm , which has no ID

@ObjectType()
type SampleApplicationForm = Omit<ApplicationForm, "id"> 

Describe alternatives you've considered
I would like to know if there are any alternatives. The goal is to reduce repeating almost similar datatypes.
Often times the property is available but other times not.
Also very common usecase is being able to specify that property is nullable or not depending on context of query/mutation called.

Additional context
N/A

@MichalLytek
Copy link
Owner

Unfortunatelly, decorators cannot be applied on types as they are erased in compilation and not present in runtime. So you have to use classes, not types or interfaces.

Duplicate of #453 🔒

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists Wontfix ❌ This will not be worked on labels Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists Wontfix ❌ This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants