1 ---
2 sidebar_label: "no-wildcard-with-specific-fields"
3 ---
4
5 export const metadata = {
6 title: `no-wildcard-with-specific-fields - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 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.
12
13 <Note>
14
15 This rule is available since Medusa [v2.18.0](https://github.com/medusajs/medusa/releases/tag/v2.18.0).
16
17 </Note>
18
19 ## Severity
20
21 `warn`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
22
23 ## What it Targets
24
25 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.
26
27 The following code is reported by the rule:
28
29 ```ts title="src/workflows/example.ts"
30 const { data } = await query.graph({
31 entity: "cart",
32 fields: ["*", "total"],
33 })
34 ```
35
36 Remove the specific top-level fields if you want all of the entity's own fields, since `*` already selects them:
37
38 <Note title="Important">
39
40 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.
41
42 </Note>
43
44 ```ts title="src/workflows/example.ts"
45 const { data } = await query.graph({
46 entity: "cart",
47 fields: ["*"],
48 })
49 ```
50
51 Or remove `*` and list only the fields you need, including any computed fields:
52
53 ```ts title="src/workflows/example.ts"
54 const { data } = await query.graph({
55 entity: "cart",
56 fields: ["id", "total", "subtotal"],
57 })
58 ```
59
60 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:
61
62 ```ts title="src/workflows/example.ts"
63 const { data } = await query.graph({
64 entity: "cart",
65 fields: ["*", "items.*", "items.title"],
66 })
67 ```
68
69 ## Why it's Important
70
71 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.
72
73 Listing only the fields you need, without `*`, is the safest approach when you require computed or non-default fields.
74
75 ## Fixable
76
77 This rule isn't auto-fixable.
78
79 ## Turn it Off
80
81 To turn off this rule, set it to `off` in your ESLint configuration:
82
83 ```ts title="eslint.config.ts"
84 import { defineConfig } from "eslint/config"
85 import medusa from "@medusajs/eslint-plugin"
86
87 export default defineConfig([
88 ...medusa.configs.recommended,
89 {
90 rules: {
91 "@medusajs/no-wildcard-with-specific-fields": "off",
92 },
93 },
94 ])
95 ```
96
97 Or disable it for a single line using an inline comment:
98
99 ```ts
100 // eslint-disable-next-line @medusajs/no-wildcard-with-specific-fields
101 const { data } = await query.graph({ entity: "cart", fields: ["*", "total"] })
102 ```