www/apps/resources/app/lint/rules/no-wildcard-with-specific-fields/page.mdx
export const metadata = {
title: no-wildcard-with-specific-fields - ESLint plugin rules,
}
This rule disallows combining the * wildcard with specific top-level fields in a query.graph or useQueryGraphStep field selection, because * silently drops those specific field selections.
This rule is available since Medusa v2.18.0.
</Note>warn. This rule is enabled in the recommended preset.
This rule targets usages of query.graph and useQueryGraphStep anywhere in your project. It reports a fields array that contains both the * wildcard and one or more specific top-level fields.
The following code is reported by the rule:
const { data } = await query.graph({
entity: "cart",
fields: ["*", "total"],
})
Remove the specific top-level fields if you want all of the entity's own fields, since * already selects them:
It's highly discouraged to use * in production code, as it can lead to performance issues with large data models. It's better to explicitly list the fields you need.
const { data } = await query.graph({
entity: "cart",
fields: ["*"],
})
Or remove * and list only the fields you need, including any computed fields:
const { data } = await query.graph({
entity: "cart",
fields: ["id", "total", "subtotal"],
})
Relation selections such as items.* or items.title are not affected by this rule. They are scoped to a relation and are kept even when * is present, so the following is valid:
const { data } = await query.graph({
entity: "cart",
fields: ["*", "items.*", "items.title"],
})
The * wildcard selects all of an entity's own scalar fields. It does not include computed fields such as total or subtotal. When you combine * with a specific top-level field like "total", the specific field is silently ignored and the response won't contain it.
Listing only the fields you need, without *, is the safest approach when you require computed or non-default fields.
This rule isn't auto-fixable.
To turn off this rule, set it to off in your ESLint configuration:
import { defineConfig } from "eslint/config"
import medusa from "@medusajs/eslint-plugin"
export default defineConfig([
...medusa.configs.recommended,
{
rules: {
"@medusajs/no-wildcard-with-specific-fields": "off",
},
},
])
Or disable it for a single line using an inline comment:
// eslint-disable-next-line @medusajs/no-wildcard-with-specific-fields
const { data } = await query.graph({ entity: "cart", fields: ["*", "total"] })