|
1 |
| -# Enforce names of input parameters and input types |
| 1 | +# `input-name` |
2 | 2 |
|
3 |
| -- Name: `input-name` |
| 3 | +- Category: `Stylistic Issues` |
| 4 | +- Rule name: `@graphql-eslint/input-name` |
4 | 5 | - Requires GraphQL Schema: `false`
|
| 6 | +- Requires GraphQL Operations: `false` |
5 | 7 |
|
| 8 | +Require mutation argument to be always called "input" and input type to be called Mutation name + "Input". |
6 | 9 | Using the same name for all input parameters will make your schemas easier to consume and more predictable. Using the same name as mutation for InputType will make it easier to find mutations that InputType belongs to.
|
7 | 10 |
|
8 |
| -## Rule Details |
| 11 | +## Usage Examples |
9 | 12 |
|
10 |
| -This rule enforces all input parameters to be named `input`, and all InputTypes to use the name of the mutation + `'Input'`. |
11 |
| - |
12 |
| -Examples of **incorrect** code for this rule: |
| 13 | +### Incorrect |
13 | 14 |
|
14 | 15 | ```graphql
|
15 |
| -# eslint @graphql-eslint/input-name: ["error", { checkInputType: true }] |
| 16 | +# eslint @graphql-eslint/input-name: ["error", [{"checkInputType":true}]] |
16 | 17 |
|
17 | 18 | type Mutation {
|
18 | 19 | SetMessage(message: InputMessage): String
|
19 | 20 | }
|
20 | 21 | ```
|
21 | 22 |
|
22 |
| -Examples of **correct** code for this rule: |
| 23 | +### Correct (with checkInputType) |
23 | 24 |
|
24 | 25 | ```graphql
|
25 |
| -# eslint @graphql-eslint/input-name: ["error", { checkInputType: true }] |
| 26 | +# eslint @graphql-eslint/input-name: ["error", [{"checkInputType":true}]] |
26 | 27 |
|
27 | 28 | type Mutation {
|
28 | 29 | SetMessage(input: SetMessageInput): String
|
29 | 30 | }
|
30 | 31 | ```
|
31 | 32 |
|
| 33 | +### Correct (without checkInputType) |
| 34 | + |
32 | 35 | ```graphql
|
33 |
| -# eslint @graphql-eslint/input-name: ["error", { checkInputType: false }] |
| 36 | +# eslint @graphql-eslint/input-name: ["error", [{"checkInputType":false}]] |
34 | 37 |
|
35 | 38 | type Mutation {
|
36 | 39 | SetMessage(input: AnyInputTypeName): String
|
37 | 40 | }
|
38 | 41 | ```
|
39 | 42 |
|
40 |
| -## Configuration |
| 43 | +## Config Schema |
| 44 | + |
| 45 | +### (array) |
| 46 | + |
| 47 | +The schema defines an array with all elements of the type `object`. |
| 48 | + |
| 49 | +The array object has the following properties: |
| 50 | + |
| 51 | +#### `checkInputType` (boolean) |
41 | 52 |
|
42 |
| -This rule accepts one option `checkInputType`. If `true` (default) it will verify that the name of the input type matches name of the mutation + 'Input'. If `false` it will not check InputType name. |
| 53 | +Default: `"true"` |
0 commit comments