no-duplicate-step-id-in-workflow - ESLint plugin rules
This rule disallows invoking the same step more than once in a createWorkflow constructor without renaming the subsequent calls with .config({ name }).
Severity#
error. This rule is enabled in the recommended preset.
What it Targets#
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.
The following code is reported by the rule:
1import {2 createWorkflow,3 WorkflowResponse,4} from "@medusajs/framework/workflows-sdk"5 6createWorkflow("hello", () => {7 const products = useQueryGraphStep({8 // ...9 })10 const customers = useQueryGraphStep({11 // ...12 })13 14 return new WorkflowResponse({ products, customers })15})
Instead, rename the subsequent calls with .config({ name }):
1import {2 createWorkflow,3 WorkflowResponse,4} from "@medusajs/framework/workflows-sdk"5 6createWorkflow("hello", () => {7 const products = useQueryGraphStep({8 // ...9 })10 const customers = useQueryGraphStep({11 // ...12 }).config({13 name: "fetch-customers",14 })15 16 return new WorkflowResponse({ products, customers })17})
Why it's Important#
Steps registered with the same ID throw an error at runtime. Giving each step a unique ID ensures the workflow runs correctly.
Learn more in the Multiple Step Usages in Workflows documentation.
Fixable#
This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.