@graphql-eslint/eslint-plugin 3.2.0-alpha-6aa2721.0 → 3.2.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/docs/rules/known-fragment-names.md +30 -9
- package/docs/rules/no-undefined-variables.md +1 -1
- package/docs/rules/no-unused-variables.md +1 -1
- package/docs/rules/require-id-when-available.md +16 -1
- package/index.js +251 -256
- package/index.mjs +253 -258
- package/package.json +4 -10
- package/rules/graphql-js-validation.d.ts +5 -2
- package/rules/index.d.ts +2 -129
- package/rules/match-document-filename.d.ts +3 -3
- package/rules/naming-convention.d.ts +1 -1
- package/types.d.ts +2 -2
- package/utils.d.ts +1 -7
@@ -5,7 +5,7 @@
|
|
5
5
|
- Category: `Operations`
|
6
6
|
- Rule name: `@graphql-eslint/known-fragment-names`
|
7
7
|
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
8
|
-
- Requires GraphQL Operations: `
|
8
|
+
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
9
9
|
|
10
10
|
A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.
|
11
11
|
|
@@ -13,7 +13,7 @@ A GraphQL document is only valid if all `...Fragment` fragment spreads refer to
|
|
13
13
|
|
14
14
|
## Usage Examples
|
15
15
|
|
16
|
-
### Incorrect
|
16
|
+
### Incorrect (fragment not defined in the document)
|
17
17
|
|
18
18
|
```graphql
|
19
19
|
# eslint @graphql-eslint/known-fragment-names: 'error'
|
@@ -21,7 +21,7 @@ A GraphQL document is only valid if all `...Fragment` fragment spreads refer to
|
|
21
21
|
query {
|
22
22
|
user {
|
23
23
|
id
|
24
|
-
...UserFields
|
24
|
+
...UserFields
|
25
25
|
}
|
26
26
|
}
|
27
27
|
```
|
@@ -44,23 +44,44 @@ query {
|
|
44
44
|
}
|
45
45
|
```
|
46
46
|
|
47
|
-
### Correct (
|
47
|
+
### Correct (existing import to UserFields fragment)
|
48
48
|
|
49
49
|
```graphql
|
50
50
|
# eslint @graphql-eslint/known-fragment-names: 'error'
|
51
51
|
|
52
|
-
#
|
52
|
+
#import '../UserFields.gql'
|
53
|
+
|
53
54
|
query {
|
54
55
|
user {
|
55
56
|
id
|
56
57
|
...UserFields
|
57
58
|
}
|
58
59
|
}
|
60
|
+
```
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
### False positive case
|
63
|
+
|
64
|
+
For extracting documents from code under the hood we use [graphql-tag-pluck](https://graphql-tools.com/docs/graphql-tag-pluck) that [don't support string interpolation](https://stackoverflow.com/questions/62749847/graphql-codegen-dynamic-fields-with-interpolation/62751311#62751311) for this moment.
|
65
|
+
|
66
|
+
```js
|
67
|
+
const USER_FIELDS = gql`
|
68
|
+
fragment UserFields on User {
|
69
|
+
id
|
70
|
+
}
|
71
|
+
`
|
72
|
+
|
73
|
+
const GET_USER = /* GraphQL */ `
|
74
|
+
# eslint @graphql-eslint/known-fragment-names: 'error'
|
75
|
+
|
76
|
+
query User {
|
77
|
+
user {
|
78
|
+
...UserFields
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
# Will give false positive error 'Unknown fragment "UserFields"'
|
83
|
+
${USER_FIELDS}
|
84
|
+
`
|
64
85
|
```
|
65
86
|
|
66
87
|
## Resources
|
@@ -5,7 +5,7 @@
|
|
5
5
|
- Category: `Operations`
|
6
6
|
- Rule name: `@graphql-eslint/no-undefined-variables`
|
7
7
|
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
8
|
-
- Requires GraphQL Operations: `
|
8
|
+
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
9
9
|
|
10
10
|
A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.
|
11
11
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
- Category: `Operations`
|
6
6
|
- Rule name: `@graphql-eslint/no-unused-variables`
|
7
7
|
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
8
|
-
- Requires GraphQL Operations: `
|
8
|
+
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
9
9
|
|
10
10
|
A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.
|
11
11
|
|
@@ -54,10 +54,25 @@ query user {
|
|
54
54
|
|
55
55
|
The schema defines the following properties:
|
56
56
|
|
57
|
-
### `fieldName`
|
57
|
+
### `fieldName`
|
58
|
+
|
59
|
+
The object must be one of the following types:
|
60
|
+
|
61
|
+
* `asString`
|
62
|
+
* `asArray`
|
58
63
|
|
59
64
|
Default: `"id"`
|
60
65
|
|
66
|
+
---
|
67
|
+
|
68
|
+
# Sub Schemas
|
69
|
+
|
70
|
+
The schema defines the following additional types:
|
71
|
+
|
72
|
+
## `asString` (string)
|
73
|
+
|
74
|
+
## `asArray` (array)
|
75
|
+
|
61
76
|
## Resources
|
62
77
|
|
63
78
|
- [Rule source](../../packages/plugin/src/rules/require-id-when-available.ts)
|