MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
7.98k stars 674 forks source link

I hope I can share fields without specify Type #1702

Closed wenerme closed 1 month ago

wenerme commented 1 month ago

Is your feature request related to a problem? Please describe.

I want to share ProfileFieldsMixinObject fields to InputType & ObjectType, I don't know which is the best practiese here, I hope thre is a decorator for middle class like @ShareType.

function detectType(obj: any) {
  return InputType
}

 function withProfileFields<TBase extends Constructor>(Base: TBase) {
  let Type = detectType(Base)

   // plan A
  @Type()
   // plan B
    // @InputType()
    // @ObjectType()
  class ProfileFieldsMixinObject extends Base {
    @Field(() => String, { nullable: true })
    fullName?: string;
  }

  return ProfileFieldsMixinObject;
}

Describe the solution you'd like

Maybe @ShareType that can be treat as transparent ?

Describe alternatives you've considered

Additional context

MichalLytek commented 1 month ago

This is the way to go, it's mentioned in the docs:

@InputType()
@ObjectType()
wenerme commented 1 month ago

Thanks