MichalLytek / MichalLytek/type-graphql
Field accessors
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
MikroORM has a feature called [References](https://mikro-orm.io/docs/entity-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):
```ts
@ObjectType()
class Book {
@Field(() => User, {get: author => author.load()})
author!: Reference;
}
```
**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:
```ts
@ObjectType()
class Book {
authorRef!: Reference;
@Field(() => User)
get author() {
return this.authorRef.load();
}
}
```
Contributor guide
Research direction
Start with the Field decorator and its current value-resolution path; the issue provides no file or test path. Done means an optional custom get accessor is supported, with identity as the default, so GraphQL exposes the resolved relation rather than MikroORM's Reference wrapper.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100