Function: QueryMethod()
QueryMethod(
queryName?):MethodDecorator
Defined in: src/decorators/workflow.decorator.ts:179
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
queryName?
string
Optional custom query name (defaults to method name)
Returns
MethodDecorator
Example
Basic Query Handler
// 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]);
}
Remarks
- 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
See
SignalMethod for modifying workflow state