Skip to content

Commit

Permalink
add suggestions for graphql-js rules (#1314)
Browse files Browse the repository at this point in the history
* format

* format

* async

* refactor graphql-js functions

* it works

* changeset

* update generate-docs
  • Loading branch information
dimaMachina committed Dec 20, 2022
1 parent f05a562 commit a4f885a
Show file tree
Hide file tree
Showing 69 changed files with 1,318 additions and 564 deletions.
12 changes: 12 additions & 0 deletions .changeset/sour-windows-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@graphql-eslint/eslint-plugin': minor
---

add ESLint suggestions for following `graphql-js` rules:

- `fields-on-correct-type`
- `known-argument-names`
- `known-type-names`
- `possible-type-extension`
- `scalar-leafs`
- `value-literals-of-correct-type`
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dist/
docs/rules/
packages/plugin/tests/__snapshots__/
examples/prettier/invalid.graphql
examples/prettier/invalid.js
Expand Down
21 changes: 11 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Name            &nbs
[alphabetize](rules/alphabetize.md)|Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.|![all][]|🚀|🔧
[description-style](rules/description-style.md)|Require all comments to follow the same style (either block or inline).|![recommended][]|🚀|💡
[executable-definitions](rules/executable-definitions.md)|A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.|![recommended][]|🔮|
[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][]|🔮|
[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][]|🔮|💡
[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][]|🔮|
[input-name](rules/input-name.md)|Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".|![all][]|🚀|💡
[known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮|
[known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮|💡
[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][]|🔮|
[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][]|🔮|
[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][]|🔮|
[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][]|🔮|💡
[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][]|🔮|
[lone-schema-definition](rules/lone-schema-definition.md)|A GraphQL document is only valid if it contains only one schema definition.|![recommended][]|🔮|
[match-document-filename](rules/match-document-filename.md)|This rule allows you to enforce that the file name should match the operation name.|![all][]|🚀|
Expand All @@ -44,18 +44,18 @@ Name            &nbs
[one-field-subscriptions](rules/one-field-subscriptions.md)|A GraphQL subscription is valid only if it contains a single root field.|![recommended][]|🔮|
[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][]|🔮|
[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][]|🔮|
[possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.||🔮|
[possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.||🔮|💡
[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][]|🔮|
[relay-arguments](rules/relay-arguments.md)|Set of rules to follow Relay specification for Arguments.||🚀|
[relay-connection-types](rules/relay-connection-types.md)|Set of rules to follow Relay specification for Connection types.||🚀|
[relay-edge-types](rules/relay-edge-types.md)|Set of rules to follow Relay specification for Edge types.||🚀|
[relay-page-info](rules/relay-page-info.md)|Set of rules to follow Relay specification for `PageInfo` object.||🚀|
[relay-arguments](rules/relay-arguments.md)|Set of rules to follow Relay specification for Arguments.|![relay][]|🚀|
[relay-connection-types](rules/relay-connection-types.md)|Set of rules to follow Relay specification for Connection types.|![relay][]|🚀|
[relay-edge-types](rules/relay-edge-types.md)|Set of rules to follow Relay specification for Edge types.|![relay][]|🚀|
[relay-page-info](rules/relay-page-info.md)|Set of rules to follow Relay specification for `PageInfo` object.|![relay][]|🚀|
[require-deprecation-date](rules/require-deprecation-date.md)|Require deletion date on `@deprecated` directive. Suggest removing deprecated things after deprecated date.|![all][]|🚀|💡
[require-deprecation-reason](rules/require-deprecation-reason.md)|Require all deprecation directives to specify a reason.|![recommended][]|🚀|
[require-description](rules/require-description.md)|Enforce descriptions in type definitions and operations.|![recommended][]|🚀|
[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][]|🚀|
[require-id-when-available](rules/require-id-when-available.md)|Enforce selecting specific fields when they are available on the GraphQL type.|![recommended][]|🚀|💡
[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][]|🔮|
[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][]|🔮|💡
[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][]|🚀|💡
[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][]|🚀|
[unique-argument-names](rules/unique-argument-names.md)|A GraphQL field or directive is only valid if all supplied arguments are uniquely named.|![recommended][]|🔮|
Expand All @@ -69,10 +69,11 @@ Name            &nbs
[unique-operation-types](rules/unique-operation-types.md)|A GraphQL document is only valid if it has only one type per operation.|![recommended][]|🔮|
[unique-type-names](rules/unique-type-names.md)|A GraphQL document is only valid if all defined types have unique names.|![recommended][]|🔮|
[unique-variable-names](rules/unique-variable-names.md)|A GraphQL operation is only valid if all its variables are uniquely named.|![recommended][]|🔮|
[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][]|🔮|
[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][]|🔮|💡
[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][]|🔮|
[variables-in-allowed-position](rules/variables-in-allowed-position.md)|Variables passed to field arguments conform to type.|![recommended][]|🔮|
<!-- prettier-ignore-end -->

[recommended]: https://img.shields.io/badge/-recommended-green.svg
[all]: https://img.shields.io/badge/-all-blue.svg
[relay]: https://img.shields.io/badge/-relay-orange.svg
30 changes: 17 additions & 13 deletions docs/rules/alphabetize.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# `alphabetize`

🔧 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.
🔧 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.

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

Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.
Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation
selections and more.

## Usage Examples

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

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`
- Minimum items: `1`
- Unique items: `true`

### `values` (array)

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

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`
- Minimum items: `1`
- Unique items: `true`

### `selections` (array)

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

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`
- Minimum items: `1`
- Unique items: `true`

### `variables` (array)

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

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`
- Minimum items: `1`
- Unique items: `true`

### `arguments` (array)

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

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`
- Minimum items: `1`
- Unique items: `true`

### `definitions` (boolean)

Expand Down
9 changes: 6 additions & 3 deletions docs/rules/description-style.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# `description-style`

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

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

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

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

Expand Down
9 changes: 6 additions & 3 deletions docs/rules/executable-definitions.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# `executable-definitions`

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

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

A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.
A GraphQL document is only valid for execution if all definitions are either operation or fragment
definitions.

> This rule is a wrapper around a `graphql-js` validation function.
Expand Down
12 changes: 9 additions & 3 deletions docs/rules/fields-on-correct-type.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# `fields-on-correct-type`

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

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

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

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`.
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`.

> This rule is a wrapper around a `graphql-js` validation function.
Expand Down
9 changes: 6 additions & 3 deletions docs/rules/fragments-on-composite-type.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# `fragments-on-composite-type`

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

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

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.
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.

> This rule is a wrapper around a `graphql-js` validation function.
Expand Down
12 changes: 8 additions & 4 deletions docs/rules/input-name.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# `input-name`

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

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

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

## Usage Examples

Expand Down
10 changes: 8 additions & 2 deletions docs/rules/known-argument-names.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# `known-argument-names`

✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` and `"plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this rule.
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` and
`"plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this
rule.

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

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

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

Expand Down
14 changes: 9 additions & 5 deletions docs/rules/known-directives.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# `known-directives`

✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` and `"plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this rule.
✅ The `"extends": "plugin:@graphql-eslint/schema-recommended"` and
`"plugin:@graphql-eslint/operations-recommended"` property in a configuration file enables this
rule.

- Category: `Schema & Operations`
- Rule name: `@graphql-eslint/known-directives`
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
- Requires GraphQL Operations: `false`
[ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)

A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.
A GraphQL document is only valid if all `@directive`s are known by the schema and legally
positioned.

> This rule is a wrapper around a `graphql-js` validation function.
Expand Down Expand Up @@ -35,8 +39,8 @@ The object is an array with all elements of the type `string`.

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`
- Minimum items: `1`
- Unique items: `true`

## Resources

Expand Down

0 comments on commit a4f885a

Please sign in to comment.