Skip to content

Commit dcd5a29

Browse files
authored
Merge pull request #421 from user1736/update-eslint-plugin-version
Add strict-non-nullable-variables rule
2 parents bfbfa6c + a8d6dd3 commit dcd5a29

19 files changed

+1064
-377
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "add strict non-nullable-variables rule",
4+
"packageName": "@graphitation/graphql-eslint-rules",
5+
"email": "dsamsonov@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"lage": "^2.7.1",
3030
"patch-package": "^6.4.7",
3131
"prettier": "^2.8.7",
32-
"ts-jest": "^29.0.5",
33-
"@graphql-eslint/eslint-plugin": "^3.7.0"
32+
"ts-jest": "^29.0.5"
3433
},
3534
"resolutions": {
3635
"cross-fetch": "^3.1.5",

packages/graphql-eslint-rules/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
"just": "monorepo-scripts"
1717
},
1818
"devDependencies": {
19-
"@graphql-eslint/eslint-plugin": "^3.7.0",
19+
"@graphql-eslint/eslint-plugin": "^3.20.0",
2020
"@types/jest": "^26.0.22",
2121
"@types/lodash.camelcase": "^4.3.6",
2222
"@types/lodash.kebabcase": "^4.1.6",
23-
"@typescript-eslint/utils": "^5.10.1",
2423
"graphql": "^15.0.0",
24+
"json-schema-to-ts": "2.9.1",
2525
"lodash.camelcase": "^4.3.0",
2626
"lodash.kebabcase": "^4.1.1",
2727
"monorepo-scripts": "*"
2828
},
2929
"peerDependencies": {
3030
"graphql": "^15.0.0",
31-
"lodash.kebabcase": "^4.1.1",
32-
"lodash.camelcase": "^4.3.0"
31+
"lodash.camelcase": "^4.3.0",
32+
"lodash.kebabcase": "^4.1.1"
3333
},
3434
"publishConfig": {
3535
"main": "./lib/index",
Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[` 1`] = `
4-
" 1 |
5-
2 | query myOperation {
6-
> 3 | user @client
7-
| ^ Use of directive @client is prohibited
8-
4 | description @foobar
9-
5 | }"
10-
`;
3+
exports[`Invalid #1 1`] = `
4+
"#### ⌨️ Code
5+
6+
1 | query myOperation {
7+
2 | user @client
8+
3 | description @foobar
9+
4 | }
10+
11+
#### ⚙️ Options
1112
12-
exports[` 2`] = `
13-
" 1 |
14-
2 | query myOperation {
15-
> 3 | user @client
16-
| ^ Use of directive @client is prohibited
17-
4 | description @foobar
18-
5 | }"
13+
{
14+
"bannedDirectives": [
15+
"client"
16+
]
17+
}
18+
19+
#### ❌ Error
20+
21+
1 | query myOperation {
22+
> 2 | user @client
23+
| ^ Use of directive @client is prohibited
24+
3 | description @foobar"
1925
`;
2026
21-
exports[` 3`] = `
22-
" 1 |
23-
2 | query myOperation {
24-
3 | user @client
25-
> 4 | description @foobar
26-
| ^ Use of directive @foobar is prohibited
27-
5 | }"
27+
exports[`Invalid #2 1`] = `
28+
"#### ⌨️ Code
29+
30+
1 | query myOperation {
31+
2 | user @client
32+
3 | description @foobar
33+
4 | }
34+
35+
#### ⚙️ Options
36+
37+
{
38+
"bannedDirectives": [
39+
"client",
40+
"foobar"
41+
]
42+
}
43+
44+
#### ❌ Error 1/2
45+
46+
1 | query myOperation {
47+
> 2 | user @client
48+
| ^ Use of directive @client is prohibited
49+
3 | description @foobar
50+
51+
#### ❌ Error 2/2
52+
53+
2 | user @client
54+
> 3 | description @foobar
55+
| ^ Use of directive @foobar is prohibited
56+
4 | }"
2857
`;
Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,83 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[` 1`] = `
4-
"> 1 | fragment graphql_eslint_rules_user_fragment on User { id name }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore"
3+
exports[`Invalid #1 1`] = `
4+
"#### ⌨️ Code
5+
6+
1 | fragment graphql_eslint_rules_user_fragment on User { id name }
7+
8+
#### ❌ Error
9+
10+
> 1 | fragment graphql_eslint_rules_user_fragment on User { id name }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore
12+
13+
#### 🔧 Autofix output
14+
15+
1 | fragment GraphqlEslintRulesUserFragment on User { id name }"
616
`;
717

8-
exports[` 2`] = `
9-
"> 1 | fragment GraphqlEslintRulesUserFragment_ on User { id name }
10-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore"
18+
exports[`Invalid #2 1`] = `
19+
"#### ⌨️ Code
20+
21+
1 | fragment GraphqlEslintRulesUserFragment_ on User { id name }
22+
23+
#### ❌ Error
24+
25+
> 1 | fragment GraphqlEslintRulesUserFragment_ on User { id name }
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore
27+
28+
#### 🔧 Autofix output
29+
30+
1 | fragment GraphqlEslintRulesUserFragment on User { id name }"
1131
`;
1232

13-
exports[` 3`] = `
14-
"> 1 | fragment GraphqlEslintRulesUser on User { id name }
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore"
33+
exports[`Invalid #3 1`] = `
34+
"#### ⌨️ Code
35+
36+
1 | fragment GraphqlEslintRulesUser on User { id name }
37+
38+
#### ❌ Error
39+
40+
> 1 | fragment GraphqlEslintRulesUser on User { id name }
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore
42+
43+
#### 🔧 Autofix output
44+
45+
1 | fragment GraphqlEslintRulesUserFragment on User { id name }"
1646
`;
1747

18-
exports[` 4`] = `
19-
"> 1 | fragment UserFragment on User { id name }
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore"
48+
exports[`Invalid #4 1`] = `
49+
"#### ⌨️ Code
50+
51+
1 | fragment UserFragment on User { id name }
52+
53+
#### ❌ Error
54+
55+
> 1 | fragment UserFragment on User { id name }
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore
57+
58+
#### 🔧 Autofix output
59+
60+
1 | fragment GraphqlEslintRulesUserFragment on User { id name }"
2161
`;
2262

23-
exports[` 5`] = `
24-
"> 1 | fragment GraphqlEslintRulesUserFragment on User { id name }
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules""
63+
exports[`Invalid #5 1`] = `
64+
"#### ⌨️ Code
65+
66+
1 | fragment GraphqlEslintRulesUserFragment on User { id name }
67+
68+
#### ❌ Error
69+
70+
> 1 | fragment GraphqlEslintRulesUserFragment on User { id name }
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules""
2672
`;
2773

28-
exports[` 6`] = `
29-
"> 1 | fragment GraphqlEslintRulesUserFragment on User { id name }
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should end with the operation name (query/mutation/subscription) e.g. foo-query.graphql OR if the file contains ONLY fragments the suffix can be "fragment" e.g foo-fragment.graphql"
74+
exports[`Invalid #6 1`] = `
75+
"#### ⌨️ Code
76+
77+
1 | fragment GraphqlEslintRulesUserFragment on User { id name }
78+
79+
#### ❌ Error
80+
81+
> 1 | fragment GraphqlEslintRulesUserFragment on User { id name }
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should end with the operation name (query/mutation/subscription) e.g. foo-query.graphql OR if the file contains ONLY fragments the suffix can be "fragment" e.g foo-fragment.graphql"
3183
`;
Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,57 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[` 1`] = `
4-
"> 1 | query { hasId { name } }
5-
| ^^^^^^^ The key-field "id" must be selected for proper Apollo Client store denormalisation purposes."
3+
exports[`Invalid #1 1`] = `
4+
"#### ⌨️ Code
5+
6+
1 | query { hasId { name } }
7+
8+
#### ⚙️ Options
9+
10+
{
11+
"typePolicies": {
12+
"KeyFieldType": {
13+
"keyFields": [
14+
"objectId"
15+
]
16+
}
17+
}
18+
}
19+
20+
#### ❌ Error
21+
22+
> 1 | query { hasId { name } }
23+
| ^^^^^^^ The key-field "id" must be selected for proper Apollo Client store denormalisation purposes.
24+
25+
#### 🔧 Autofix output
26+
27+
1 | query { hasId { id
28+
2 | name } }"
629
`;
730

8-
exports[` 2`] = `
9-
"> 1 | query { keyField { id name } }
10-
| ^^^^^^^^^^ The key-field "objectId" must be selected for proper Apollo Client store denormalisation purposes."
31+
exports[`Invalid #2 1`] = `
32+
"#### ⌨️ Code
33+
34+
1 | query { keyField { id name } }
35+
36+
#### ⚙️ Options
37+
38+
{
39+
"typePolicies": {
40+
"KeyFieldType": {
41+
"keyFields": [
42+
"objectId"
43+
]
44+
}
45+
}
46+
}
47+
48+
#### ❌ Error
49+
50+
> 1 | query { keyField { id name } }
51+
| ^^^^^^^^^^ The key-field "objectId" must be selected for proper Apollo Client store denormalisation purposes.
52+
53+
#### 🔧 Autofix output
54+
55+
1 | query { keyField { objectId
56+
2 | id name } }"
1157
`;
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[` 1`] = `
4-
"> 1 | query wrongName { user { id name } }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Operation should follow the naming conventions, the expected name is GraphqlEslintRulesUserQuery"
3+
exports[`Invalid #1 1`] = `
4+
"#### ⌨️ Code
5+
6+
1 | query wrongName { user { id name } }
7+
8+
#### ❌ Error
9+
10+
> 1 | query wrongName { user { id name } }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Operation should follow the naming conventions, the expected name is GraphqlEslintRulesUserQuery
12+
13+
#### 🔧 Autofix output
14+
15+
1 | query GraphqlEslintRulesUserQuery { user { id name } }"
616
`;
717

8-
exports[` 2`] = `
9-
"> 1 | query GraphqlEslintRulesUserQuery { user { id name } }
10-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules""
18+
exports[`Invalid #2 1`] = `
19+
"#### ⌨️ Code
20+
21+
1 | query GraphqlEslintRulesUserQuery { user { id name } }
22+
23+
#### ❌ Error
24+
25+
> 1 | query GraphqlEslintRulesUserQuery { user { id name } }
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules""
1127
`;
1228

13-
exports[` 3`] = `
14-
"> 1 | query GraphqlEslintRulesUserQuery { user { id name } }
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should end with the operation name (query/mutation/subscription) e.g. foo-query.graphql"
29+
exports[`Invalid #3 1`] = `
30+
"#### ⌨️ Code
31+
32+
1 | query GraphqlEslintRulesUserQuery { user { id name } }
33+
34+
#### ❌ Error
35+
36+
> 1 | query GraphqlEslintRulesUserQuery { user { id name } }
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should end with the operation name (query/mutation/subscription) e.g. foo-query.graphql"
1638
`;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Invalid #1 1`] = `
4+
"#### ⌨️ Code
5+
6+
1 | query Q ($number: Int = 3) {
7+
2 | sum(numbers: [1, $number, 3])
8+
3 | }
9+
10+
#### ❌ Error
11+
12+
1 | query Q ($number: Int = 3) {
13+
> 2 | sum(numbers: [1, $number, 3])
14+
| ^ Can't use nullable variable in non nullable position.
15+
3 | }"
16+
`;
17+
18+
exports[`Invalid #2 1`] = `
19+
"#### ⌨️ Code
20+
21+
1 | query Q ($number: Int = 3) {
22+
2 | addOne(number: $number)
23+
3 | addOneSafe(number: $number)
24+
4 | }
25+
26+
#### ❌ Error
27+
28+
1 | query Q ($number: Int = 3) {
29+
> 2 | addOne(number: $number)
30+
| ^ Can't use nullable variable in non nullable position.
31+
3 | addOneSafe(number: $number)"
32+
`;
33+
34+
exports[`Invalid #3 1`] = `
35+
"#### ⌨️ Code
36+
37+
1 | query Q ($number: Int = 3) {
38+
2 | addTwo(input: { left: $number, right: 2 })
39+
3 | }
40+
41+
#### ❌ Error
42+
43+
1 | query Q ($number: Int = 3) {
44+
> 2 | addTwo(input: { left: $number, right: 2 })
45+
| ^ Can't use nullable variable in non nullable position.
46+
3 | }"
47+
`;

0 commit comments

Comments
 (0)