@graphql-eslint/eslint-plugin 2.5.0-alpha-14532ce.0 → 3.0.0-alpha-069461d.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/configs/all.d.ts CHANGED
@@ -15,6 +15,9 @@ export declare const allConfig: {
15
15
  '@graphql-eslint/match-document-filename': string;
16
16
  '@graphql-eslint/no-deprecated': string;
17
17
  '@graphql-eslint/no-hashtag-description': string;
18
+ '@graphql-eslint/no-root-type': (string | {
19
+ disallow: string[];
20
+ })[];
18
21
  '@graphql-eslint/no-unreachable-types': string;
19
22
  '@graphql-eslint/no-unused-fields': string;
20
23
  '@graphql-eslint/require-deprecation-date': string;
@@ -34,7 +37,35 @@ export declare const allConfig: {
34
37
  '@graphql-eslint/known-type-names': string;
35
38
  '@graphql-eslint/lone-anonymous-operation': string;
36
39
  '@graphql-eslint/lone-schema-definition': string;
37
- '@graphql-eslint/naming-convention': string;
40
+ '@graphql-eslint/naming-convention': (string | {
41
+ types: string;
42
+ fields: string;
43
+ overrides: {
44
+ EnumValueDefinition: string;
45
+ OperationDefinition: {
46
+ style: string;
47
+ forbiddenPrefixes: string[];
48
+ forbiddenSuffixes: string[];
49
+ };
50
+ FragmentDefinition: {
51
+ style: string;
52
+ forbiddenPrefixes: string[];
53
+ forbiddenSuffixes: string[];
54
+ };
55
+ 'FieldDefinition[parent.name.value=Query]': {
56
+ forbiddenPrefixes: string[];
57
+ forbiddenSuffixes: string[];
58
+ };
59
+ 'FieldDefinition[parent.name.value=Mutation]': {
60
+ forbiddenPrefixes: string[];
61
+ forbiddenSuffixes: string[];
62
+ };
63
+ 'FieldDefinition[parent.name.value=Subscription]': {
64
+ forbiddenPrefixes: string[];
65
+ forbiddenSuffixes: string[];
66
+ };
67
+ };
68
+ })[];
38
69
  '@graphql-eslint/no-anonymous-operations': string;
39
70
  '@graphql-eslint/no-case-insensitive-enum-values-duplicates': string;
40
71
  '@graphql-eslint/no-fragment-cycles': string;
@@ -16,6 +16,9 @@ export declare const configs: {
16
16
  '@graphql-eslint/match-document-filename': string;
17
17
  '@graphql-eslint/no-deprecated': string;
18
18
  '@graphql-eslint/no-hashtag-description': string;
19
+ '@graphql-eslint/no-root-type': (string | {
20
+ disallow: string[];
21
+ })[];
19
22
  '@graphql-eslint/no-unreachable-types': string;
20
23
  '@graphql-eslint/no-unused-fields': string;
21
24
  '@graphql-eslint/require-deprecation-date': string;
@@ -35,7 +38,35 @@ export declare const configs: {
35
38
  '@graphql-eslint/known-type-names': string;
36
39
  '@graphql-eslint/lone-anonymous-operation': string;
37
40
  '@graphql-eslint/lone-schema-definition': string;
38
- '@graphql-eslint/naming-convention': string;
41
+ '@graphql-eslint/naming-convention': (string | {
42
+ types: string;
43
+ fields: string;
44
+ overrides: {
45
+ EnumValueDefinition: string;
46
+ OperationDefinition: {
47
+ style: string;
48
+ forbiddenPrefixes: string[];
49
+ forbiddenSuffixes: string[];
50
+ };
51
+ FragmentDefinition: {
52
+ style: string;
53
+ forbiddenPrefixes: string[];
54
+ forbiddenSuffixes: string[];
55
+ };
56
+ 'FieldDefinition[parent.name.value=Query]': {
57
+ forbiddenPrefixes: string[];
58
+ forbiddenSuffixes: string[];
59
+ };
60
+ 'FieldDefinition[parent.name.value=Mutation]': {
61
+ forbiddenPrefixes: string[];
62
+ forbiddenSuffixes: string[];
63
+ };
64
+ 'FieldDefinition[parent.name.value=Subscription]': {
65
+ forbiddenPrefixes: string[];
66
+ forbiddenSuffixes: string[];
67
+ };
68
+ };
69
+ })[];
39
70
  '@graphql-eslint/no-anonymous-operations': string;
40
71
  '@graphql-eslint/no-case-insensitive-enum-values-duplicates': string;
41
72
  '@graphql-eslint/no-fragment-cycles': string;
@@ -81,7 +112,35 @@ export declare const configs: {
81
112
  '@graphql-eslint/known-type-names': string;
82
113
  '@graphql-eslint/lone-anonymous-operation': string;
83
114
  '@graphql-eslint/lone-schema-definition': string;
84
- '@graphql-eslint/naming-convention': string;
115
+ '@graphql-eslint/naming-convention': (string | {
116
+ types: string;
117
+ fields: string;
118
+ overrides: {
119
+ EnumValueDefinition: string;
120
+ OperationDefinition: {
121
+ style: string;
122
+ forbiddenPrefixes: string[];
123
+ forbiddenSuffixes: string[];
124
+ };
125
+ FragmentDefinition: {
126
+ style: string;
127
+ forbiddenPrefixes: string[];
128
+ forbiddenSuffixes: string[];
129
+ };
130
+ 'FieldDefinition[parent.name.value=Query]': {
131
+ forbiddenPrefixes: string[];
132
+ forbiddenSuffixes: string[];
133
+ };
134
+ 'FieldDefinition[parent.name.value=Mutation]': {
135
+ forbiddenPrefixes: string[];
136
+ forbiddenSuffixes: string[];
137
+ };
138
+ 'FieldDefinition[parent.name.value=Subscription]': {
139
+ forbiddenPrefixes: string[];
140
+ forbiddenSuffixes: string[];
141
+ };
142
+ };
143
+ })[];
85
144
  '@graphql-eslint/no-anonymous-operations': string;
86
145
  '@graphql-eslint/no-case-insensitive-enum-values-duplicates': string;
87
146
  '@graphql-eslint/no-fragment-cycles': string;
@@ -12,7 +12,35 @@ export declare const recommendedConfig: {
12
12
  '@graphql-eslint/known-type-names': string;
13
13
  '@graphql-eslint/lone-anonymous-operation': string;
14
14
  '@graphql-eslint/lone-schema-definition': string;
15
- '@graphql-eslint/naming-convention': string;
15
+ '@graphql-eslint/naming-convention': (string | {
16
+ types: string;
17
+ fields: string;
18
+ overrides: {
19
+ EnumValueDefinition: string;
20
+ OperationDefinition: {
21
+ style: string;
22
+ forbiddenPrefixes: string[];
23
+ forbiddenSuffixes: string[];
24
+ };
25
+ FragmentDefinition: {
26
+ style: string;
27
+ forbiddenPrefixes: string[];
28
+ forbiddenSuffixes: string[];
29
+ };
30
+ 'FieldDefinition[parent.name.value=Query]': {
31
+ forbiddenPrefixes: string[];
32
+ forbiddenSuffixes: string[];
33
+ };
34
+ 'FieldDefinition[parent.name.value=Mutation]': {
35
+ forbiddenPrefixes: string[];
36
+ forbiddenSuffixes: string[];
37
+ };
38
+ 'FieldDefinition[parent.name.value=Subscription]': {
39
+ forbiddenPrefixes: string[];
40
+ forbiddenSuffixes: string[];
41
+ };
42
+ };
43
+ })[];
16
44
  '@graphql-eslint/no-anonymous-operations': string;
17
45
  '@graphql-eslint/no-case-insensitive-enum-values-duplicates': string;
18
46
  '@graphql-eslint/no-fragment-cycles': string;
package/docs/README.md CHANGED
@@ -35,6 +35,7 @@ Name            &nbs
35
35
  [no-fragment-cycles](rules/no-fragment-cycles.md)|A GraphQL fragment is only valid when it does not have cycles in fragments usage.|🔮||✅
36
36
  [no-hashtag-description](rules/no-hashtag-description.md)|Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.|🚀||
37
37
  [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.|🚀|🔧|✅
38
+ [no-root-type](rules/no-root-type.md)|Disallow using root types for `read-only` or `write-only` schemas.|🚀||
38
39
  [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.|🔮||✅
39
40
  [no-unreachable-types](rules/no-unreachable-types.md)|Requires all types to be reachable at some level by root level fields.|🚀|🔧|
40
41
  [no-unused-fields](rules/no-unused-fields.md)|Requires all fields to be used at some level by siblings operations.|🚀|🔧|
@@ -95,50 +95,75 @@ The schema defines the following properties:
95
95
 
96
96
  ### `fields` (array)
97
97
 
98
- Fields of `type`, `interface`, and `input`.
98
+ Fields of `type`, `interface`, and `input`
99
99
 
100
- The elements of the array must contain the following properties:
100
+ The elements of the array can contain the following enum values:
101
101
 
102
102
  - `ObjectTypeDefinition`
103
103
  - `InterfaceTypeDefinition`
104
104
  - `InputObjectTypeDefinition`
105
105
 
106
+ Additional restrictions:
107
+
108
+ * Minimum items: `1`
109
+ * Unique items: `true`
110
+
106
111
  ### `values` (array)
107
112
 
108
- Values of `enum`.
113
+ Values of `enum`
109
114
 
110
- The elements of the array must contain the following properties:
115
+ The elements of the array can contain the following enum values:
111
116
 
112
117
  - `EnumTypeDefinition`
113
118
 
119
+ Additional restrictions:
120
+
121
+ * Minimum items: `1`
122
+ * Unique items: `true`
123
+
114
124
  ### `selections` (array)
115
125
 
116
- Selections of operations (`query`, `mutation` and `subscription`) and `fragment`.
126
+ Selections of operations (`query`, `mutation` and `subscription`) and `fragment`
117
127
 
118
- The elements of the array must contain the following properties:
128
+ The elements of the array can contain the following enum values:
119
129
 
120
130
  - `OperationDefinition`
121
131
  - `FragmentDefinition`
122
132
 
133
+ Additional restrictions:
134
+
135
+ * Minimum items: `1`
136
+ * Unique items: `true`
137
+
123
138
  ### `variables` (array)
124
139
 
125
- Variables of operations (`query`, `mutation` and `subscription`).
140
+ Variables of operations (`query`, `mutation` and `subscription`)
126
141
 
127
- The elements of the array must contain the following properties:
142
+ The elements of the array can contain the following enum values:
128
143
 
129
144
  - `OperationDefinition`
130
145
 
146
+ Additional restrictions:
147
+
148
+ * Minimum items: `1`
149
+ * Unique items: `true`
150
+
131
151
  ### `arguments` (array)
132
152
 
133
- Arguments of fields and directives.
153
+ Arguments of fields and directives
134
154
 
135
- The elements of the array must contain the following properties:
155
+ The elements of the array can contain the following enum values:
136
156
 
137
157
  - `FieldDefinition`
138
158
  - `Field`
139
159
  - `DirectiveDefinition`
140
160
  - `Directive`
141
161
 
162
+ Additional restrictions:
163
+
164
+ * Minimum items: `1`
165
+ * Unique items: `true`
166
+
142
167
  ## Resources
143
168
 
144
169
  - [Rule source](../../packages/plugin/src/rules/alphabetize.ts)
@@ -39,8 +39,8 @@ The schema defines the following properties:
39
39
 
40
40
  This element must be one of the following enum values:
41
41
 
42
- * `block`
43
- * `inline`
42
+ - `block`
43
+ - `inline`
44
44
 
45
45
  Default: `"inline"`
46
46
 
@@ -92,8 +92,8 @@ The schema defines the following properties:
92
92
 
93
93
  This element must be one of the following enum values:
94
94
 
95
- * `.gql`
96
- * `.graphql`
95
+ - `.gql`
96
+ - `.graphql`
97
97
 
98
98
  ### `query`
99
99
 
@@ -141,11 +141,11 @@ Properties of the `asObject` object:
141
141
 
142
142
  This element must be one of the following enum values:
143
143
 
144
- * `camelCase`
145
- * `PascalCase`
146
- * `snake_case`
147
- * `UPPER_CASE`
148
- * `kebab-case`
144
+ - `camelCase`
145
+ - `PascalCase`
146
+ - `snake_case`
147
+ - `UPPER_CASE`
148
+ - `kebab-case`
149
149
 
150
150
  ## Resources
151
151
 
@@ -14,20 +14,20 @@ Require names to follow specified conventions.
14
14
  ### Incorrect
15
15
 
16
16
  ```graphql
17
- # eslint @graphql-eslint/naming-convention: ['error', { ObjectTypeDefinition: 'PascalCase' }]
17
+ # eslint @graphql-eslint/naming-convention: ['error', { types: 'PascalCase', fields: 'camelCase' }]
18
18
 
19
- type someTypeName {
20
- f: String!
19
+ type user {
20
+ first_name: String!
21
21
  }
22
22
  ```
23
23
 
24
24
  ### Correct
25
25
 
26
26
  ```graphql
27
- # eslint @graphql-eslint/naming-convention: ['error', { FieldDefinition: 'camelCase', ObjectTypeDefinition: 'PascalCase' }]
27
+ # eslint @graphql-eslint/naming-convention: ['error', { types: 'PascalCase', fields: 'camelCase' }]
28
28
 
29
- type SomeTypeName {
30
- someFieldName: String
29
+ type User {
30
+ firstName: String
31
31
  }
32
32
  ```
33
33
 
@@ -35,115 +35,84 @@ type SomeTypeName {
35
35
 
36
36
  The schema defines the following properties:
37
37
 
38
- ### `FieldDefinition`
38
+ ### `types`
39
39
 
40
- The object must be one of the following types:
41
-
42
- * `asString`
43
- * `asObject`
40
+ Includes:
44
41
 
45
- ### `InputObjectTypeDefinition`
42
+ - `ObjectTypeDefinition`
43
+ - `InterfaceTypeDefinition`
44
+ - `EnumTypeDefinition`
45
+ - `ScalarTypeDefinition`
46
+ - `InputObjectTypeDefinition`
47
+ - `UnionTypeDefinition`
46
48
 
47
49
  The object must be one of the following types:
48
50
 
49
51
  * `asString`
50
52
  * `asObject`
51
53
 
52
- ### `EnumValueDefinition`
54
+ ### `fields`
53
55
 
54
- The object must be one of the following types:
55
-
56
- * `asString`
57
- * `asObject`
58
-
59
- ### `InputValueDefinition`
60
-
61
- The object must be one of the following types:
62
-
63
- * `asString`
64
- * `asObject`
56
+ Includes:
65
57
 
66
- ### `ObjectTypeDefinition`
58
+ - `FieldDefinition`
59
+ - `InputValueDefinition`
60
+ - `VariableDefinition`
61
+ - `Argument`
62
+ - `DirectiveDefinition`
67
63
 
68
64
  The object must be one of the following types:
69
65
 
70
66
  * `asString`
71
67
  * `asObject`
72
68
 
73
- ### `InterfaceTypeDefinition`
69
+ ### `allowLeadingUnderscore` (boolean)
74
70
 
75
- The object must be one of the following types:
71
+ Default: `false`
76
72
 
77
- * `asString`
78
- * `asObject`
73
+ ### `allowTrailingUnderscore` (boolean)
79
74
 
80
- ### `EnumTypeDefinition`
75
+ Default: `false`
81
76
 
82
- The object must be one of the following types:
77
+ ### `overrides` (object)
83
78
 
84
- * `asString`
85
- * `asObject`
79
+ May contain the following `ASTNode` names:
86
80
 
87
- ### `UnionTypeDefinition`
81
+ - `Argument`
82
+ - `DirectiveDefinition`
83
+ - `EnumTypeDefinition`
84
+ - `EnumValueDefinition`
85
+ - `FieldDefinition`
86
+ - `FragmentDefinition`
87
+ - `InputObjectTypeDefinition`
88
+ - `InputValueDefinition`
89
+ - `InterfaceTypeDefinition`
90
+ - `ObjectTypeDefinition`
91
+ - `OperationDefinition`
92
+ - `ScalarTypeDefinition`
93
+ - `UnionTypeDefinition`
94
+ - `VariableDefinition`
88
95
 
89
- The object must be one of the following types:
96
+ > It's also possible to use a [`selector`](https://eslint.org/docs/developer-guide/selectors) that starts with `ASTNode` name
97
+ >
98
+ > Example: pattern property `FieldDefinition[parent.name.value=Query]` will match only fields for type `Query`
90
99
 
91
- * `asString`
92
- * `asObject`
100
+ Pattern properties of the `overrides` object:
93
101
 
94
- ### `ScalarTypeDefinition`
102
+ #### `^(Argument|DirectiveDefinition|EnumTypeDefinition|EnumValueDefinition|FieldDefinition|FragmentDefinition|InputObjectTypeDefinition|InputValueDefinition|InterfaceTypeDefinition|ObjectTypeDefinition|OperationDefinition|ScalarTypeDefinition|UnionTypeDefinition|VariableDefinition)(.+)?$`
95
103
 
96
104
  The object must be one of the following types:
97
105
 
98
106
  * `asString`
99
107
  * `asObject`
100
108
 
101
- ### `OperationDefinition`
102
-
103
- The object must be one of the following types:
104
-
105
- * `asString`
106
- * `asObject`
107
-
108
- ### `FragmentDefinition`
109
-
110
- The object must be one of the following types:
111
-
112
- * `asString`
113
- * `asObject`
114
-
115
- ### `QueryDefinition`
116
-
117
- The object must be one of the following types:
118
-
119
- * `asString`
120
- * `asObject`
121
-
122
- ### `leadingUnderscore` (string, enum)
123
-
124
- This element must be one of the following enum values:
125
-
126
- * `allow`
127
- * `forbid`
128
-
129
- Default: `"forbid"`
130
-
131
- ### `trailingUnderscore` (string, enum)
132
-
133
- This element must be one of the following enum values:
134
-
135
- * `allow`
136
- * `forbid`
137
-
138
- Default: `"forbid"`
139
-
140
109
  ---
141
110
 
142
111
  # Sub Schemas
143
112
 
144
113
  The schema defines the following additional types:
145
114
 
146
- ## `asString` (string)
115
+ ## `asString` (enum)
147
116
 
148
117
  One of: `camelCase`, `PascalCase`, `snake_case`, `UPPER_CASE`
149
118
 
@@ -151,14 +120,14 @@ One of: `camelCase`, `PascalCase`, `snake_case`, `UPPER_CASE`
151
120
 
152
121
  Properties of the `asObject` object:
153
122
 
154
- ### `style` (string, enum)
123
+ ### `style` (enum)
155
124
 
156
125
  This element must be one of the following enum values:
157
126
 
158
- * `camelCase`
159
- * `PascalCase`
160
- * `snake_case`
161
- * `UPPER_CASE`
127
+ - `camelCase`
128
+ - `PascalCase`
129
+ - `snake_case`
130
+ - `UPPER_CASE`
162
131
 
163
132
  ### `prefix` (string)
164
133
 
@@ -171,6 +140,7 @@ The object is an array with all elements of the type `string`.
171
140
  Additional restrictions:
172
141
 
173
142
  * Minimum items: `1`
143
+ * Unique items: `true`
174
144
 
175
145
  ### `forbiddenSuffixes` (array)
176
146
 
@@ -179,6 +149,7 @@ The object is an array with all elements of the type `string`.
179
149
  Additional restrictions:
180
150
 
181
151
  * Minimum items: `1`
152
+ * Unique items: `true`
182
153
 
183
154
  ## Resources
184
155
 
@@ -48,8 +48,8 @@ enum SomeType {
48
48
  mutation {
49
49
  changeSomething(
50
50
  type: OLD # This is deprecated, so you'll get an error
51
- ) {
52
- ...
51
+ ) {
52
+ ...
53
53
  }
54
54
  }
55
55
  ```
@@ -0,0 +1,56 @@
1
+ # `no-root-type`
2
+
3
+ - Category: `Validation`
4
+ - Rule name: `@graphql-eslint/no-root-type`
5
+ - Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
6
+ - Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
7
+
8
+ Disallow using root types for `read-only` or `write-only` schemas.
9
+
10
+ ## Usage Examples
11
+
12
+ ### Incorrect (`read-only` schema)
13
+
14
+ ```graphql
15
+ # eslint @graphql-eslint/no-root-type: ['error', { disallow: ['mutation', 'subscription'] }]
16
+
17
+ type Mutation {
18
+ createUser(input: CreateUserInput!): User!
19
+ }
20
+ ```
21
+
22
+ ### Incorrect (`write-only` schema)
23
+
24
+ ```graphql
25
+ # eslint @graphql-eslint/no-root-type: ['error', { disallow: ['query'] }]
26
+
27
+ type Query {
28
+ users: [User!]!
29
+ }
30
+ ```
31
+
32
+ ### Correct (`read-only` schema)
33
+
34
+ ```graphql
35
+ # eslint @graphql-eslint/no-root-type: ['error', { disallow: ['mutation', 'subscription'] }]
36
+
37
+ type Query {
38
+ users: [User!]!
39
+ }
40
+ ```
41
+
42
+ ## Config Schema
43
+
44
+ The schema defines the following properties:
45
+
46
+ ### `disallow` (array, required)
47
+
48
+ Additional restrictions:
49
+
50
+ * Minimum items: `1`
51
+ * Unique items: `true`
52
+
53
+ ## Resources
54
+
55
+ - [Rule source](../../packages/plugin/src/rules/no-root-type.ts)
56
+ - [Test source](../../packages/plugin/tests/no-root-type.spec.ts)
@@ -70,7 +70,7 @@ The object is an array with all elements of the type `string`.
70
70
 
71
71
  Default:
72
72
 
73
- ```
73
+ ```json
74
74
  [
75
75
  "id"
76
76
  ]
@@ -82,7 +82,7 @@ The object is an array with all elements of the type `string`.
82
82
 
83
83
  Default:
84
84
 
85
- ```
85
+ ```json
86
86
  [
87
87
  "ID"
88
88
  ]
@@ -100,7 +100,7 @@ The object is an array with all elements of the type `string`.
100
100
 
101
101
  Default:
102
102
 
103
- ```
103
+ ```json
104
104
  []
105
105
  ```
106
106
 
@@ -112,7 +112,7 @@ The object is an array with all elements of the type `string`.
112
112
 
113
113
  Default:
114
114
 
115
- ```
115
+ ```json
116
116
  []
117
117
  ```
118
118