MichalLytek / MichalLytek/type-graphql

Support ADR pattern in subscriptions

Open
#542 5 comments 2 reactions 1 assignee View on GitHub

@MichalLytek is already working on this.

Since Jun 10, 2021.

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.**
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.