Back to Medusa

{metadata.title}

www/apps/resources/app/lint/rules/no-duplicate-step-id-in-workflow/page.mdx

2.17.01.7 KB
Original Source

export const metadata = { title: no-duplicate-step-id-in-workflow - ESLint plugin rules, }

{metadata.title}

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:

ts
import {
  createWorkflow,
  WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"

createWorkflow("hello", () => {
  const products = useQueryGraphStep({
    // ...
  })
  const customers = useQueryGraphStep({
    // ...
  })

  return new WorkflowResponse({ products, customers })
})

Instead, rename the subsequent calls with .config({ name }):

ts
import {
  createWorkflow,
  WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"

createWorkflow("hello", () => {
  const products = useQueryGraphStep({
    // ...
  })
  const customers = useQueryGraphStep({
    // ...
  }).config({
    name: "fetch-customers",
  })

  return new WorkflowResponse({ products, customers })
})

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.