MichalLytek / MichalLytek/type-graphql
Support ADR pattern in subscriptions
@MichalLytek is already working on this.
Since Jun 10, 2021.
- 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.**
When using the Subscription annotation with a custom subscribe, you cant access your class dependencies and cant use the parameter annotations to selectively pick from the resolver args.
**Describe the solution you'd like**
A solution would be to allow placing the Subscription annotation on a class (and maybe also the FieldResolver annotation later) enabling the ADR pattern. Translated to graphql this would make, the Subscription class the Action, the Domain are your (internal) services & models and the Responder is graphql itself.
```ts
@Subscription(() => News) // or its own dedicated decorator SubscriptionAction
export class NewsSubscription implements SubscriptionAction {
public constructor(/* my deps */) {}
// required if no string topics given, overrides declaritive options from annotation if given
public subscribe(@Arg('category') category: string): AsyncIterator | Promise {
// ...
}
// optional, args get merged
public resolve(@Arg('language') language: string): Promise {
// ...
}
}
```
**Additional context**
https://en.wikipedia.org/wiki/Action%E2%80%93domain%E2%80%93responder
It can also improve reuseability and organization.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.