|
1
|
--- |
|
2
|
sidebar_label: "no-workflow-call-without-container" |
|
3
|
--- |
|
4
|
|
|
5
|
import { Note } from "docs-ui" |
|
6
|
|
|
7
|
export const metadata = { |
|
8
|
title: `no-workflow-call-without-container - ESLint plugin rules`, |
|
9
|
} |
|
10
|
|
|
11
|
# {metadata.title} |
|
12
|
|
|
13
|
This rule requires a workflow to be invoked with the Medusa container, as in `workflow(container).run({ input })`. |
|
14
|
|
|
15
|
## Severity |
|
16
|
|
|
17
|
`warn`. This rule is enabled in the [strict](../../page.mdx#strict) preset. |
|
18
|
|
|
19
|
By default, Medusa projects use the [recommended](../../page.mdx#recommended) preset, which doesn't enable this rule. To use it, switch to the [strict](../../page.mdx#strict) preset. |
|
20
|
|
|
21
|
## What it Targets |
|
22
|
|
|
23
|
This rule targets workflow execution calls anywhere in your project. It reports invoking a workflow with no arguments or accessing its `.run` method directly, without passing the container. |
|
24
|
|
|
25
|
The following code is reported by the rule: |
|
26
|
|
|
27
|
```ts title="src/api/store/custom/route.ts" |
|
28
|
import { myWorkflow } from "../../../workflows/my-workflow" |
|
29
|
|
|
30
|
async function handler() { |
|
31
|
await myWorkflow().run({ input: {} }) |
|
32
|
} |
|
33
|
``` |
|
34
|
|
|
35
|
Instead, pass the container when invoking the workflow: |
|
36
|
|
|
37
|
```ts title="src/api/store/custom/route.ts" |
|
38
|
import { myWorkflow } from "../../../workflows/my-workflow" |
|
39
|
|
|
40
|
async function handler(container) { |
|
41
|
await myWorkflow(container).run({ input: {} }) |
|
42
|
} |
|
43
|
``` |
|
44
|
|
|
45
|
## Why it's Important |
|
46
|
|
|
47
|
A workflow resolves its steps' dependencies from the Medusa container. Invoking the workflow without the container, or calling `.run` directly, bypasses container resolution and the workflow fails to execute correctly. |
|
48
|
|
|
49
|
Learn more in the [Workflows documentation](!docs!/learn/fundamentals/workflows). |
|
50
|
|
|
51
|
## Fixable |
|
52
|
|
|
53
|
This rule isn't auto-fixable. |
|
54
|
|
|
55
|
## Turn it Off |
|
56
|
|
|
57
|
To turn off this rule, set it to `off` in your ESLint configuration: |
|
58
|
|
|
59
|
```ts title="eslint.config.ts" |
|
60
|
import { defineConfig } from "eslint/config" |
|
61
|
import medusa from "@medusajs/eslint-plugin" |
|
62
|
|
|
63
|
export default defineConfig([ |
|
64
|
...medusa.configs.strict, |
|
65
|
{ |
|
66
|
rules: { |
|
67
|
"@medusajs/no-workflow-call-without-container": "off", |
|
68
|
}, |
|
69
|
}, |
|
70
|
]) |
|
71
|
``` |
|
72
|
|
|
73
|
Or disable it for a single line using an inline comment: |
|
74
|
|
|
75
|
```ts |
|
76
|
// eslint-disable-next-line @medusajs/no-workflow-call-without-container |
|
77
|
await myWorkflow().run({ input: {} }) |
|
78
|
``` |