@graphql-eslint/eslint-plugin 3.14.0-alpha-20221221142641-4e1a924 → 3.14.0-alpha-20221222124206-b82954b
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +309 -0
- package/cjs/cache.js +30 -0
- package/cjs/configs/base.js +7 -0
- package/cjs/configs/index.js +16 -0
- package/cjs/configs/operations-all.js +31 -0
- package/cjs/configs/operations-recommended.js +56 -0
- package/cjs/configs/relay.js +12 -0
- package/cjs/configs/schema-all.js +23 -0
- package/cjs/configs/schema-recommended.js +52 -0
- package/cjs/documents.js +149 -0
- package/cjs/estree-converter/converter.js +62 -0
- package/cjs/estree-converter/index.js +6 -0
- package/cjs/estree-converter/types.js +2 -0
- package/cjs/estree-converter/utils.js +109 -0
- package/cjs/graphql-config.js +55 -0
- package/cjs/index.js +17 -0
- package/cjs/parser.js +61 -0
- package/cjs/processor.js +78 -0
- package/cjs/rules/alphabetize.js +348 -0
- package/cjs/rules/description-style.js +78 -0
- package/cjs/rules/graphql-js-validation.js +499 -0
- package/cjs/rules/index.js +68 -0
- package/cjs/rules/input-name.js +136 -0
- package/cjs/rules/lone-executable-definition.js +88 -0
- package/cjs/rules/match-document-filename.js +235 -0
- package/cjs/rules/naming-convention.js +310 -0
- package/cjs/rules/no-anonymous-operations.js +67 -0
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +61 -0
- package/cjs/rules/no-deprecated.js +124 -0
- package/cjs/rules/no-duplicate-fields.js +112 -0
- package/cjs/rules/no-hashtag-description.js +89 -0
- package/cjs/rules/no-root-type.js +86 -0
- package/cjs/rules/no-scalar-result-type-on-mutation.js +66 -0
- package/cjs/rules/no-typename-prefix.js +65 -0
- package/cjs/rules/no-unreachable-types.js +158 -0
- package/cjs/rules/no-unused-fields.js +130 -0
- package/cjs/rules/relay-arguments.js +121 -0
- package/cjs/rules/relay-connection-types.js +107 -0
- package/cjs/rules/relay-edge-types.js +189 -0
- package/cjs/rules/relay-page-info.js +100 -0
- package/cjs/rules/require-deprecation-date.js +123 -0
- package/cjs/rules/require-deprecation-reason.js +56 -0
- package/cjs/rules/require-description.js +193 -0
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +72 -0
- package/cjs/rules/require-id-when-available.js +199 -0
- package/cjs/rules/selection-set-depth.js +135 -0
- package/cjs/rules/strict-id-in-types.js +162 -0
- package/cjs/rules/unique-fragment-name.js +90 -0
- package/cjs/rules/unique-operation-name.js +65 -0
- package/cjs/schema.js +42 -0
- package/cjs/testkit.js +183 -0
- package/cjs/types.js +2 -0
- package/cjs/utils.js +96 -0
- package/docs/README.md +82 -0
- package/docs/custom-rules.md +184 -0
- package/docs/deprecated-rules.md +24 -0
- package/docs/parser-options.md +95 -0
- package/docs/parser.md +67 -0
- package/docs/rules/alphabetize.md +194 -0
- package/docs/rules/description-style.md +57 -0
- package/docs/rules/executable-definitions.md +20 -0
- package/docs/rules/fields-on-correct-type.md +23 -0
- package/docs/rules/fragments-on-composite-type.md +20 -0
- package/docs/rules/input-name.md +80 -0
- package/docs/rules/known-argument-names.md +23 -0
- package/docs/rules/known-directives.md +48 -0
- package/docs/rules/known-fragment-names.md +72 -0
- package/docs/rules/known-type-names.md +24 -0
- package/docs/rules/lone-anonymous-operation.md +20 -0
- package/docs/rules/lone-executable-definition.md +59 -0
- package/docs/rules/lone-schema-definition.md +19 -0
- package/docs/rules/match-document-filename.md +181 -0
- package/docs/rules/naming-convention.md +320 -0
- package/docs/rules/no-anonymous-operations.md +43 -0
- package/docs/rules/no-case-insensitive-enum-values-duplicates.md +46 -0
- package/docs/rules/no-deprecated.md +88 -0
- package/docs/rules/no-duplicate-fields.md +69 -0
- package/docs/rules/no-fragment-cycles.md +19 -0
- package/docs/rules/no-hashtag-description.md +62 -0
- package/docs/rules/no-root-type.md +55 -0
- package/docs/rules/no-scalar-result-type-on-mutation.md +39 -0
- package/docs/rules/no-typename-prefix.md +42 -0
- package/docs/rules/no-undefined-variables.md +20 -0
- package/docs/rules/no-unreachable-types.md +52 -0
- package/docs/rules/no-unused-fields.md +64 -0
- package/docs/rules/no-unused-fragments.md +20 -0
- package/docs/rules/no-unused-variables.md +20 -0
- package/docs/rules/one-field-subscriptions.md +19 -0
- package/docs/rules/overlapping-fields-can-be-merged.md +20 -0
- package/docs/rules/possible-fragment-spread.md +21 -0
- package/docs/rules/possible-type-extension.md +19 -0
- package/docs/rules/provided-required-arguments.md +21 -0
- package/docs/rules/relay-arguments.md +59 -0
- package/docs/rules/relay-connection-types.md +43 -0
- package/docs/rules/relay-edge-types.md +60 -0
- package/docs/rules/relay-page-info.md +34 -0
- package/docs/rules/require-deprecation-date.md +59 -0
- package/docs/rules/require-deprecation-reason.md +49 -0
- package/docs/rules/require-description.md +147 -0
- package/docs/rules/require-field-of-type-query-in-mutation-result.md +50 -0
- package/docs/rules/require-id-when-available.md +91 -0
- package/docs/rules/scalar-leafs.md +23 -0
- package/docs/rules/selection-set-depth.md +86 -0
- package/docs/rules/strict-id-in-types.md +129 -0
- package/docs/rules/unique-argument-names.md +19 -0
- package/docs/rules/unique-directive-names-per-location.md +21 -0
- package/docs/rules/unique-directive-names.md +19 -0
- package/docs/rules/unique-enum-value-names.md +16 -0
- package/docs/rules/unique-field-definition-names.md +19 -0
- package/docs/rules/unique-fragment-name.md +52 -0
- package/docs/rules/unique-input-field-names.md +19 -0
- package/docs/rules/unique-operation-name.md +56 -0
- package/docs/rules/unique-operation-types.md +19 -0
- package/docs/rules/unique-type-names.md +19 -0
- package/docs/rules/unique-variable-names.md +19 -0
- package/docs/rules/value-literals-of-correct-type.md +22 -0
- package/docs/rules/variables-are-input-types.md +20 -0
- package/docs/rules/variables-in-allowed-position.md +19 -0
- package/package.json +8 -11
- package/{cache.d.ts → typings/cache.d.cts} +0 -0
- package/typings/cache.d.ts +10 -0
- package/typings/configs/base.d.cts +5 -0
- package/typings/configs/base.d.ts +5 -0
- package/typings/configs/index.d.cts +139 -0
- package/typings/configs/index.d.ts +139 -0
- package/typings/configs/operations-all.d.cts +20 -0
- package/typings/configs/operations-all.d.ts +20 -0
- package/typings/configs/operations-recommended.d.cts +50 -0
- package/typings/configs/operations-recommended.d.ts +50 -0
- package/typings/configs/relay.d.cts +10 -0
- package/typings/configs/relay.d.ts +10 -0
- package/typings/configs/schema-all.d.cts +15 -0
- package/typings/configs/schema-all.d.ts +15 -0
- package/typings/configs/schema-recommended.d.cts +47 -0
- package/typings/configs/schema-recommended.d.ts +47 -0
- package/{documents.d.ts → typings/documents.d.cts} +0 -0
- package/typings/documents.d.ts +21 -0
- package/{estree-converter/converter.d.ts → typings/estree-converter/converter.d.cts} +0 -0
- package/typings/estree-converter/converter.d.ts +3 -0
- package/{estree-converter/index.d.ts → typings/estree-converter/index.d.cts} +0 -0
- package/typings/estree-converter/index.d.ts +3 -0
- package/{estree-converter/types.d.ts → typings/estree-converter/types.d.cts} +0 -0
- package/typings/estree-converter/types.d.ts +40 -0
- package/{estree-converter/utils.d.ts → typings/estree-converter/utils.d.cts} +0 -0
- package/typings/estree-converter/utils.d.ts +13 -0
- package/{graphql-config.d.ts → typings/graphql-config.d.cts} +0 -0
- package/typings/graphql-config.d.ts +4 -0
- package/typings/index.d.cts +9 -0
- package/{index.d.ts → typings/index.d.ts} +1 -5
- package/{parser.d.ts → typings/parser.d.cts} +0 -0
- package/typings/parser.d.ts +2 -0
- package/{processor.d.ts → typings/processor.d.cts} +0 -0
- package/typings/processor.d.ts +6 -0
- package/{rules/alphabetize.d.ts → typings/rules/alphabetize.d.cts} +0 -0
- package/typings/rules/alphabetize.d.ts +76 -0
- package/{rules/description-style.d.ts → typings/rules/description-style.d.cts} +0 -0
- package/typings/rules/description-style.d.ts +20 -0
- package/{rules/graphql-js-validation.d.ts → typings/rules/graphql-js-validation.d.cts} +0 -0
- package/typings/rules/graphql-js-validation.d.ts +2 -0
- package/{rules/index.d.ts → typings/rules/index.d.cts} +0 -0
- package/typings/rules/index.d.ts +104 -0
- package/{rules/input-name.d.ts → typings/rules/input-name.d.cts} +0 -0
- package/typings/rules/input-name.d.ts +35 -0
- package/{rules/lone-executable-definition.d.ts → typings/rules/lone-executable-definition.d.cts} +0 -0
- package/typings/rules/lone-executable-definition.d.ts +26 -0
- package/{rules/match-document-filename.d.ts → typings/rules/match-document-filename.d.cts} +0 -0
- package/typings/rules/match-document-filename.d.ts +72 -0
- package/{rules/naming-convention.d.ts → typings/rules/naming-convention.d.cts} +0 -0
- package/typings/rules/naming-convention.d.ts +83 -0
- package/{rules/no-anonymous-operations.d.ts → typings/rules/no-anonymous-operations.d.cts} +0 -0
- package/{rules/no-case-insensitive-enum-values-duplicates.d.ts → typings/rules/no-anonymous-operations.d.ts} +0 -0
- package/{rules/no-hashtag-description.d.ts → typings/rules/no-case-insensitive-enum-values-duplicates.d.cts} +0 -0
- package/{rules/no-scalar-result-type-on-mutation.d.ts → typings/rules/no-case-insensitive-enum-values-duplicates.d.ts} +0 -0
- package/{rules/no-deprecated.d.ts → typings/rules/no-deprecated.d.cts} +0 -0
- package/typings/rules/no-deprecated.d.ts +2 -0
- package/{rules/no-duplicate-fields.d.ts → typings/rules/no-duplicate-fields.d.cts} +0 -0
- package/{rules/relay-page-info.d.ts → typings/rules/no-duplicate-fields.d.ts} +0 -0
- package/{rules/no-typename-prefix.d.ts → typings/rules/no-hashtag-description.d.cts} +0 -0
- package/{rules/no-unreachable-types.d.ts → typings/rules/no-hashtag-description.d.ts} +0 -0
- package/{rules/no-root-type.d.ts → typings/rules/no-root-type.d.cts} +0 -0
- package/typings/rules/no-root-type.d.ts +25 -0
- package/{rules/no-unused-fields.d.ts → typings/rules/no-scalar-result-type-on-mutation.d.cts} +0 -0
- package/{rules/unique-operation-name.d.ts → typings/rules/no-scalar-result-type-on-mutation.d.ts} +0 -0
- package/typings/rules/no-typename-prefix.d.cts +2 -0
- package/typings/rules/no-typename-prefix.d.ts +2 -0
- package/typings/rules/no-unreachable-types.d.cts +2 -0
- package/typings/rules/no-unreachable-types.d.ts +2 -0
- package/typings/rules/no-unused-fields.d.cts +2 -0
- package/typings/rules/no-unused-fields.d.ts +2 -0
- package/{rules/relay-arguments.d.ts → typings/rules/relay-arguments.d.cts} +0 -0
- package/typings/rules/relay-arguments.d.ts +21 -0
- package/{rules/relay-connection-types.d.ts → typings/rules/relay-connection-types.d.cts} +0 -0
- package/typings/rules/relay-connection-types.d.ts +4 -0
- package/{rules/relay-edge-types.d.ts → typings/rules/relay-edge-types.d.cts} +0 -0
- package/typings/rules/relay-edge-types.d.ts +31 -0
- package/{rules/require-deprecation-reason.d.ts → typings/rules/relay-page-info.d.cts} +0 -0
- package/{rules/require-field-of-type-query-in-mutation-result.d.ts → typings/rules/relay-page-info.d.ts} +0 -0
- package/{rules/require-deprecation-date.d.ts → typings/rules/require-deprecation-date.d.cts} +0 -0
- package/typings/rules/require-deprecation-date.d.ts +18 -0
- package/typings/rules/require-deprecation-reason.d.cts +2 -0
- package/typings/rules/require-deprecation-reason.d.ts +2 -0
- package/{rules/require-description.d.ts → typings/rules/require-description.d.cts} +0 -0
- package/typings/rules/require-description.d.ts +14 -0
- package/typings/rules/require-field-of-type-query-in-mutation-result.d.cts +2 -0
- package/typings/rules/require-field-of-type-query-in-mutation-result.d.ts +2 -0
- package/{rules/require-id-when-available.d.ts → typings/rules/require-id-when-available.d.cts} +0 -0
- package/typings/rules/require-id-when-available.d.ts +36 -0
- package/{rules/selection-set-depth.d.ts → typings/rules/selection-set-depth.d.cts} +0 -0
- package/typings/rules/selection-set-depth.d.ts +28 -0
- package/{rules/strict-id-in-types.d.ts → typings/rules/strict-id-in-types.d.cts} +0 -0
- package/typings/rules/strict-id-in-types.d.ts +57 -0
- package/{rules/unique-fragment-name.d.ts → typings/rules/unique-fragment-name.d.cts} +0 -0
- package/typings/rules/unique-fragment-name.d.ts +5 -0
- package/typings/rules/unique-operation-name.d.cts +2 -0
- package/typings/rules/unique-operation-name.d.ts +2 -0
- package/{schema.d.ts → typings/schema.d.cts} +0 -0
- package/typings/schema.d.ts +3 -0
- package/{testkit.d.ts → typings/testkit.d.cts} +0 -0
- package/typings/testkit.d.ts +27 -0
- package/{types.d.ts → typings/types.d.cts} +0 -0
- package/typings/types.d.ts +81 -0
- package/{utils.d.ts → typings/utils.d.cts} +0 -0
- package/typings/utils.d.ts +34 -0
- package/configs/base.json +0 -4
- package/configs/operations-all.json +0 -25
- package/configs/operations-recommended.json +0 -50
- package/configs/relay.json +0 -9
- package/configs/schema-all.json +0 -17
- package/configs/schema-recommended.json +0 -49
- package/index.js +0 -4995
- package/index.mjs +0 -4983
@@ -0,0 +1,147 @@
|
|
1
|
+
# `require-description`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
- Category: `Schema`
|
7
|
+
- Rule name: `@graphql-eslint/require-description`
|
8
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `false`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
Enforce descriptions in type definitions and operations.
|
13
|
+
|
14
|
+
## Usage Examples
|
15
|
+
|
16
|
+
### Incorrect
|
17
|
+
|
18
|
+
```graphql
|
19
|
+
# eslint @graphql-eslint/require-description: ['error', { types: true, FieldDefinition: true }]
|
20
|
+
|
21
|
+
type someTypeName {
|
22
|
+
name: String
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
### Correct
|
27
|
+
|
28
|
+
```graphql
|
29
|
+
# eslint @graphql-eslint/require-description: ['error', { types: true, FieldDefinition: true }]
|
30
|
+
|
31
|
+
"""
|
32
|
+
Some type description
|
33
|
+
"""
|
34
|
+
type someTypeName {
|
35
|
+
"""
|
36
|
+
Name description
|
37
|
+
"""
|
38
|
+
name: String
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
### Correct
|
43
|
+
|
44
|
+
```graphql
|
45
|
+
# eslint @graphql-eslint/require-description: ['error', { OperationDefinition: true }]
|
46
|
+
|
47
|
+
# Create a new user
|
48
|
+
mutation createUser {
|
49
|
+
# ...
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
### Correct
|
54
|
+
|
55
|
+
```graphql
|
56
|
+
# eslint @graphql-eslint/require-description: ['error', { rootField: true }]
|
57
|
+
|
58
|
+
type Mutation {
|
59
|
+
"Create a new user"
|
60
|
+
createUser: User
|
61
|
+
}
|
62
|
+
|
63
|
+
type User {
|
64
|
+
name: String
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
## Config Schema
|
69
|
+
|
70
|
+
The schema defines the following properties:
|
71
|
+
|
72
|
+
### `types` (boolean)
|
73
|
+
|
74
|
+
Includes:
|
75
|
+
|
76
|
+
- `ObjectTypeDefinition`
|
77
|
+
- `InterfaceTypeDefinition`
|
78
|
+
- `EnumTypeDefinition`
|
79
|
+
- `ScalarTypeDefinition`
|
80
|
+
- `InputObjectTypeDefinition`
|
81
|
+
- `UnionTypeDefinition`
|
82
|
+
|
83
|
+
### `rootField` (boolean)
|
84
|
+
|
85
|
+
Definitions within `Query`, `Mutation`, and `Subscription` root types.
|
86
|
+
|
87
|
+
### `DirectiveDefinition` (boolean)
|
88
|
+
|
89
|
+
Read more about this kind on
|
90
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#DirectiveDefinition).
|
91
|
+
|
92
|
+
### `EnumTypeDefinition` (boolean)
|
93
|
+
|
94
|
+
Read more about this kind on
|
95
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#EnumTypeDefinition).
|
96
|
+
|
97
|
+
### `EnumValueDefinition` (boolean)
|
98
|
+
|
99
|
+
Read more about this kind on
|
100
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#EnumValueDefinition).
|
101
|
+
|
102
|
+
### `FieldDefinition` (boolean)
|
103
|
+
|
104
|
+
Read more about this kind on
|
105
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#FieldDefinition).
|
106
|
+
|
107
|
+
### `InputObjectTypeDefinition` (boolean)
|
108
|
+
|
109
|
+
Read more about this kind on
|
110
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#InputObjectTypeDefinition).
|
111
|
+
|
112
|
+
### `InputValueDefinition` (boolean)
|
113
|
+
|
114
|
+
Read more about this kind on
|
115
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#InputValueDefinition).
|
116
|
+
|
117
|
+
### `InterfaceTypeDefinition` (boolean)
|
118
|
+
|
119
|
+
Read more about this kind on
|
120
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#InterfaceTypeDefinition).
|
121
|
+
|
122
|
+
### `ObjectTypeDefinition` (boolean)
|
123
|
+
|
124
|
+
Read more about this kind on
|
125
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#ObjectTypeDefinition).
|
126
|
+
|
127
|
+
### `OperationDefinition` (boolean)
|
128
|
+
|
129
|
+
Read more about this kind on
|
130
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#OperationDefinition).
|
131
|
+
|
132
|
+
> You must use only comment syntax `#` and not description syntax `"""` or `"`.
|
133
|
+
|
134
|
+
### `ScalarTypeDefinition` (boolean)
|
135
|
+
|
136
|
+
Read more about this kind on
|
137
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#ScalarTypeDefinition).
|
138
|
+
|
139
|
+
### `UnionTypeDefinition` (boolean)
|
140
|
+
|
141
|
+
Read more about this kind on
|
142
|
+
[spec.graphql.org](https://spec.graphql.org/October2021/#UnionTypeDefinition).
|
143
|
+
|
144
|
+
## Resources
|
145
|
+
|
146
|
+
- [Rule source](../../packages/plugin/src/rules/require-description.ts)
|
147
|
+
- [Test source](../../packages/plugin/tests/require-description.spec.ts)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# `require-field-of-type-query-in-mutation-result`
|
2
|
+
|
3
|
+
- Category: `Schema`
|
4
|
+
- Rule name: `@graphql-eslint/require-field-of-type-query-in-mutation-result`
|
5
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
6
|
+
- Requires GraphQL Operations: `false`
|
7
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
8
|
+
|
9
|
+
Allow the client in one round-trip not only to call mutation but also to get a wagon of data to
|
10
|
+
update their application.
|
11
|
+
|
12
|
+
> Currently, no errors are reported for result type `union`, `interface` and `scalar`.
|
13
|
+
|
14
|
+
## Usage Examples
|
15
|
+
|
16
|
+
### Incorrect
|
17
|
+
|
18
|
+
```graphql
|
19
|
+
# eslint @graphql-eslint/require-field-of-type-query-in-mutation-result: 'error'
|
20
|
+
|
21
|
+
type User { ... }
|
22
|
+
|
23
|
+
type Mutation {
|
24
|
+
createUser: User!
|
25
|
+
}
|
26
|
+
```
|
27
|
+
|
28
|
+
### Correct
|
29
|
+
|
30
|
+
```graphql
|
31
|
+
# eslint @graphql-eslint/require-field-of-type-query-in-mutation-result: 'error'
|
32
|
+
|
33
|
+
type User { ... }
|
34
|
+
|
35
|
+
type Query { ... }
|
36
|
+
|
37
|
+
type CreateUserPayload {
|
38
|
+
user: User!
|
39
|
+
query: Query!
|
40
|
+
}
|
41
|
+
|
42
|
+
type Mutation {
|
43
|
+
createUser: CreateUserPayload!
|
44
|
+
}
|
45
|
+
```
|
46
|
+
|
47
|
+
## Resources
|
48
|
+
|
49
|
+
- [Rule source](../../packages/plugin/src/rules/require-field-of-type-query-in-mutation-result.ts)
|
50
|
+
- [Test source](../../packages/plugin/tests/require-field-of-type-query-in-mutation-result.spec.ts)
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# `require-id-when-available`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
💡 This rule provides
|
7
|
+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
8
|
+
|
9
|
+
- Category: `Operations`
|
10
|
+
- Rule name: `@graphql-eslint/require-id-when-available`
|
11
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
12
|
+
- Requires GraphQL Operations: `true`
|
13
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
14
|
+
|
15
|
+
Enforce selecting specific fields when they are available on the GraphQL type.
|
16
|
+
|
17
|
+
## Usage Examples
|
18
|
+
|
19
|
+
### Incorrect
|
20
|
+
|
21
|
+
```graphql
|
22
|
+
# eslint @graphql-eslint/require-id-when-available: 'error'
|
23
|
+
|
24
|
+
# In your schema
|
25
|
+
type User {
|
26
|
+
id: ID!
|
27
|
+
name: String!
|
28
|
+
}
|
29
|
+
|
30
|
+
# Query
|
31
|
+
query {
|
32
|
+
user {
|
33
|
+
name
|
34
|
+
}
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
### Correct
|
39
|
+
|
40
|
+
```graphql
|
41
|
+
# eslint @graphql-eslint/require-id-when-available: 'error'
|
42
|
+
|
43
|
+
# In your schema
|
44
|
+
type User {
|
45
|
+
id: ID!
|
46
|
+
name: String!
|
47
|
+
}
|
48
|
+
|
49
|
+
# Query
|
50
|
+
query {
|
51
|
+
user {
|
52
|
+
id
|
53
|
+
name
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
# Selecting `id` with an alias is also valid
|
58
|
+
query {
|
59
|
+
user {
|
60
|
+
id: name
|
61
|
+
}
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
## Config Schema
|
66
|
+
|
67
|
+
The schema defines the following properties:
|
68
|
+
|
69
|
+
### `fieldName`
|
70
|
+
|
71
|
+
The object must be one of the following types:
|
72
|
+
|
73
|
+
- `asString`
|
74
|
+
- `asArray`
|
75
|
+
|
76
|
+
Default: `"id"`
|
77
|
+
|
78
|
+
---
|
79
|
+
|
80
|
+
# Sub Schemas
|
81
|
+
|
82
|
+
The schema defines the following additional types:
|
83
|
+
|
84
|
+
## `asString` (string)
|
85
|
+
|
86
|
+
## `asArray` (array)
|
87
|
+
|
88
|
+
## Resources
|
89
|
+
|
90
|
+
- [Rule source](../../packages/plugin/src/rules/require-id-when-available.ts)
|
91
|
+
- [Test source](../../packages/plugin/tests/require-id-when-available.spec.ts)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# `scalar-leafs`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
💡 This rule provides
|
7
|
+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
8
|
+
|
9
|
+
- Category: `Operations`
|
10
|
+
- Rule name: `@graphql-eslint/scalar-leafs`
|
11
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
12
|
+
- Requires GraphQL Operations: `false`
|
13
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
14
|
+
|
15
|
+
A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or
|
16
|
+
enum types.
|
17
|
+
|
18
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
19
|
+
|
20
|
+
## Resources
|
21
|
+
|
22
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ScalarLeafsRule.ts)
|
23
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/ScalarLeafsRule-test.ts)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# `selection-set-depth`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
💡 This rule provides
|
7
|
+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
8
|
+
|
9
|
+
- Category: `Operations`
|
10
|
+
- Rule name: `@graphql-eslint/selection-set-depth`
|
11
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
12
|
+
- Requires GraphQL Operations: `true`
|
13
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
14
|
+
|
15
|
+
Limit the complexity of the GraphQL operations solely by their depth. Based on
|
16
|
+
[graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).
|
17
|
+
|
18
|
+
## Usage Examples
|
19
|
+
|
20
|
+
### Incorrect
|
21
|
+
|
22
|
+
```graphql
|
23
|
+
# eslint @graphql-eslint/selection-set-depth: ['error', { maxDepth: 1 }]
|
24
|
+
|
25
|
+
query deep2 {
|
26
|
+
viewer {
|
27
|
+
# Level 0
|
28
|
+
albums {
|
29
|
+
# Level 1
|
30
|
+
title # Level 2
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
36
|
+
### Correct
|
37
|
+
|
38
|
+
```graphql
|
39
|
+
# eslint @graphql-eslint/selection-set-depth: ['error', { maxDepth: 4 }]
|
40
|
+
|
41
|
+
query deep2 {
|
42
|
+
viewer {
|
43
|
+
# Level 0
|
44
|
+
albums {
|
45
|
+
# Level 1
|
46
|
+
title # Level 2
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
### Correct (ignored field)
|
53
|
+
|
54
|
+
```graphql
|
55
|
+
# eslint @graphql-eslint/selection-set-depth: ['error', { maxDepth: 1, ignore: ['albums'] }]
|
56
|
+
|
57
|
+
query deep2 {
|
58
|
+
viewer {
|
59
|
+
# Level 0
|
60
|
+
albums {
|
61
|
+
# Level 1
|
62
|
+
title # Level 2
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
## Config Schema
|
69
|
+
|
70
|
+
The schema defines the following properties:
|
71
|
+
|
72
|
+
### `maxDepth` (number, required)
|
73
|
+
|
74
|
+
### `ignore` (array)
|
75
|
+
|
76
|
+
The object is an array with all elements of the type `string`.
|
77
|
+
|
78
|
+
Additional restrictions:
|
79
|
+
|
80
|
+
- Minimum items: `1`
|
81
|
+
- Unique items: `true`
|
82
|
+
|
83
|
+
## Resources
|
84
|
+
|
85
|
+
- [Rule source](../../packages/plugin/src/rules/selection-set-depth.ts)
|
86
|
+
- [Test source](../../packages/plugin/tests/selection-set-depth.spec.ts)
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# `strict-id-in-types`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
- Category: `Schema`
|
7
|
+
- Rule name: `@graphql-eslint/strict-id-in-types`
|
8
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `false`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
Requires output types to have one unique identifier unless they do not have a logical one.
|
13
|
+
Exceptions can be used to ignore output types that do not have unique identifiers.
|
14
|
+
|
15
|
+
## Usage Examples
|
16
|
+
|
17
|
+
### Incorrect
|
18
|
+
|
19
|
+
```graphql
|
20
|
+
# eslint @graphql-eslint/strict-id-in-types: ['error', { acceptedIdNames: ['id', '_id'], acceptedIdTypes: ['ID'], exceptions: { suffixes: ['Payload'] } }]
|
21
|
+
|
22
|
+
# Incorrect field name
|
23
|
+
type InvalidFieldName {
|
24
|
+
key: ID!
|
25
|
+
}
|
26
|
+
|
27
|
+
# Incorrect field type
|
28
|
+
type InvalidFieldType {
|
29
|
+
id: String!
|
30
|
+
}
|
31
|
+
|
32
|
+
# Incorrect exception suffix
|
33
|
+
type InvalidSuffixResult {
|
34
|
+
data: String!
|
35
|
+
}
|
36
|
+
|
37
|
+
# Too many unique identifiers. Must only contain one.
|
38
|
+
type InvalidFieldName {
|
39
|
+
id: ID!
|
40
|
+
_id: ID!
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
### Correct
|
45
|
+
|
46
|
+
```graphql
|
47
|
+
# eslint @graphql-eslint/strict-id-in-types: ['error', { acceptedIdNames: ['id', '_id'], acceptedIdTypes: ['ID'], exceptions: { types: ['Error'], suffixes: ['Payload'] } }]
|
48
|
+
|
49
|
+
type User {
|
50
|
+
id: ID!
|
51
|
+
}
|
52
|
+
|
53
|
+
type Post {
|
54
|
+
_id: ID!
|
55
|
+
}
|
56
|
+
|
57
|
+
type CreateUserPayload {
|
58
|
+
data: String!
|
59
|
+
}
|
60
|
+
|
61
|
+
type Error {
|
62
|
+
message: String!
|
63
|
+
}
|
64
|
+
```
|
65
|
+
|
66
|
+
## Config Schema
|
67
|
+
|
68
|
+
The schema defines the following properties:
|
69
|
+
|
70
|
+
### `acceptedIdNames` (array)
|
71
|
+
|
72
|
+
The object is an array with all elements of the type `string`.
|
73
|
+
|
74
|
+
Default:
|
75
|
+
|
76
|
+
```json
|
77
|
+
["id"]
|
78
|
+
```
|
79
|
+
|
80
|
+
Additional restrictions:
|
81
|
+
|
82
|
+
- Minimum items: `1`
|
83
|
+
- Unique items: `true`
|
84
|
+
|
85
|
+
### `acceptedIdTypes` (array)
|
86
|
+
|
87
|
+
The object is an array with all elements of the type `string`.
|
88
|
+
|
89
|
+
Default:
|
90
|
+
|
91
|
+
```json
|
92
|
+
["ID"]
|
93
|
+
```
|
94
|
+
|
95
|
+
Additional restrictions:
|
96
|
+
|
97
|
+
- Minimum items: `1`
|
98
|
+
- Unique items: `true`
|
99
|
+
|
100
|
+
### `exceptions` (object)
|
101
|
+
|
102
|
+
Properties of the `exceptions` object:
|
103
|
+
|
104
|
+
#### `types` (array)
|
105
|
+
|
106
|
+
This is used to exclude types with names that match one of the specified values.
|
107
|
+
|
108
|
+
The object is an array with all elements of the type `string`.
|
109
|
+
|
110
|
+
Additional restrictions:
|
111
|
+
|
112
|
+
- Minimum items: `1`
|
113
|
+
- Unique items: `true`
|
114
|
+
|
115
|
+
#### `suffixes` (array)
|
116
|
+
|
117
|
+
This is used to exclude types with names with suffixes that match one of the specified values.
|
118
|
+
|
119
|
+
The object is an array with all elements of the type `string`.
|
120
|
+
|
121
|
+
Additional restrictions:
|
122
|
+
|
123
|
+
- Minimum items: `1`
|
124
|
+
- Unique items: `true`
|
125
|
+
|
126
|
+
## Resources
|
127
|
+
|
128
|
+
- [Rule source](../../packages/plugin/src/rules/strict-id-in-types.ts)
|
129
|
+
- [Test source](../../packages/plugin/tests/strict-id-in-types.spec.ts)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# `unique-argument-names`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
- Category: `Operations`
|
7
|
+
- Rule name: `@graphql-eslint/unique-argument-names`
|
8
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `false`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
A GraphQL field or directive is only valid if all supplied arguments are uniquely named.
|
13
|
+
|
14
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueArgumentNamesRule.ts)
|
19
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueArgumentNamesRule-test.ts)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# `unique-directive-names-per-location`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` and
|
4
|
+
`"plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this
|
5
|
+
rule.
|
6
|
+
|
7
|
+
- Category: `Schema & Operations`
|
8
|
+
- Rule name: `@graphql-eslint/unique-directive-names-per-location`
|
9
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
10
|
+
- Requires GraphQL Operations: `false`
|
11
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
12
|
+
|
13
|
+
A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely
|
14
|
+
named.
|
15
|
+
|
16
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
17
|
+
|
18
|
+
## Resources
|
19
|
+
|
20
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueDirectivesPerLocationRule.ts)
|
21
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueDirectivesPerLocationRule-test.ts)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# `unique-directive-names`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
- Category: `Schema`
|
7
|
+
- Rule name: `@graphql-eslint/unique-directive-names`
|
8
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `false`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
A GraphQL document is only valid if all defined directives have unique names.
|
13
|
+
|
14
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueDirectiveNamesRule.ts)
|
19
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueDirectiveNamesRule-test.ts)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# `unique-enum-value-names`
|
2
|
+
|
3
|
+
- Category: `Schema`
|
4
|
+
- Rule name: `@graphql-eslint/unique-enum-value-names`
|
5
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
6
|
+
- Requires GraphQL Operations: `false`
|
7
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
8
|
+
|
9
|
+
A GraphQL enum type is only valid if all its values are uniquely named.
|
10
|
+
|
11
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
12
|
+
|
13
|
+
## Resources
|
14
|
+
|
15
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueEnumValueNamesRule.ts)
|
16
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueEnumValueNamesRule-test.ts)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# `unique-field-definition-names`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
- Category: `Schema`
|
7
|
+
- Rule name: `@graphql-eslint/unique-field-definition-names`
|
8
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `false`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
A GraphQL complex type is only valid if all its fields are uniquely named.
|
13
|
+
|
14
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueFieldDefinitionNamesRule.ts)
|
19
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueFieldDefinitionNamesRule-test.ts)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# `unique-fragment-name`
|
2
|
+
|
3
|
+
- Category: `Operations`
|
4
|
+
- Rule name: `@graphql-eslint/unique-fragment-name`
|
5
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
6
|
+
- Requires GraphQL Operations: `true`
|
7
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
8
|
+
|
9
|
+
Enforce unique fragment names across your project.
|
10
|
+
|
11
|
+
## Usage Examples
|
12
|
+
|
13
|
+
### Incorrect
|
14
|
+
|
15
|
+
```graphql
|
16
|
+
# eslint @graphql-eslint/unique-fragment-name: 'error'
|
17
|
+
|
18
|
+
# user.fragment.graphql
|
19
|
+
fragment UserFields on User {
|
20
|
+
id
|
21
|
+
name
|
22
|
+
fullName
|
23
|
+
}
|
24
|
+
|
25
|
+
# user-fields.graphql
|
26
|
+
fragment UserFields on User {
|
27
|
+
id
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
### Correct
|
32
|
+
|
33
|
+
```graphql
|
34
|
+
# eslint @graphql-eslint/unique-fragment-name: 'error'
|
35
|
+
|
36
|
+
# user.fragment.graphql
|
37
|
+
fragment AllUserFields on User {
|
38
|
+
id
|
39
|
+
name
|
40
|
+
fullName
|
41
|
+
}
|
42
|
+
|
43
|
+
# user-fields.graphql
|
44
|
+
fragment UserFields on User {
|
45
|
+
id
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
## Resources
|
50
|
+
|
51
|
+
- [Rule source](../../packages/plugin/src/rules/unique-fragment-name.ts)
|
52
|
+
- [Test source](../../packages/plugin/tests/unique-fragment-name.spec.ts)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# `unique-input-field-names`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
|
4
|
+
enables this rule.
|
5
|
+
|
6
|
+
- Category: `Operations`
|
7
|
+
- Rule name: `@graphql-eslint/unique-input-field-names`
|
8
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `false`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
A GraphQL input object value is only valid if all supplied fields are uniquely named.
|
13
|
+
|
14
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
15
|
+
|
16
|
+
## Resources
|
17
|
+
|
18
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueInputFieldNamesRule.ts)
|
19
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/UniqueInputFieldNamesRule-test.ts)
|