@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,57 @@
|
|
1
|
+
# `description-style`
|
2
|
+
|
3
|
+
✅ The `"extends": "plugin:@graphql-eslint/schema-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: `Schema`
|
10
|
+
- Rule name: `@graphql-eslint/description-style`
|
11
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
12
|
+
- Requires GraphQL Operations: `false`
|
13
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
14
|
+
|
15
|
+
Require all comments to follow the same style (either block or inline).
|
16
|
+
|
17
|
+
## Usage Examples
|
18
|
+
|
19
|
+
### Incorrect
|
20
|
+
|
21
|
+
```graphql
|
22
|
+
# eslint @graphql-eslint/description-style: ['error', { style: 'inline' }]
|
23
|
+
|
24
|
+
""" Description """
|
25
|
+
type someTypeName {
|
26
|
+
# ...
|
27
|
+
}
|
28
|
+
```
|
29
|
+
|
30
|
+
### Correct
|
31
|
+
|
32
|
+
```graphql
|
33
|
+
# eslint @graphql-eslint/description-style: ['error', { style: 'inline' }]
|
34
|
+
|
35
|
+
" Description "
|
36
|
+
type someTypeName {
|
37
|
+
# ...
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Config Schema
|
42
|
+
|
43
|
+
The schema defines the following properties:
|
44
|
+
|
45
|
+
### `style` (enum)
|
46
|
+
|
47
|
+
This element must be one of the following enum values:
|
48
|
+
|
49
|
+
- `block`
|
50
|
+
- `inline`
|
51
|
+
|
52
|
+
Default: `"block"`
|
53
|
+
|
54
|
+
## Resources
|
55
|
+
|
56
|
+
- [Rule source](../../packages/plugin/src/rules/description-style.ts)
|
57
|
+
- [Test source](../../packages/plugin/tests/description-style.spec.ts)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# `executable-definitions`
|
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/executable-definitions`
|
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 document is only valid for execution if all definitions are either operation or fragment
|
13
|
+
definitions.
|
14
|
+
|
15
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
16
|
+
|
17
|
+
## Resources
|
18
|
+
|
19
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ExecutableDefinitionsRule.ts)
|
20
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/ExecutableDefinitionsRule-test.ts)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# `fields-on-correct-type`
|
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/fields-on-correct-type`
|
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 only valid if all fields selected are defined by the parent type, or are an
|
16
|
+
allowed meta field such as `__typename`.
|
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/FieldsOnCorrectTypeRule.ts)
|
23
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/FieldsOnCorrectTypeRule-test.ts)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# `fragments-on-composite-type`
|
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/fragments-on-composite-type`
|
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
|
+
Fragments use a type condition to determine if they apply, since fragments can only be spread into a
|
13
|
+
composite type (object, interface, or union), the type condition must also be a composite type.
|
14
|
+
|
15
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
16
|
+
|
17
|
+
## Resources
|
18
|
+
|
19
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/FragmentsOnCompositeTypesRule.ts)
|
20
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/FragmentsOnCompositeTypesRule-test.ts)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# `input-name`
|
2
|
+
|
3
|
+
💡 This rule provides
|
4
|
+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
5
|
+
|
6
|
+
- Category: `Schema`
|
7
|
+
- Rule name: `@graphql-eslint/input-name`
|
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
|
+
Require mutation argument to be always called "input" and input type to be called Mutation name +
|
13
|
+
"Input". Using the same name for all input parameters will make your schemas easier to consume and
|
14
|
+
more predictable. Using the same name as mutation for InputType will make it easier to find
|
15
|
+
mutations that InputType belongs to.
|
16
|
+
|
17
|
+
## Usage Examples
|
18
|
+
|
19
|
+
### Incorrect
|
20
|
+
|
21
|
+
```graphql
|
22
|
+
# eslint @graphql-eslint/input-name: ['error', { checkInputType: true }]
|
23
|
+
|
24
|
+
type Mutation {
|
25
|
+
SetMessage(message: InputMessage): String
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
### Correct (with checkInputType)
|
30
|
+
|
31
|
+
```graphql
|
32
|
+
# eslint @graphql-eslint/input-name: ['error', { checkInputType: true }]
|
33
|
+
|
34
|
+
type Mutation {
|
35
|
+
SetMessage(input: SetMessageInput): String
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
### Correct (without checkInputType)
|
40
|
+
|
41
|
+
```graphql
|
42
|
+
# eslint @graphql-eslint/input-name: ['error', { checkInputType: false }]
|
43
|
+
|
44
|
+
type Mutation {
|
45
|
+
SetMessage(input: AnyInputTypeName): String
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
## Config Schema
|
50
|
+
|
51
|
+
The schema defines the following properties:
|
52
|
+
|
53
|
+
### `checkInputType` (boolean)
|
54
|
+
|
55
|
+
Check that the input type name follows the convention <mutationName>Input
|
56
|
+
|
57
|
+
Default: `false`
|
58
|
+
|
59
|
+
### `caseSensitiveInputType` (boolean)
|
60
|
+
|
61
|
+
Allow for case discrepancies in the input type name
|
62
|
+
|
63
|
+
Default: `true`
|
64
|
+
|
65
|
+
### `checkQueries` (boolean)
|
66
|
+
|
67
|
+
Apply the rule to Queries
|
68
|
+
|
69
|
+
Default: `false`
|
70
|
+
|
71
|
+
### `checkMutations` (boolean)
|
72
|
+
|
73
|
+
Apply the rule to Mutations
|
74
|
+
|
75
|
+
Default: `true`
|
76
|
+
|
77
|
+
## Resources
|
78
|
+
|
79
|
+
- [Rule source](../../packages/plugin/src/rules/input-name.ts)
|
80
|
+
- [Test source](../../packages/plugin/tests/input-name.spec.ts)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# `known-argument-names`
|
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
|
+
💡 This rule provides
|
8
|
+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
9
|
+
|
10
|
+
- Category: `Schema & Operations`
|
11
|
+
- Rule name: `@graphql-eslint/known-argument-names`
|
12
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
13
|
+
- Requires GraphQL Operations: `false`
|
14
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
15
|
+
|
16
|
+
A GraphQL field is only valid if all supplied arguments are defined by that field.
|
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/KnownArgumentNamesRule.ts)
|
23
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/KnownArgumentNamesRule-test.ts)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# `known-directives`
|
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/known-directives`
|
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 `@directive`s are known by the schema and legally
|
14
|
+
positioned.
|
15
|
+
|
16
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
17
|
+
|
18
|
+
## Usage Examples
|
19
|
+
|
20
|
+
### Valid
|
21
|
+
|
22
|
+
```graphql
|
23
|
+
# eslint @graphql-eslint/known-directives: ['error', { ignoreClientDirectives: ['client'] }]
|
24
|
+
|
25
|
+
{
|
26
|
+
product {
|
27
|
+
someClientField @client
|
28
|
+
}
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
## Config Schema
|
33
|
+
|
34
|
+
The schema defines the following properties:
|
35
|
+
|
36
|
+
### `ignoreClientDirectives` (array, required)
|
37
|
+
|
38
|
+
The object is an array with all elements of the type `string`.
|
39
|
+
|
40
|
+
Additional restrictions:
|
41
|
+
|
42
|
+
- Minimum items: `1`
|
43
|
+
- Unique items: `true`
|
44
|
+
|
45
|
+
## Resources
|
46
|
+
|
47
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownDirectivesRule.ts)
|
48
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/KnownDirectivesRule-test.ts)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# `known-fragment-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/known-fragment-names`
|
8
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
9
|
+
- Requires GraphQL Operations: `true`
|
10
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
11
|
+
|
12
|
+
A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in
|
13
|
+
the same document.
|
14
|
+
|
15
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
16
|
+
|
17
|
+
## Usage Examples
|
18
|
+
|
19
|
+
### Incorrect
|
20
|
+
|
21
|
+
```graphql
|
22
|
+
# eslint @graphql-eslint/known-fragment-names: 'error'
|
23
|
+
|
24
|
+
query {
|
25
|
+
user {
|
26
|
+
id
|
27
|
+
...UserFields # fragment not defined in the document
|
28
|
+
}
|
29
|
+
}
|
30
|
+
```
|
31
|
+
|
32
|
+
### Correct
|
33
|
+
|
34
|
+
```graphql
|
35
|
+
# eslint @graphql-eslint/known-fragment-names: 'error'
|
36
|
+
|
37
|
+
fragment UserFields on User {
|
38
|
+
firstName
|
39
|
+
lastName
|
40
|
+
}
|
41
|
+
|
42
|
+
query {
|
43
|
+
user {
|
44
|
+
id
|
45
|
+
...UserFields
|
46
|
+
}
|
47
|
+
}
|
48
|
+
```
|
49
|
+
|
50
|
+
### Correct (`UserFields` fragment located in a separate file)
|
51
|
+
|
52
|
+
```graphql
|
53
|
+
# eslint @graphql-eslint/known-fragment-names: 'error'
|
54
|
+
|
55
|
+
# user.gql
|
56
|
+
query {
|
57
|
+
user {
|
58
|
+
id
|
59
|
+
...UserFields
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
# user-fields.gql
|
64
|
+
fragment UserFields on User {
|
65
|
+
id
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
## Resources
|
70
|
+
|
71
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownFragmentNamesRule.ts)
|
72
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/KnownFragmentNamesRule-test.ts)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# `known-type-names`
|
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
|
+
💡 This rule provides
|
8
|
+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
9
|
+
|
10
|
+
- Category: `Schema & Operations`
|
11
|
+
- Rule name: `@graphql-eslint/known-type-names`
|
12
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
13
|
+
- Requires GraphQL Operations: `false`
|
14
|
+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
15
|
+
|
16
|
+
A GraphQL document is only valid if referenced types (specifically variable definitions and fragment
|
17
|
+
conditions) are defined by the type schema.
|
18
|
+
|
19
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
20
|
+
|
21
|
+
## Resources
|
22
|
+
|
23
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownTypeNamesRule.ts)
|
24
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/KnownTypeNamesRule-test.ts)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# `lone-anonymous-operation`
|
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/lone-anonymous-operation`
|
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 document that contains an anonymous operation (the `query` short-hand) is only valid if it
|
13
|
+
contains only that one operation definition.
|
14
|
+
|
15
|
+
> This rule is a wrapper around a `graphql-js` validation function.
|
16
|
+
|
17
|
+
## Resources
|
18
|
+
|
19
|
+
- [Rule source](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/LoneAnonymousOperationRule.ts)
|
20
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/LoneAnonymousOperationRule-test.ts)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# `lone-executable-definition`
|
2
|
+
|
3
|
+
- Category: `Operations`
|
4
|
+
- Rule name: `@graphql-eslint/lone-executable-definition`
|
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
|
+
Require all queries, mutations, subscriptions and fragments to be located in separate files.
|
10
|
+
|
11
|
+
## Usage Examples
|
12
|
+
|
13
|
+
### Incorrect
|
14
|
+
|
15
|
+
```graphql
|
16
|
+
# eslint @graphql-eslint/lone-executable-definition: 'error'
|
17
|
+
|
18
|
+
query Foo {
|
19
|
+
id
|
20
|
+
}
|
21
|
+
fragment Bar on Baz {
|
22
|
+
id
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
### Correct
|
27
|
+
|
28
|
+
```graphql
|
29
|
+
# eslint @graphql-eslint/lone-executable-definition: 'error'
|
30
|
+
|
31
|
+
query Foo {
|
32
|
+
id
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
36
|
+
## Config Schema
|
37
|
+
|
38
|
+
The schema defines the following properties:
|
39
|
+
|
40
|
+
### `ignore` (array)
|
41
|
+
|
42
|
+
Allow certain definitions to be placed alongside others.
|
43
|
+
|
44
|
+
The elements of the array can contain the following enum values:
|
45
|
+
|
46
|
+
- `fragment`
|
47
|
+
- `query`
|
48
|
+
- `mutation`
|
49
|
+
- `subscription`
|
50
|
+
|
51
|
+
Additional restrictions:
|
52
|
+
|
53
|
+
- Minimum items: `1`
|
54
|
+
- Unique items: `true`
|
55
|
+
|
56
|
+
## Resources
|
57
|
+
|
58
|
+
- [Rule source](../../packages/plugin/src/rules/lone-executable-definition.ts)
|
59
|
+
- [Test source](../../packages/plugin/tests/lone-executable-definition.spec.ts)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# `lone-schema-definition`
|
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/lone-schema-definition`
|
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 it contains only one schema definition.
|
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/LoneSchemaDefinitionRule.ts)
|
19
|
+
- [Test source](https://github.com/graphql/graphql-js/tree/main/src/validation/__tests__/LoneSchemaDefinitionRule-test.ts)
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# `match-document-filename`
|
2
|
+
|
3
|
+
- Category: `Operations`
|
4
|
+
- Rule name: `@graphql-eslint/match-document-filename`
|
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
|
+
This rule allows you to enforce that the file name should match the operation name.
|
10
|
+
|
11
|
+
## Usage Examples
|
12
|
+
|
13
|
+
### Correct
|
14
|
+
|
15
|
+
```graphql
|
16
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { fileExtension: '.gql' }]
|
17
|
+
|
18
|
+
# user.gql
|
19
|
+
type User {
|
20
|
+
id: ID!
|
21
|
+
}
|
22
|
+
```
|
23
|
+
|
24
|
+
### Correct
|
25
|
+
|
26
|
+
```graphql
|
27
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { query: 'snake_case' }]
|
28
|
+
|
29
|
+
# user_by_id.gql
|
30
|
+
query UserById {
|
31
|
+
userById(id: 5) {
|
32
|
+
id
|
33
|
+
name
|
34
|
+
fullName
|
35
|
+
}
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
### Correct
|
40
|
+
|
41
|
+
```graphql
|
42
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { fragment: { style: 'kebab-case', suffix: '.fragment' } }]
|
43
|
+
|
44
|
+
# user-fields.fragment.gql
|
45
|
+
fragment user_fields on User {
|
46
|
+
id
|
47
|
+
email
|
48
|
+
}
|
49
|
+
```
|
50
|
+
|
51
|
+
### Correct
|
52
|
+
|
53
|
+
```graphql
|
54
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { mutation: { style: 'PascalCase', suffix: 'Mutation' } }]
|
55
|
+
|
56
|
+
# DeleteUserMutation.gql
|
57
|
+
mutation DELETE_USER {
|
58
|
+
deleteUser(id: 5)
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
62
|
+
### Incorrect
|
63
|
+
|
64
|
+
```graphql
|
65
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { fileExtension: '.graphql' }]
|
66
|
+
|
67
|
+
# post.gql
|
68
|
+
type Post {
|
69
|
+
id: ID!
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
### Incorrect
|
74
|
+
|
75
|
+
```graphql
|
76
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { query: 'PascalCase' }]
|
77
|
+
|
78
|
+
# user-by-id.gql
|
79
|
+
query UserById {
|
80
|
+
userById(id: 5) {
|
81
|
+
id
|
82
|
+
name
|
83
|
+
fullName
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
### Correct
|
89
|
+
|
90
|
+
```graphql
|
91
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { fragment: { style: 'kebab-case', prefix: 'mutation.' } }]
|
92
|
+
|
93
|
+
# mutation.add-alert.graphql
|
94
|
+
mutation addAlert {
|
95
|
+
foo
|
96
|
+
}
|
97
|
+
```
|
98
|
+
|
99
|
+
### Correct
|
100
|
+
|
101
|
+
```graphql
|
102
|
+
# eslint @graphql-eslint/match-document-filename: ['error', { fragment: { prefix: 'query.' } }]
|
103
|
+
|
104
|
+
# query.me.graphql
|
105
|
+
query me {
|
106
|
+
foo
|
107
|
+
}
|
108
|
+
```
|
109
|
+
|
110
|
+
## Config Schema
|
111
|
+
|
112
|
+
The schema defines the following properties:
|
113
|
+
|
114
|
+
### `fileExtension` (enum)
|
115
|
+
|
116
|
+
This element must be one of the following enum values:
|
117
|
+
|
118
|
+
- `.gql`
|
119
|
+
- `.graphql`
|
120
|
+
|
121
|
+
### `query`
|
122
|
+
|
123
|
+
The object must be one of the following types:
|
124
|
+
|
125
|
+
- `asString`
|
126
|
+
- `asObject`
|
127
|
+
|
128
|
+
### `mutation`
|
129
|
+
|
130
|
+
The object must be one of the following types:
|
131
|
+
|
132
|
+
- `asString`
|
133
|
+
- `asObject`
|
134
|
+
|
135
|
+
### `subscription`
|
136
|
+
|
137
|
+
The object must be one of the following types:
|
138
|
+
|
139
|
+
- `asString`
|
140
|
+
- `asObject`
|
141
|
+
|
142
|
+
### `fragment`
|
143
|
+
|
144
|
+
The object must be one of the following types:
|
145
|
+
|
146
|
+
- `asString`
|
147
|
+
- `asObject`
|
148
|
+
|
149
|
+
---
|
150
|
+
|
151
|
+
# Sub Schemas
|
152
|
+
|
153
|
+
The schema defines the following additional types:
|
154
|
+
|
155
|
+
## `asString` (enum)
|
156
|
+
|
157
|
+
One of: `camelCase`, `PascalCase`, `snake_case`, `UPPER_CASE`, `kebab-case`, `matchDocumentStyle`
|
158
|
+
|
159
|
+
## `asObject` (object)
|
160
|
+
|
161
|
+
Properties of the `asObject` object:
|
162
|
+
|
163
|
+
### `style` (enum)
|
164
|
+
|
165
|
+
This element must be one of the following enum values:
|
166
|
+
|
167
|
+
- `camelCase`
|
168
|
+
- `PascalCase`
|
169
|
+
- `snake_case`
|
170
|
+
- `UPPER_CASE`
|
171
|
+
- `kebab-case`
|
172
|
+
- `matchDocumentStyle`
|
173
|
+
|
174
|
+
### `suffix` (string)
|
175
|
+
|
176
|
+
### `prefix` (string)
|
177
|
+
|
178
|
+
## Resources
|
179
|
+
|
180
|
+
- [Rule source](../../packages/plugin/src/rules/match-document-filename.ts)
|
181
|
+
- [Test source](../../packages/plugin/tests/match-document-filename.spec.ts)
|