docs: added workflow hooks docs + changed workflow response (#8364)

* docs: added workflow hooks docs + changed workflow response

* Update page.mdx
This commit is contained in:
Shahed Nasser
2024-07-31 17:01:33 +03:00
committed by GitHub
parent 27837b8833
commit 6f973d9f2b
29 changed files with 321 additions and 167 deletions
+11 -7
View File
@@ -56,6 +56,7 @@ Next, add the following to the same file to create the workflow using the `creat
import {
// other imports...
createWorkflow,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
// ...
@@ -67,9 +68,9 @@ const myWorkflow = createWorkflow(
// to pass input
const str2 = step2(input)
return {
return new WorkflowResponse({
message: str1,
}
})
}
)
@@ -78,6 +79,8 @@ export default myWorkflow
This creates a `hello-world` workflow. When you create a workflow, its constructed but not executed yet.
The workflow must return an instance of `WorkflowResponse`, whose first parameter is returned to workflow executors.
### 3. Execute the Workflow
You can execute a workflow from different resources within Medusa.
@@ -223,19 +226,20 @@ Each step in the workflow receives as a second parameter a `context` object. The
For example:
export const highlights = [
["11", "resolve", "Resolve the Product Module's main service."],
["12", "resolve", "Resolve the Product Module's main service."],
[
"11",
"12",
"ModuleRegistrationName.PRODUCT",
"The resource registration name imported from `@medusajs/modules-sdk`.",
],
]
```ts title="src/workflows/product-count.ts" highlights={highlights} collapsibleLines="1-12" expandButtonLabel="Show Imports"
```ts title="src/workflows/product-count.ts" highlights={highlights} collapsibleLines="1-9" expandButtonLabel="Show Imports"
import {
createStep,
StepResponse,
createWorkflow,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
@@ -254,9 +258,9 @@ const myWorkflow = createWorkflow(
function () {
const count = step1()
return {
return new WorkflowResponse({
count,
}
})
}
)