Skip to content

ExecutionContext

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/features/execution-context.interface.ts

Part of: Common

Interface describing details about the current request pipeline.

ExecutionContext describes the state and metadata available while a request moves through the application's execution pipeline. It provides a shared context for pipeline features, allowing them to read request-scoped information and coordinate processing without relying on global state.

Diagram

mermaid
graph LR
  Request[Incoming Request] --> Pipeline[Request Pipeline]
  Pipeline --> Context[ExecutionContext]
  Context --> FeatureA[Feature / Middleware A]
  Context --> FeatureB[Feature / Middleware B]
  FeatureA --> Result[Response or Execution Result]
  FeatureB --> Result

Usage

ts
import type { ExecutionContext } from '@common/interfaces/features/execution-context.interface';

function processFeature(context: ExecutionContext): void {
  // Read request-scoped details from the context and perform
  // feature-specific processing.
  console.log('Processing request with execution context:', context);
}

function runPipeline(context: ExecutionContext): void {
  processFeature(context);

  // Pass the same context to subsequent pipeline features so they
  // operate on the same request-scoped execution state.
  // validateFeature(context);
  // authorizationFeature(context);
}

AI Coding Instructions

  • Treat ExecutionContext as request-scoped data; do not reuse one instance across unrelated requests.
  • Pass the existing context through pipeline stages instead of creating disconnected context objects.
  • Keep feature-specific logic in pipeline handlers rather than adding unrelated behavior to the interface.
  • When extending the context, ensure new fields are available to every pipeline integration that depends on them.

Used by

48 references from 48 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (48)

  • AuthGuardintegration/graphql-code-first/src/common/guards/auth.guard.ts:9
  • DataInterceptorintegration/graphql-code-first/src/common/interceptors/data.interceptor.ts:10
  • CatsGuardintegration/graphql-schema-first/src/cats/cats.guard.ts:4
  • Guardintegration/inspector/src/circular-hello/guards/request-scoped.guard.ts:9
  • Interceptorintegration/inspector/src/circular-hello/interceptors/logging.interceptor.ts:10
  • RolesGuardintegration/inspector/src/common/guards/roles.guard.ts:4
  • TimeoutInterceptorintegration/inspector/src/common/interceptors/timeout.interceptor.ts:10
  • LoggingInterceptorintegration/inspector/src/core/interceptors/logging.interceptor.ts:10

…and 40 more.

Was this page helpful?

Download as PDF
ExecutionContext — NestJS head-to-head