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.
Severity#
warn. This rule is enabled in the recommended preset.
What it Targets#
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:
Remove the specific top-level fields if you want all of the entity's own fields, since * already selects them:
* in production code, as it can lead to performance issues with large data models. It's better to explicitly list the fields you need.src/workflows/example.ts1const { data } = await query.graph({2 entity: "cart",3 fields: ["*"],4})
Or remove * and list only the fields you need, including any computed fields:
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:
Why it's Important#
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.
Fixable#
This rule isn't auto-fixable.
Turn it Off#
To turn off this rule, set it to off in your ESLint configuration:
Or disable it for a single line using an inline comment: