MichalLytek / MichalLytek/type-graphql
[doc] DI vs Apollo Context/@Ctx
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
Early on in the docs in the resolvers chapter you introduce DI as a way to access data without re-initializing new classes. I used this with typedi to access the DB connection.
However, I realized that Apollo Context and injecting with it with `@Ctx` might be better for this use case. It's shorter, quicker and you don't have to check if the connection is already established. I'd just mention it in the docs as alternative to DI, so people don't enter the rabbit hole of DI like I did (btw re our prior discussion, typedi is the best lib, I was wrong).
Contributor guide
Research direction
Read the resolvers chapter and its section on dependency injection first. Add a concise discussion of Apollo Context and @Ctx as an alternative for accessing a database connection, including the relevant trade-offs. The documentation is done when readers can compare this approach with DI for that use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100