Back to Biomejs

noDuplicateFields

src/content/docs/linter/rules/no-duplicate-fields.mdx

latest5.7 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="GraphQL" icon="seti:graphql"> ## Summary - Rule available since: `v1.9.0` - Diagnostic Category: [`lint/suspicious/noDuplicateFields`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@graphql-eslint/no-duplicate-fields`](https://the-guild.dev/graphql/eslint/rules/no-duplicate-fields)

How to configure

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noDuplicateFields": "error"
			}
		}
	}
}

Description

No duplicated fields in GraphQL operations.

Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.

Examples

Invalid

graphql
query {
  users {
    id
    name
    email
    name
  }
}
<pre class="language-text"><code class="language-text">code-block.graphql:6:5 <a href="https://biomejs.dev/linter/rules/no-duplicate-fields">lint/suspicious/noDuplicateFields</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Field &#96;name&#96; defined multiple times.</span> <strong>4 │ </strong> name <strong>5 │ </strong> email <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> name <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>7 │ </strong> &#125; <strong>8 │ </strong>&#125; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Remove the duplicated field.</span> </code></pre>
graphql
query {
  users(
    first: 100,
    after: 10,
    filter: "test",
    first: 50
  ) {
    id
  }
}
<pre class="language-text"><code class="language-text">code-block.graphql:6:5 <a href="https://biomejs.dev/linter/rules/no-duplicate-fields">lint/suspicious/noDuplicateFields</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Argument &#96;first&#96; defined multiple times.</span> <strong>4 │ </strong> after: 10, <strong>5 │ </strong> filter: &quot;test&quot;, <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> first: 50 <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>7 │ </strong> ) &#123; <strong>8 │ </strong> id <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Remove the duplicated argument.</span> </code></pre>
graphql
query ($v: String, $t: String, $v: String) {
  id
}
<pre class="language-text"><code class="language-text">code-block.graphql:1:32 <a href="https://biomejs.dev/linter/rules/no-duplicate-fields">lint/suspicious/noDuplicateFields</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Variable &#96;v&#96; defined multiple times.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>query ($v: String, $t: String, $v: String) &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> id <strong>3 │ </strong>&#125; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Remove the duplicated variable.</span> </code></pre>

Valid

graphql
query {
  users {
    id
    name
    email
  }
}
</TabItem> </Tabs>