Back to Biomejs

useLoneAnonymousOperation

src/content/docs/linter/rules/use-lone-anonymous-operation.mdx

latest3.8 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.12` - Diagnostic Category: [`lint/nursery/useLoneAnonymousOperation`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@graphql-eslint/lone-anonymous-operation`](https://the-guild.dev/graphql/eslint/rules/lone-anonymous-operation)

How to configure

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

Description

Disallow anonymous operations when more than one operation specified in document.

A GraphQL document that contains an anonymous operation (the query short-hand) is only valid if it contains only that one operation definition.

Examples

Invalid

graphql
query {
  fieldA
}

query B {
  fieldB
}
<pre class="language-text"><code class="language-text">code-block.graphql:1:1 <a href="https://biomejs.dev/linter/rules/use-lone-anonymous-operation">lint/nursery/useLoneAnonymousOperation</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Document contains an anonymous operation while defining more than one operation. This anonymous operation must be the only defined operation in this document or turned into a named operation.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>query &#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;">&gt;</span></strong> <strong>2 │ </strong> fieldA <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>4 │ </strong> <strong>5 │ </strong>query B &#123; <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">A GraphQL document that contains an anonymous operation (the query short-hand) is only valid if it contains only that one operation definition.</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 A {
  fieldA
}

query B {
  fieldB
}
</TabItem> </Tabs>