1 ---
2 sidebar_label: "use-query-context-utility"
3 ---
4
5 export const metadata = {
6 title: `use-query-context-utility - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 <Note type="warning">
12
13 This rule has been removed as of Medusa [v2.18.0](https://github.com/medusajs/medusa/releases/tag/v2.18.0) since `QueryContext` can be applied to nested objects, making it difficult to determine its usage in a linting rule.
14
15 </Note>
16
17 This rule requires wrapping `context` arguments to `query.graph` or `query.index` with `QueryContext(...)` from `@medusajs/framework/utils`.
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 all files in your project. It reports a `context` property passed to `query.graph` or `query.index` whose value is a plain object literal instead of a `QueryContext(...)` call.
26
27 The following code is reported by the rule:
28
29 ```ts title="src/api/example.ts"
30 // non-compliant
31 query.graph({
32 entity: "product",
33 fields: ["*"],
34 context: { region_id: "us" },
35 })
36 ```
37
38 Instead, wrap the value with `QueryContext`:
39
40 ```ts title="src/api/example.ts"
41 // compliant
42 import { QueryContext } from "@medusajs/framework/utils"
43
44 query.graph({
45 entity: "product",
46 fields: ["*"],
47 context: QueryContext({ region_id: "us" }),
48 })
49 ```
50
51 ## Why it's Important
52
53 `QueryContext` marks values as context passed to relation resolvers, ensuring Query interprets them correctly. Passing a plain object can lead to context values being treated as regular filters.
54
55 Learn more in the [Query Context documentation](!docs!/learn/fundamentals/query/query-context).
56
57 ## Fixable
58
59 This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically.
60
61 ## Turn it Off
62
63 To turn off this rule, set it to `off` in your ESLint configuration:
64
65 ```ts title="eslint.config.ts"
66 import { defineConfig } from "eslint/config"
67 import medusa from "@medusajs/eslint-plugin"
68
69 export default defineConfig([
70 ...medusa.configs.recommended,
71 {
72 rules: {
73 "@medusajs/use-query-context-utility": "off",
74 },
75 },
76 ])
77 ```
78
79 Or disable it for a single line using an inline comment:
80
81 ```ts
82 // eslint-disable-next-line @medusajs/use-query-context-utility
83 context: { region_id: "us" },
84 ```