NestJS · Senior · Question 6 of 75
How do you inject the current request into a provider, and what does it cost?
- 1Use
@Req()in the service constructor with no cost - 2It's impossible in services
- ✓Correct answer: Inject
REQUESTfrom@nestjs/corein a request-scoped provider; this makes the provider and its dependents request-scoped
Explanation
In GraphQL the request lives in the context (CONTEXT). For most needs, ALS gives per-request data without scope changes.