MichalLytek / MichalLytek/type-graphql

Field accessors

Open
#760 8 comments 1 reaction 0 assignees View on GitHub
Community :family_man_girl: Discussion :speech_balloon: Enhancement :new:
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.