Back to Biomejs

noDuplicateGraphqlOperationName

src/content/docs/linter/rules/no-duplicate-graphql-operation-name.mdx

latest4.4 KB
Original Source

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

<Tabs> <TabItem label="GraphQL" icon="seti:graphql"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.6` - Diagnostic Category: [`lint/nursery/noDuplicateGraphqlOperationName`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Inspired from [`@graphql-eslint/unique-operation-name`](https://the-guild.dev/graphql/eslint/rules/unique-operation-name)

How to configure

json
{
	"linter": {
		"rules": {
			"nursery": {
				"noDuplicateGraphqlOperationName": "error"
			}
		}
	}
}

Description

Enforce unique operation names across a GraphQL document.

This rule ensures that all GraphQL operations (queries, mutations, subscriptions) have unique names. Using unique operation names is essential for proper identification and reducing confusion.

:::note This rule currently does not work across multiple files. :::

Examples

Invalid

graphql
query user {
  user {
    id
  }
}

query user {
  me {
    id
  }
}
<pre class="language-text"><code class="language-text">code-block.graphql:7:1 <a href="https://biomejs.dev/linter/rules/no-duplicate-graphql-operation-name">lint/nursery/noDuplicateGraphqlOperationName</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Operation named &quot;user&quot; is already defined.</span> <strong>5 │ </strong>&#125; <strong>6 │ </strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>7 │ </strong>query user &#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><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>8 │ </strong> me &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>9 │ </strong> id <strong><span style="color: Tomato;">&gt;</span></strong> <strong>10 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>11 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>12 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">GraphQL operation names must be unique to ensure proper identification.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Rename the operation to have a unique name.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>

Valid

graphql
query user {
  user {
    id
  }
}

query me {
  me {
    id
  }
}
</TabItem> </Tabs>