Skip to content

Commit f428d46

Browse files
author
Dimitri POSTOLOV
authored
feat: improve generate-docs and types (#516)
1 parent e276552 commit f428d46

Some content is hidden

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

47 files changed

+241
-211
lines changed

.changeset/nasty-elephants-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
feat: improve generate-docs and types

docs/README.md

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
11
## Available Rules
22

33

4-
- [`avoid-typename-prefix`](./rules/avoid-typename-prefix.md)
5-
- [`no-unreachable-types`](./rules/no-unreachable-types.md)
6-
- [`no-unused-fields`](./rules/no-unused-fields.md)
7-
- [`no-deprecated`](./rules/no-deprecated.md)
8-
- [`unique-fragment-name`](./rules/unique-fragment-name.md)
9-
- [`unique-operation-name`](./rules/unique-operation-name.md)
10-
- [`no-hashtag-description`](./rules/no-hashtag-description.md)
11-
- [`no-anonymous-operations`](./rules/no-anonymous-operations.md)
12-
- [`no-operation-name-suffix`](./rules/no-operation-name-suffix.md)
13-
- [`require-deprecation-reason`](./rules/require-deprecation-reason.md)
14-
- [`avoid-operation-name-prefix`](./rules/avoid-operation-name-prefix.md)
15-
- [`selection-set-depth`](./rules/selection-set-depth.md)
16-
- [`no-case-insensitive-enum-values-duplicates`](./rules/no-case-insensitive-enum-values-duplicates.md)
17-
- [`require-description`](./rules/require-description.md)
18-
- [`require-id-when-available`](./rules/require-id-when-available.md)
19-
- [`description-style`](./rules/description-style.md)
20-
- [`avoid-duplicate-fields`](./rules/avoid-duplicate-fields.md)
21-
- [`naming-convention`](./rules/naming-convention.md)
22-
- [`input-name`](./rules/input-name.md)
23-
- [`strict-id-in-types`](./rules/strict-id-in-types.md)
24-
- [`executable-definitions`](./rules/executable-definitions.md)
25-
- [`fields-on-correct-type`](./rules/fields-on-correct-type.md)
26-
- [`fragments-on-composite-type`](./rules/fragments-on-composite-type.md)
27-
- [`known-argument-names`](./rules/known-argument-names.md)
28-
- [`known-directives`](./rules/known-directives.md)
29-
- [`known-fragment-names`](./rules/known-fragment-names.md)
30-
- [`known-type-names`](./rules/known-type-names.md)
31-
- [`lone-anonymous-operation`](./rules/lone-anonymous-operation.md)
32-
- [`lone-schema-definition`](./rules/lone-schema-definition.md)
33-
- [`no-fragment-cycles`](./rules/no-fragment-cycles.md)
34-
- [`no-undefined-variables`](./rules/no-undefined-variables.md)
35-
- [`no-unused-fragments`](./rules/no-unused-fragments.md)
36-
- [`no-unused-variables`](./rules/no-unused-variables.md)
37-
- [`overlapping-fields-can-be-merged`](./rules/overlapping-fields-can-be-merged.md)
38-
- [`possible-fragment-spread`](./rules/possible-fragment-spread.md)
39-
- [`possible-type-extension`](./rules/possible-type-extension.md)
40-
- [`provided-required-arguments`](./rules/provided-required-arguments.md)
41-
- [`scalar-leafs`](./rules/scalar-leafs.md)
42-
- [`one-field-subscriptions`](./rules/one-field-subscriptions.md)
43-
- [`unique-argument-names`](./rules/unique-argument-names.md)
44-
- [`unique-directive-names`](./rules/unique-directive-names.md)
45-
- [`unique-directive-names-per-location`](./rules/unique-directive-names-per-location.md)
46-
- [`unique-enum-value-names`](./rules/unique-enum-value-names.md)
47-
- [`unique-field-definition-names`](./rules/unique-field-definition-names.md)
48-
- [`unique-input-field-names`](./rules/unique-input-field-names.md)
49-
- [`unique-operation-types`](./rules/unique-operation-types.md)
50-
- [`unique-type-names`](./rules/unique-type-names.md)
51-
- [`unique-variable-names`](./rules/unique-variable-names.md)
52-
- [`value-literals-of-correct-type`](./rules/value-literals-of-correct-type.md)
53-
- [`variables-are-input-types`](./rules/variables-are-input-types.md)
54-
- [`variables-in-allowed-position`](./rules/variables-in-allowed-position.md)
4+
Each rule has emojis denoting:
5+
6+
* 🚀 `@graphql-eslint` rule
7+
* 🔮 `graphql-js` rule
8+
* 🔧 if some problems reported by the rule are automatically fixable by the `--fix` [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) option
9+
10+
<!-- Do not manually modify this table. Run: `yarn generate:docs` -->
11+
<!-- RULES_TABLE_START -->
12+
| Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Description | 🚀&nbsp;/&nbsp;🔮 | 🔧 |
13+
| :-- | :-- | :-- | :-- |
14+
| [avoid-duplicate-fields](rules/avoid-duplicate-fields.md) | Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field. | &nbsp;&nbsp;&nbsp;🚀 | |
15+
| [avoid-operation-name-prefix](rules/avoid-operation-name-prefix.md) | Enforce/avoid operation name prefix, useful if you wish to avoid prefix in your root fields, or avoid using REST terminology in your schema. | &nbsp;&nbsp;&nbsp;🚀 | |
16+
| [avoid-typename-prefix](rules/avoid-typename-prefix.md) | Enforces users to avoid using the type name in a field name while defining your schema. | &nbsp;&nbsp;&nbsp;🚀 | |
17+
| [description-style](rules/description-style.md) | Require all comments to follow the same style (either block or inline). | &nbsp;&nbsp;&nbsp;🚀 | |
18+
| [executable-definitions](rules/executable-definitions.md) | A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions. | &nbsp;&nbsp;&nbsp;🔮 | |
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`. | &nbsp;&nbsp;&nbsp;🔮 | |
20+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
21+
| [input-name](rules/input-name.md) | Require mutation argument to be always called "input" and input type to be called Mutation name + "Input". | &nbsp;&nbsp;&nbsp;🚀 | |
22+
| [known-argument-names](rules/known-argument-names.md) | A GraphQL field is only valid if all supplied arguments are defined by that field. | &nbsp;&nbsp;&nbsp;🔮 | |
23+
| [known-directives](rules/known-directives.md) | A GraphQL document is only valid if all `@directives` are known by the schema and legally positioned. | &nbsp;&nbsp;&nbsp;🔮 | |
24+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
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. | &nbsp;&nbsp;&nbsp;🔮 | |
26+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
27+
| [lone-schema-definition](rules/lone-schema-definition.md) | A GraphQL document is only valid if it contains only one schema definition. | &nbsp;&nbsp;&nbsp;🔮 | |
28+
| [naming-convention](rules/naming-convention.md) | Require names to follow specified conventions. | &nbsp;&nbsp;&nbsp;🚀 | |
29+
| [no-anonymous-operations](rules/no-anonymous-operations.md) | Require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes. | &nbsp;&nbsp;&nbsp;🚀 | |
30+
| [no-case-insensitive-enum-values-duplicates](rules/no-case-insensitive-enum-values-duplicates.md) | | &nbsp;&nbsp;&nbsp;🚀 | 🔧 |
31+
| [no-deprecated](rules/no-deprecated.md) | This rule allow you to enforce that deprecated fields or enum values are not in use by operations. | &nbsp;&nbsp;&nbsp;🚀 | |
32+
| [no-fragment-cycles](rules/no-fragment-cycles.md) | A GraphQL fragment is only valid when it does not have cycles in fragments usage. | &nbsp;&nbsp;&nbsp;🔮 | |
33+
| [no-hashtag-description](rules/no-hashtag-description.md) | Requires to use `"""` or `"` for adding a GraphQL description instead of `#`. | &nbsp;&nbsp;&nbsp;🚀 | |
34+
| [no-operation-name-suffix](rules/no-operation-name-suffix.md) | Makes sure you are not adding the operation type to the name of the operation. | &nbsp;&nbsp;&nbsp;🚀 | 🔧 |
35+
| [no-undefined-variables](rules/no-undefined-variables.md) | A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation. | &nbsp;&nbsp;&nbsp;🔮 | |
36+
| [no-unreachable-types](rules/no-unreachable-types.md) | Requires all types to be reachable at some level by root level fields. | &nbsp;&nbsp;&nbsp;🚀 | 🔧 |
37+
| [no-unused-fields](rules/no-unused-fields.md) | Requires all fields to be used at some level by siblings operations. | &nbsp;&nbsp;&nbsp;🚀 | 🔧 |
38+
| [no-unused-fragments](rules/no-unused-fragments.md) | A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations. | &nbsp;&nbsp;&nbsp;🔮 | |
39+
| [no-unused-variables](rules/no-unused-variables.md) | A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment. | &nbsp;&nbsp;&nbsp;🔮 | |
40+
| [one-field-subscriptions](rules/one-field-subscriptions.md) | A GraphQL subscription is valid only if it contains a single root field. | &nbsp;&nbsp;&nbsp;🔮 | |
41+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
42+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
43+
| [possible-type-extension](rules/possible-type-extension.md) | A type extension is only valid if the type is defined and has the same kind. | &nbsp;&nbsp;&nbsp;🔮 | |
44+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
45+
| [require-deprecation-reason](rules/require-deprecation-reason.md) | Require all deprecation directives to specify a reason. | &nbsp;&nbsp;&nbsp;🚀 | |
46+
| [require-description](rules/require-description.md) | Enforce descriptions in your type definitions. | &nbsp;&nbsp;&nbsp;🚀 | |
47+
| [require-id-when-available](rules/require-id-when-available.md) | This rule allow you to enforce selecting specific fields when they are available on the GraphQL type. | &nbsp;&nbsp;&nbsp;🚀 | |
48+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
49+
| [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://github.com/stems/graphql-depth-limit). | &nbsp;&nbsp;&nbsp;🚀 | |
50+
| [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. | &nbsp;&nbsp;&nbsp;🚀 | |
51+
| [unique-argument-names](rules/unique-argument-names.md) | A GraphQL field or directive is only valid if all supplied arguments are uniquely named. | &nbsp;&nbsp;&nbsp;🔮 | |
52+
| [unique-directive-names](rules/unique-directive-names.md) | A GraphQL document is only valid if all defined directives have unique names. | &nbsp;&nbsp;&nbsp;🔮 | |
53+
| [unique-directive-names-per-location](rules/unique-directive-names-per-location.md) | A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named. | &nbsp;&nbsp;&nbsp;🔮 | |
54+
| [unique-enum-value-names](rules/unique-enum-value-names.md) | A GraphQL enum type is only valid if all its values are uniquely named. | &nbsp;&nbsp;&nbsp;🔮 | |
55+
| [unique-field-definition-names](rules/unique-field-definition-names.md) | A GraphQL complex type is only valid if all its fields are uniquely named. | &nbsp;&nbsp;&nbsp;🔮 | |
56+
| [unique-fragment-name](rules/unique-fragment-name.md) | This rule allow you to enforce unique fragment name across your application. | &nbsp;&nbsp;&nbsp;🚀 | |
57+
| [unique-input-field-names](rules/unique-input-field-names.md) | A GraphQL input object value is only valid if all supplied fields are uniquely named. | &nbsp;&nbsp;&nbsp;🔮 | |
58+
| [unique-operation-name](rules/unique-operation-name.md) | This rule allow you to enforce unique operation names across your project. | &nbsp;&nbsp;&nbsp;🚀 | |
59+
| [unique-operation-types](rules/unique-operation-types.md) | A GraphQL document is only valid if it has only one type per operation. | &nbsp;&nbsp;&nbsp;🔮 | |
60+
| [unique-type-names](rules/unique-type-names.md) | A GraphQL document is only valid if all defined types have unique names. | &nbsp;&nbsp;&nbsp;🔮 | |
61+
| [unique-variable-names](rules/unique-variable-names.md) | A GraphQL operation is only valid if all its variables are uniquely named. | &nbsp;&nbsp;&nbsp;🔮 | |
62+
| [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. | &nbsp;&nbsp;&nbsp;🔮 | |
63+
| [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). | &nbsp;&nbsp;&nbsp;🔮 | |
64+
| [variables-in-allowed-position](rules/variables-in-allowed-position.md) | Variables passed to field arguments conform to type. | &nbsp;&nbsp;&nbsp;🔮 | |
65+
<!-- RULES_TABLE_END -->
5566

5667
## Further Reading
5768

58-
- [Writing Custom Rules](./custom-rules.md)
59-
- [How the parser works?](./parser.md)
60-
- [`parserOptions`](./parser-options.md)
69+
- [Writing Custom Rules](custom-rules.md)
70+
- [How the parser works?](parser.md)
71+
- [`parserOptions`](parser-options.md)

docs/rules/avoid-duplicate-fields.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Checks for duplicate fields in selection set, variables in operation definition,
1212
### Incorrect
1313

1414
```graphql
15-
# eslint @graphql-eslint/avoid-duplicate-fields: ["error"]
15+
# eslint @graphql-eslint/avoid-duplicate-fields: 'error'
1616

1717
query getUserDetails {
1818
user {
@@ -26,7 +26,7 @@ query getUserDetails {
2626
### Incorrect
2727

2828
```graphql
29-
# eslint @graphql-eslint/avoid-duplicate-fields: ["error"]
29+
# eslint @graphql-eslint/avoid-duplicate-fields: 'error'
3030

3131
query getUsers {
3232
users(
@@ -43,7 +43,7 @@ query getUsers {
4343
### Incorrect
4444

4545
```graphql
46-
# eslint @graphql-eslint/avoid-duplicate-fields: ["error"]
46+
# eslint @graphql-eslint/avoid-duplicate-fields: 'error'
4747

4848
query getUsers($first: Int!, $first: Int!) {
4949
# Duplicate variable

docs/rules/avoid-operation-name-prefix.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
66
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
77

8-
Enforce/avoid operation name prefix, useful if you wish to avoid prefix in your root fields, or avoid using REST terminology in your schema
8+
Enforce/avoid operation name prefix, useful if you wish to avoid prefix in your root fields, or avoid using REST terminology in your schema.
99

1010
## Usage Examples
1111

1212
### Incorrect
1313

1414
```graphql
15-
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", {"keywords":["get"]}]
15+
# eslint @graphql-eslint/avoid-operation-name-prefix: ['error', { keywords: ['get'] }]
1616

1717
query getUserDetails {
1818
# ...
@@ -22,7 +22,7 @@ query getUserDetails {
2222
### Correct
2323

2424
```graphql
25-
# eslint @graphql-eslint/avoid-operation-name-prefix: ["error", {"keywords":["get"]}]
25+
# eslint @graphql-eslint/avoid-operation-name-prefix: ['error', { keywords: ['get'] }]
2626

2727
query userDetails {
2828
# ...

docs/rules/avoid-typename-prefix.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Enforces users to avoid using the type name in a field name while defining your
1212
### Incorrect
1313

1414
```graphql
15-
# eslint @graphql-eslint/avoid-typename-prefix: ["error"]
15+
# eslint @graphql-eslint/avoid-typename-prefix: 'error'
1616

1717
type User {
1818
userId: ID!
@@ -22,7 +22,7 @@ type User {
2222
### Correct
2323

2424
```graphql
25-
# eslint @graphql-eslint/avoid-typename-prefix: ["error"]
25+
# eslint @graphql-eslint/avoid-typename-prefix: 'error'
2626

2727
type User {
2828
id: ID!

docs/rules/description-style.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
66
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
77

8-
Require all comments to follow the same style (either block or inline)
8+
Require all comments to follow the same style (either block or inline).
99

1010
## Usage Examples
1111

1212
### Incorrect
1313

1414
```graphql
15-
# eslint @graphql-eslint/description-style: ["error", {"style":"inline"}]
15+
# eslint @graphql-eslint/description-style: ['error', { style: 'inline' }]
1616

1717
""" Description """
1818
type someTypeName {
@@ -23,7 +23,7 @@ type someTypeName {
2323
### Correct
2424

2525
```graphql
26-
# eslint @graphql-eslint/description-style: ["error", {"style":"inline"}]
26+
# eslint @graphql-eslint/description-style: ['error', { style: 'inline' }]
2727

2828
" Description "
2929
type someTypeName {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
66
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
77

8-
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.
8+
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`.
99

1010
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/FieldsOnCorrectTypeRule.ts).

docs/rules/input-name.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Using the same name for all input parameters will make your schemas easier to co
1313
### Incorrect
1414

1515
```graphql
16-
# eslint @graphql-eslint/input-name: ["error", {"checkInputType":true}]
16+
# eslint @graphql-eslint/input-name: ['error', { checkInputType: true }]
1717

1818
type Mutation {
1919
SetMessage(message: InputMessage): String
@@ -23,7 +23,7 @@ type Mutation {
2323
### Correct (with checkInputType)
2424

2525
```graphql
26-
# eslint @graphql-eslint/input-name: ["error", {"checkInputType":true}]
26+
# eslint @graphql-eslint/input-name: ['error', { checkInputType: true }]
2727

2828
type Mutation {
2929
SetMessage(input: SetMessageInput): String
@@ -33,7 +33,7 @@ type Mutation {
3333
### Correct (without checkInputType)
3434

3535
```graphql
36-
# eslint @graphql-eslint/input-name: ["error", {"checkInputType":false}]
36+
# eslint @graphql-eslint/input-name: ['error', { checkInputType: false }]
3737

3838
type Mutation {
3939
SetMessage(input: AnyInputTypeName): String

docs/rules/known-fragment-names.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A GraphQL document is only valid if all `...Fragment` fragment spreads refer to
1414
### Incorrect (fragment not defined in the document)
1515

1616
```graphql
17-
# eslint @graphql-eslint/known-fragment-names: ["error"]
17+
# eslint @graphql-eslint/known-fragment-names: 'error'
1818

1919
query {
2020
user {
@@ -27,7 +27,7 @@ query {
2727
### Correct
2828

2929
```graphql
30-
# eslint @graphql-eslint/known-fragment-names: ["error"]
30+
# eslint @graphql-eslint/known-fragment-names: 'error'
3131

3232
fragment UserFields on User {
3333
firstName
@@ -45,7 +45,7 @@ query {
4545
### Correct (existing import to UserFields fragment)
4646

4747
```graphql
48-
# eslint @graphql-eslint/known-fragment-names: ["error"]
48+
# eslint @graphql-eslint/known-fragment-names: 'error'
4949

5050
#import '../UserFields.gql'
5151

0 commit comments

Comments
 (0)