Field accessors

Author: arcanisCreated Dec 9, 2020Updated Feb 10, 2025
LabelsEnhancement :new:Community :family_man_girl:Discussion :speech_balloon:

Is your feature request related to a problem? Please describe. MikroORM has a feature called References - basically, fields contain a wrapper that itself contain the true relation entity. Those wrappers are an implementation detail, and thus shouldn't be exposed through the GraphQL API.

Describe the solution you'd like I'd like my Field decorator to support defining a custom data accessor (by default an identity function):

typescript
@ObjectType()
class Book {
  @Field(() => User, {get: author => author.load()})
  author!: Reference<User>;
}

Describe alternatives you've considered I'm currently doing the following, which requires a somewhat heavy boilerplate since I have to create "unneeded" class properties and thus loose coupling:

typescript
@ObjectType()
class Book {
  authorRef!: Reference<User>;

  @Field(() => User)
  get author() {
    return this.authorRef.load();
  }
}

Source: MichalLytek/type-graphql