Loading...
Was this page helpful?
This documentation provides a reference to the createWorkflow
. It belongs to the Workflows SDK.
This function creates a workflow with the provided name and a constructor function.
The constructor function builds the workflow from steps created by the createStep function.
The returned workflow is an exported workflow of type ReturnWorkflow, meaning it's not executed right away. To execute it,
invoke the exported workflow, then run its run
method.
1import {2 createWorkflow,3 WorkflowResponse4} from "@medusajs/framework/workflows-sdk"5import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"6import {7 createProductStep,8 getProductStep,9} from "./steps"10 11interface WorkflowInput {12 title: string13}14 15const myWorkflow = createWorkflow(16 "my-workflow",17 (input: WorkflowInput) => {18 // Everything here will be executed and resolved later19 // during the execution. Including the data access.20 21 const product = createProductStep(input)22 return new WorkflowResponse(getProductStep(product.id))23 }24)25 26export async function GET(27 req: MedusaRequest,28 res: MedusaResponse29) {30 const { result: product } = await myWorkflow(req.scope)31 .run({32 input: {33 title: "Shirt"34 }35 })36 37 res.json({38 product39 })40}
TData
objectOptionalTResult
objectOptionalTHooks
any[]OptionalnameOrConfig
string | object & TransactionModelOptionscomposer
(input: WorkflowData<TData>) => void | WorkflowResponse<TResult, THooks>run
method in ReturnWorkflow is used.
The function can't be an arrow function or an asynchronus function. It also can't directly manipulate data.
You'll have to use the transform function if you need to directly manipulate data.ReturnWorkflow
ReturnWorkflow<TData, TResult, THooks>run
method.