|
1
|
--- |
|
2
|
sidebar_label: "no-duplicate-step-id-in-workflow" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `no-duplicate-step-id-in-workflow - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule disallows invoking the same step more than once in a `createWorkflow` constructor without renaming the subsequent calls with `.config({ name })`. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets files in your project's `src/workflows` directory. It reports a step invoked more than once in a workflow's constructor when the duplicates aren't renamed. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/workflows/example.ts" |
|
24
|
import { |
|
25
|
createWorkflow, |
|
26
|
WorkflowResponse, |
|
27
|
} from "@medusajs/framework/workflows-sdk" |
|
28
|
|
|
29
|
createWorkflow("hello", () => { |
|
30
|
const products = useQueryGraphStep({ |
|
31
|
// ... |
|
32
|
}) |
|
33
|
const customers = useQueryGraphStep({ |
|
34
|
// ... |
|
35
|
}) |
|
36
|
|
|
37
|
return new WorkflowResponse({ products, customers }) |
|
38
|
}) |
|
39
|
``` |
|
40
|
|
|
41
|
Instead, rename the subsequent calls with `.config({ name })`: |
|
42
|
|
|
43
|
```ts title="src/workflows/example.ts" |
|
44
|
import { |
|
45
|
createWorkflow, |
|
46
|
WorkflowResponse, |
|
47
|
} from "@medusajs/framework/workflows-sdk" |
|
48
|
|
|
49
|
createWorkflow("hello", () => { |
|
50
|
const products = useQueryGraphStep({ |
|
51
|
// ... |
|
52
|
}) |
|
53
|
const customers = useQueryGraphStep({ |
|
54
|
// ... |
|
55
|
}).config({ |
|
56
|
name: "fetch-customers", |
|
57
|
}) |
|
58
|
|
|
59
|
return new WorkflowResponse({ products, customers }) |
|
60
|
}) |
|
61
|
``` |
|
62
|
|
|
63
|
## Why it's Important |
|
64
|
|
|
65
|
Steps registered with the same ID throw an error at runtime. Giving each step a unique ID ensures the workflow runs correctly. |
|
66
|
|
|
67
|
Learn more in the [Multiple Step Usages in Workflows documentation](!docs!/learn/fundamentals/workflows/multiple-step-usage). |
|
68
|
|
|
69
|
## Fixable |
|
70
|
|
|
71
|
This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically. |