nestjs-temporal-core
    Preparing search index...

    Function QueryMethod

    • Marks a method as a query handler for the workflow. Queries allow external clients to retrieve the current state of a running workflow without affecting its execution. Query methods should be synchronous and side-effect free.

      This decorator works in v8 isolated environments by registering query handlers at runtime without relying on dependency injection or external services.

      Parameters

      • OptionalqueryName: string

        Optional custom query name (defaults to method name)

      Returns MethodDecorator

      // In function-based workflow
      const getStatusQuery = wf.defineQuery<string>('getStatus');
      const getItemsQuery = wf.defineQuery<OrderItem[]>('getItems');

      export async function orderWorkflow(): Promise<void> {
      let orderStatus = 'pending';
      let orderItems: OrderItem[] = [];

      wf.setHandler(getStatusQuery, () => orderStatus);
      wf.setHandler(getItemsQuery, () => [...orderItems]);
      }
      • Query methods must be synchronous and return immediately
      • They should not modify workflow state or have side effects
      • They can be called at any time during workflow execution

      SignalMethod for modifying workflow state