|
| 1 | +# `alphabetize` |
| 2 | + |
| 3 | +- Category: `Best Practices` |
| 4 | +- Rule name: `@graphql-eslint/alphabetize` |
| 5 | +- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema) |
| 6 | +- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations) |
| 7 | + |
| 8 | +Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more. |
| 9 | + |
| 10 | +## Usage Examples |
| 11 | + |
| 12 | +### Incorrect |
| 13 | + |
| 14 | +```graphql |
| 15 | +# eslint @graphql-eslint/alphabetize: ['error', { fields: ['ObjectTypeDefinition'] }] |
| 16 | + |
| 17 | +type User { |
| 18 | + password: String |
| 19 | + firstName: String! # should be before "password" |
| 20 | + age: Int # should be before "firstName" |
| 21 | + lastName: String! |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +### Correct |
| 26 | + |
| 27 | +```graphql |
| 28 | +# eslint @graphql-eslint/alphabetize: ['error', { fields: ['ObjectTypeDefinition'] }] |
| 29 | + |
| 30 | +type User { |
| 31 | + age: Int |
| 32 | + firstName: String! |
| 33 | + lastName: String! |
| 34 | + password: String |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +### Incorrect |
| 39 | + |
| 40 | +```graphql |
| 41 | +# eslint @graphql-eslint/alphabetize: ['error', { values: ['EnumTypeDefinition'] }] |
| 42 | + |
| 43 | +enum Role { |
| 44 | + SUPER_ADMIN |
| 45 | + ADMIN # should be before "SUPER_ADMIN" |
| 46 | + USER |
| 47 | + GOD # should be before "USER" |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +### Correct |
| 52 | + |
| 53 | +```graphql |
| 54 | +# eslint @graphql-eslint/alphabetize: ['error', { values: ['EnumTypeDefinition'] }] |
| 55 | + |
| 56 | +enum Role { |
| 57 | + ADMIN |
| 58 | + GOD |
| 59 | + SUPER_ADMIN |
| 60 | + USER |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Incorrect |
| 65 | + |
| 66 | +```graphql |
| 67 | +# eslint @graphql-eslint/alphabetize: ['error', { selections: ['OperationDefinition'] }] |
| 68 | + |
| 69 | +query { |
| 70 | + me { |
| 71 | + firstName |
| 72 | + lastName |
| 73 | + email # should be before "lastName" |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### Correct |
| 79 | + |
| 80 | +```graphql |
| 81 | +# eslint @graphql-eslint/alphabetize: ['error', { selections: ['OperationDefinition'] }] |
| 82 | + |
| 83 | +query { |
| 84 | + me { |
| 85 | + email |
| 86 | + firstName |
| 87 | + lastName |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +## Config Schema |
| 93 | + |
| 94 | +The schema defines the following properties: |
| 95 | + |
| 96 | +### `fields` (array) |
| 97 | + |
| 98 | +Fields of `type`, `interface`, and `input`. |
| 99 | + |
| 100 | +The elements of the array must contain the following properties: |
| 101 | + |
| 102 | +- `ObjectTypeDefinition` |
| 103 | +- `InterfaceTypeDefinition` |
| 104 | +- `InputObjectTypeDefinition` |
| 105 | + |
| 106 | +### `values` (array) |
| 107 | + |
| 108 | +Values of `enum`. |
| 109 | + |
| 110 | +The elements of the array must contain the following properties: |
| 111 | + |
| 112 | +- `EnumTypeDefinition` |
| 113 | + |
| 114 | +### `selections` (array) |
| 115 | + |
| 116 | +Selections of operations (`query`, `mutation` and `subscription`) and `fragment`. |
| 117 | + |
| 118 | +The elements of the array must contain the following properties: |
| 119 | + |
| 120 | +- `OperationDefinition` |
| 121 | +- `FragmentDefinition` |
| 122 | + |
| 123 | +### `variables` (array) |
| 124 | + |
| 125 | +Variables of operations (`query`, `mutation` and `subscription`). |
| 126 | + |
| 127 | +The elements of the array must contain the following properties: |
| 128 | + |
| 129 | +- `OperationDefinition` |
| 130 | + |
| 131 | +### `arguments` (array) |
| 132 | + |
| 133 | +Arguments of fields and directives. |
| 134 | + |
| 135 | +The elements of the array must contain the following properties: |
| 136 | + |
| 137 | +- `FieldDefinition` |
| 138 | +- `Field` |
| 139 | +- `DirectiveDefinition` |
| 140 | +- `Directive` |
0 commit comments