MichalLytek / MichalLytek/type-graphql

Feature: Decorate classes without @Decorators.

Open
#294 5 comments 2 reactions 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

If I have existing models that are used in other apps not requiring type-graphql or graphql at all, it'd be nice to be able to decorate those without wrapping them.

Lets say I have:

```typescript

/** @org/db/Doc.ts */
interface Doc {
_id: ObjectId;
createdAt: Date;
updatedAt: Date;
}

abstract class Document {
public doc: T;

constructor(doc: T) {
this.doc = doc;
}

get id(): string {
return this.doc._id.toHexString();
}

// ...
}

/** @org/db/User.ts */
interface UserDocument extends Doc {
name: string;
}

class User extends Document {
get name(): string {
return this.doc.name;
}
}

/** @other/graphql/___.ts */
import { ObjectTypeDecorator } from 'type-graphql';
import { User, Document } from '@org/db';

const documentDecorator = new ObjectTypeDecorator(Document);
documentDecorator.field('id');
documentDecorator.field('createdAt');
documentDecorator.field('updatedAt');

const userDecorator = new ObjectTypeDecorator(User);
userDecorator.field('name');

// can now use "User" as a type throughout.
```

Contributor guide

Open the contributing guide

Research direction

Start with the ObjectTypeDecorator usage shown in @other/graphql/___.ts and compare it with the example model files @org/db/Doc.ts and @org/db/User.ts. Define what external decoration must support for Document and User, including their fields; done means User can be used as a GraphQL type while the original model package remains free of type-graphql dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.