Skip to content

Commit a4f885a

Browse files
authored
add suggestions for graphql-js rules (#1314)
* format * format * async * refactor graphql-js functions * it works * changeset * update generate-docs
1 parent f05a562 commit a4f885a

File tree

69 files changed

+1318
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1318
-564
lines changed

.changeset/sour-windows-tap.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': minor
3+
---
4+
5+
add ESLint suggestions for following `graphql-js` rules:
6+
7+
- `fields-on-correct-type`
8+
- `known-argument-names`
9+
- `known-type-names`
10+
- `possible-type-extension`
11+
- `scalar-leafs`
12+
- `value-literals-of-correct-type`

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dist/
2-
docs/rules/
32
packages/plugin/tests/__snapshots__/
43
examples/prettier/invalid.graphql
54
examples/prettier/invalid.js

docs/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Name            &nbs
1616
[alphabetize](rules/alphabetize.md)|Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.|![all][]|🚀|🔧
1717
[description-style](rules/description-style.md)|Require all comments to follow the same style (either block or inline).|![recommended][]|🚀|💡
1818
[executable-definitions](rules/executable-definitions.md)|A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.|![recommended][]|🔮|
19-
[fields-on-correct-type](rules/fields-on-correct-type.md)|A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.|![recommended][]|🔮|
19+
[fields-on-correct-type](rules/fields-on-correct-type.md)|A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.|![recommended][]|🔮|💡
2020
[fragments-on-composite-type](rules/fragments-on-composite-type.md)|Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.|![recommended][]|🔮|
2121
[input-name](rules/input-name.md)|Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".|![all][]|🚀|💡
22-
[known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮|
22+
[known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮|💡
2323
[known-directives](rules/known-directives.md)|A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.|![recommended][]|🔮|
2424
[known-fragment-names](rules/known-fragment-names.md)|A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.|![recommended][]|🔮|
25-
[known-type-names](rules/known-type-names.md)|A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.|![recommended][]|🔮|
25+
[known-type-names](rules/known-type-names.md)|A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.|![recommended][]|🔮|💡
2626
[lone-anonymous-operation](rules/lone-anonymous-operation.md)|A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.|![recommended][]|🔮|
2727
[lone-schema-definition](rules/lone-schema-definition.md)|A GraphQL document is only valid if it contains only one schema definition.|![recommended][]|🔮|
2828
[match-document-filename](rules/match-document-filename.md)|This rule allows you to enforce that the file name should match the operation name.|![all][]|🚀|
@@ -44,18 +44,18 @@ Name            &nbs
4444
[one-field-subscriptions](rules/one-field-subscriptions.md)|A GraphQL subscription is valid only if it contains a single root field.|![recommended][]|🔮|
4545
[overlapping-fields-can-be-merged](rules/overlapping-fields-can-be-merged.md)|A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.|![recommended][]|🔮|
4646
[possible-fragment-spread](rules/possible-fragment-spread.md)|A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.|![recommended][]|🔮|
47-
[possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.||🔮|
47+
[possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.||🔮|💡
4848
[provided-required-arguments](rules/provided-required-arguments.md)|A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.|![recommended][]|🔮|
49-
[relay-arguments](rules/relay-arguments.md)|Set of rules to follow Relay specification for Arguments.||🚀|
50-
[relay-connection-types](rules/relay-connection-types.md)|Set of rules to follow Relay specification for Connection types.||🚀|
51-
[relay-edge-types](rules/relay-edge-types.md)|Set of rules to follow Relay specification for Edge types.||🚀|
52-
[relay-page-info](rules/relay-page-info.md)|Set of rules to follow Relay specification for `PageInfo` object.||🚀|
49+
[relay-arguments](rules/relay-arguments.md)|Set of rules to follow Relay specification for Arguments.|![relay][]|🚀|
50+
[relay-connection-types](rules/relay-connection-types.md)|Set of rules to follow Relay specification for Connection types.|![relay][]|🚀|
51+
[relay-edge-types](rules/relay-edge-types.md)|Set of rules to follow Relay specification for Edge types.|![relay][]|🚀|
52+
[relay-page-info](rules/relay-page-info.md)|Set of rules to follow Relay specification for `PageInfo` object.|![relay][]|🚀|
5353
[require-deprecation-date](rules/require-deprecation-date.md)|Require deletion date on `@deprecated` directive. Suggest removing deprecated things after deprecated date.|![all][]|🚀|💡
5454
[require-deprecation-reason](rules/require-deprecation-reason.md)|Require all deprecation directives to specify a reason.|![recommended][]|🚀|
5555
[require-description](rules/require-description.md)|Enforce descriptions in type definitions and operations.|![recommended][]|🚀|
5656
[require-field-of-type-query-in-mutation-result](rules/require-field-of-type-query-in-mutation-result.md)|Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.|![all][]|🚀|
5757
[require-id-when-available](rules/require-id-when-available.md)|Enforce selecting specific fields when they are available on the GraphQL type.|![recommended][]|🚀|💡
58-
[scalar-leafs](rules/scalar-leafs.md)|A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.|![recommended][]|🔮|
58+
[scalar-leafs](rules/scalar-leafs.md)|A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.|![recommended][]|🔮|💡
5959
[selection-set-depth](rules/selection-set-depth.md)|Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).|![recommended][]|🚀|💡
6060
[strict-id-in-types](rules/strict-id-in-types.md)|Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.|![recommended][]|🚀|
6161
[unique-argument-names](rules/unique-argument-names.md)|A GraphQL field or directive is only valid if all supplied arguments are uniquely named.|![recommended][]|🔮|
@@ -69,10 +69,11 @@ Name            &nbs
6969
[unique-operation-types](rules/unique-operation-types.md)|A GraphQL document is only valid if it has only one type per operation.|![recommended][]|🔮|
7070
[unique-type-names](rules/unique-type-names.md)|A GraphQL document is only valid if all defined types have unique names.|![recommended][]|🔮|
7171
[unique-variable-names](rules/unique-variable-names.md)|A GraphQL operation is only valid if all its variables are uniquely named.|![recommended][]|🔮|
72-
[value-literals-of-correct-type](rules/value-literals-of-correct-type.md)|A GraphQL document is only valid if all value literals are of the type expected at their position.|![recommended][]|🔮|
72+
[value-literals-of-correct-type](rules/value-literals-of-correct-type.md)|A GraphQL document is only valid if all value literals are of the type expected at their position.|![recommended][]|🔮|💡
7373
[variables-are-input-types](rules/variables-are-input-types.md)|A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).|![recommended][]|🔮|
7474
[variables-in-allowed-position](rules/variables-in-allowed-position.md)|Variables passed to field arguments conform to type.|![recommended][]|🔮|
7575
<!-- prettier-ignore-end -->
7676

7777
[recommended]: https://img.shields.io/badge/-recommended-green.svg
7878
[all]: https://img.shields.io/badge/-all-blue.svg
79+
[relay]: https://img.shields.io/badge/-relay-orange.svg

docs/rules/alphabetize.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# `alphabetize`
22

3-
🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#--fix) can automatically fix some of the problems reported by this rule.
3+
🔧 The `--fix` option on the
4+
[command line](https://eslint.org/docs/user-guide/command-line-interface#--fix) can automatically
5+
fix some of the problems reported by this rule.
46

57
- Category: `Schema & Operations`
68
- Rule name: `@graphql-eslint/alphabetize`
79
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
8-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
10+
- Requires GraphQL Operations: `false`
11+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
912

10-
Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.
13+
Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation
14+
selections and more.
1115

1216
## Usage Examples
1317

@@ -107,8 +111,8 @@ The elements of the array can contain the following enum values:
107111

108112
Additional restrictions:
109113

110-
* Minimum items: `1`
111-
* Unique items: `true`
114+
- Minimum items: `1`
115+
- Unique items: `true`
112116

113117
### `values` (array)
114118

@@ -120,8 +124,8 @@ The elements of the array can contain the following enum values:
120124

121125
Additional restrictions:
122126

123-
* Minimum items: `1`
124-
* Unique items: `true`
127+
- Minimum items: `1`
128+
- Unique items: `true`
125129

126130
### `selections` (array)
127131

@@ -134,8 +138,8 @@ The elements of the array can contain the following enum values:
134138

135139
Additional restrictions:
136140

137-
* Minimum items: `1`
138-
* Unique items: `true`
141+
- Minimum items: `1`
142+
- Unique items: `true`
139143

140144
### `variables` (array)
141145

@@ -147,8 +151,8 @@ The elements of the array can contain the following enum values:
147151

148152
Additional restrictions:
149153

150-
* Minimum items: `1`
151-
* Unique items: `true`
154+
- Minimum items: `1`
155+
- Unique items: `true`
152156

153157
### `arguments` (array)
154158

@@ -163,8 +167,8 @@ The elements of the array can contain the following enum values:
163167

164168
Additional restrictions:
165169

166-
* Minimum items: `1`
167-
* Unique items: `true`
170+
- Minimum items: `1`
171+
- Unique items: `true`
168172

169173
### `definitions` (boolean)
170174

docs/rules/description-style.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# `description-style`
22

3-
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file enables this rule.
3+
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` property in a configuration file
4+
enables this rule.
45

5-
💡 This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
6+
💡 This rule provides
7+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
68

79
- Category: `Schema`
810
- Rule name: `@graphql-eslint/description-style`
911
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
10-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
12+
- Requires GraphQL Operations: `false`
13+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
1114

1215
Require all comments to follow the same style (either block or inline).
1316

docs/rules/executable-definitions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# `executable-definitions`
22

3-
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this rule.
3+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
4+
enables this rule.
45

56
- Category: `Operations`
67
- Rule name: `@graphql-eslint/executable-definitions`
78
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
8-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
9+
- Requires GraphQL Operations: `false`
10+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
911

10-
A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.
12+
A GraphQL document is only valid for execution if all definitions are either operation or fragment
13+
definitions.
1114

1215
> This rule is a wrapper around a `graphql-js` validation function.
1316

docs/rules/fields-on-correct-type.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# `fields-on-correct-type`
22

3-
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this rule.
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)
48

59
- Category: `Operations`
610
- Rule name: `@graphql-eslint/fields-on-correct-type`
711
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
8-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
12+
- Requires GraphQL Operations: `false`
13+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
914

10-
A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.
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`.
1117

1218
> This rule is a wrapper around a `graphql-js` validation function.
1319

docs/rules/fragments-on-composite-type.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# `fragments-on-composite-type`
22

3-
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this rule.
3+
✅ The `"extends": "plugin:@graphql-eslint/operations-recommended"` property in a configuration file
4+
enables this rule.
45

56
- Category: `Operations`
67
- Rule name: `@graphql-eslint/fragments-on-composite-type`
78
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
8-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
9+
- Requires GraphQL Operations: `false`
10+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
911

10-
Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.
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.
1114

1215
> This rule is a wrapper around a `graphql-js` validation function.
1316

docs/rules/input-name.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# `input-name`
22

3-
💡 This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
3+
💡 This rule provides
4+
[suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
45

56
- Category: `Schema`
67
- Rule name: `@graphql-eslint/input-name`
78
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
8-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
9+
- Requires GraphQL Operations: `false`
10+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
911

10-
Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".
11-
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.
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.
1216

1317
## Usage Examples
1418

docs/rules/known-argument-names.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# `known-argument-names`
22

3-
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` and `"plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this rule.
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)
49

510
- Category: `Schema & Operations`
611
- Rule name: `@graphql-eslint/known-argument-names`
712
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
8-
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
13+
- Requires GraphQL Operations: `false`
14+
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
915

1016
A GraphQL field is only valid if all supplied arguments are defined by that field.
1117

0 commit comments

Comments
 (0)