Back to Biomejs

useInputName

src/content/docs/linter/rules/use-input-name.mdx

latest5.5 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.14` - Diagnostic Category: [`lint/nursery/useInputName`](/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/input-name`](https://the-guild.dev/graphql/eslint/rules/input-name)

How to configure

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

Description

Require mutation argument to be always called "input"

Using the same name for all input parameters will make your schemas easier to consume and more predictable.

Examples

Invalid

graphql
type Mutation {
  SetMessage(message: InputMessage): String
}
<pre class="language-text"><code class="language-text">code-block.graphql:2:14 <a href="https://biomejs.dev/linter/rules/use-input-name">lint/nursery/useInputName</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Unexpected input name, expected the input name &quot;message&quot; to be named &quot;input&quot;.</span> <strong>1 │ </strong>type Mutation &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> SetMessage(message: InputMessage): String <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;">^</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>3 │ </strong>&#125; <strong>4 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Using the same name for all input parameters will make your schemas easier to consume and more predictable.</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
type Mutation {
  SetMessage(input: SetMessageInput): String
}

Options

checkInputType

With the option checkInputType on, the input type name requires to be called <mutation name>Input. This can either be "loose" (case-insensitive) or "strict" (case-sensitive). Using the name of the mutation in the input type name will make it easier to find the mutation that the input type belongs to.

Default "off"

json
{
	"linter": {
		"rules": {
			"nursery": {
				"useInputName": {
					"options": {
						"checkInputType": "loose"
					}
				}
			}
		}
	}
}

graphql
type Mutation {
  SetMessage(input: InputMessage): String
}
<pre class="language-text"><code class="language-text"></code></pre>
graphql
type Mutation {
  SetMessage(input: setMessageInput): String
}
graphql
type Mutation {
  SetMessage(input: SetMessageInput): String
}
json
{
	"linter": {
		"rules": {
			"nursery": {
				"useInputName": {
					"options": {
						"checkInputType": "strict"
					}
				}
			}
		}
	}
}

graphql
type Mutation {
  SetMessage(input: InputMessage): String
}
<pre class="language-text"><code class="language-text"></code></pre>
graphql
type Mutation {
  SetMessage(input: setMessageInput): String
}
<pre class="language-text"><code class="language-text"></code></pre>
graphql
type Mutation {
  SetMessage(input: SetMessageInput): String
}
</TabItem> </Tabs>