-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from user1736/update-eslint-plugin-version
Add strict-non-nullable-variables rule
- Loading branch information
Showing
19 changed files
with
1,064 additions
and
377 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@graphitation-graphql-eslint-rules-9975efa4-c302-4e4a-af26-746c10e5cbea.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "add strict non-nullable-variables rule", | ||
"packageName": "@graphitation/graphql-eslint-rules", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 51 additions & 22 deletions
73
packages/graphql-eslint-rules/src/__tests__/__snapshots__/ban-directives.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,57 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[` 1`] = ` | ||
" 1 | | ||
2 | query myOperation { | ||
> 3 | user @client | ||
| ^ Use of directive @client is prohibited | ||
4 | description @foobar | ||
5 | }" | ||
`; | ||
exports[`Invalid #1 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query myOperation { | ||
2 | user @client | ||
3 | description @foobar | ||
4 | } | ||
#### ⚙️ Options | ||
exports[` 2`] = ` | ||
" 1 | | ||
2 | query myOperation { | ||
> 3 | user @client | ||
| ^ Use of directive @client is prohibited | ||
4 | description @foobar | ||
5 | }" | ||
{ | ||
"bannedDirectives": [ | ||
"client" | ||
] | ||
} | ||
#### ❌ Error | ||
1 | query myOperation { | ||
> 2 | user @client | ||
| ^ Use of directive @client is prohibited | ||
3 | description @foobar" | ||
`; | ||
exports[` 3`] = ` | ||
" 1 | | ||
2 | query myOperation { | ||
3 | user @client | ||
> 4 | description @foobar | ||
| ^ Use of directive @foobar is prohibited | ||
5 | }" | ||
exports[`Invalid #2 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query myOperation { | ||
2 | user @client | ||
3 | description @foobar | ||
4 | } | ||
#### ⚙️ Options | ||
{ | ||
"bannedDirectives": [ | ||
"client", | ||
"foobar" | ||
] | ||
} | ||
#### ❌ Error 1/2 | ||
1 | query myOperation { | ||
> 2 | user @client | ||
| ^ Use of directive @client is prohibited | ||
3 | description @foobar | ||
#### ❌ Error 2/2 | ||
2 | user @client | ||
> 3 | description @foobar | ||
| ^ Use of directive @foobar is prohibited | ||
4 | }" | ||
`; |
88 changes: 70 additions & 18 deletions
88
...graphql-eslint-rules/src/__tests__/__snapshots__/fragment-naming-conventions.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,83 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[` 1`] = ` | ||
"> 1 | fragment graphql_eslint_rules_user_fragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore" | ||
exports[`Invalid #1 1`] = ` | ||
"#### ⌨️ Code | ||
1 | fragment graphql_eslint_rules_user_fragment on User { id name } | ||
#### ❌ Error | ||
> 1 | fragment graphql_eslint_rules_user_fragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore | ||
#### 🔧 Autofix output | ||
1 | fragment GraphqlEslintRulesUserFragment on User { id name }" | ||
`; | ||
|
||
exports[` 2`] = ` | ||
"> 1 | fragment GraphqlEslintRulesUserFragment_ on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore" | ||
exports[`Invalid #2 1`] = ` | ||
"#### ⌨️ Code | ||
1 | fragment GraphqlEslintRulesUserFragment_ on User { id name } | ||
#### ❌ Error | ||
> 1 | fragment GraphqlEslintRulesUserFragment_ on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore | ||
#### 🔧 Autofix output | ||
1 | fragment GraphqlEslintRulesUserFragment on User { id name }" | ||
`; | ||
|
||
exports[` 3`] = ` | ||
"> 1 | fragment GraphqlEslintRulesUser on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore" | ||
exports[`Invalid #3 1`] = ` | ||
"#### ⌨️ Code | ||
1 | fragment GraphqlEslintRulesUser on User { id name } | ||
#### ❌ Error | ||
> 1 | fragment GraphqlEslintRulesUser on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore | ||
#### 🔧 Autofix output | ||
1 | fragment GraphqlEslintRulesUserFragment on User { id name }" | ||
`; | ||
|
||
exports[` 4`] = ` | ||
"> 1 | fragment UserFragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore" | ||
exports[`Invalid #4 1`] = ` | ||
"#### ⌨️ Code | ||
1 | fragment UserFragment on User { id name } | ||
#### ❌ Error | ||
> 1 | fragment UserFragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fragment should follow the naming conventions, the expected name is GraphqlEslintRulesUserFragment OR GraphqlEslintRulesUserFragment_optionalSuffix It's possible to chain suffixes using underscore | ||
#### 🔧 Autofix output | ||
1 | fragment GraphqlEslintRulesUserFragment on User { id name }" | ||
`; | ||
|
||
exports[` 5`] = ` | ||
"> 1 | fragment GraphqlEslintRulesUserFragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules"" | ||
exports[`Invalid #5 1`] = ` | ||
"#### ⌨️ Code | ||
1 | fragment GraphqlEslintRulesUserFragment on User { id name } | ||
#### ❌ Error | ||
> 1 | fragment GraphqlEslintRulesUserFragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules"" | ||
`; | ||
|
||
exports[` 6`] = ` | ||
"> 1 | fragment GraphqlEslintRulesUserFragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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" | ||
exports[`Invalid #6 1`] = ` | ||
"#### ⌨️ Code | ||
1 | fragment GraphqlEslintRulesUserFragment on User { id name } | ||
#### ❌ Error | ||
> 1 | fragment GraphqlEslintRulesUserFragment on User { id name } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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" | ||
`; |
58 changes: 52 additions & 6 deletions
58
...s/graphql-eslint-rules/src/__tests__/__snapshots__/missing-apollo-key-fields.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,57 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[` 1`] = ` | ||
"> 1 | query { hasId { name } } | ||
| ^^^^^^^ The key-field "id" must be selected for proper Apollo Client store denormalisation purposes." | ||
exports[`Invalid #1 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query { hasId { name } } | ||
#### ⚙️ Options | ||
{ | ||
"typePolicies": { | ||
"KeyFieldType": { | ||
"keyFields": [ | ||
"objectId" | ||
] | ||
} | ||
} | ||
} | ||
#### ❌ Error | ||
> 1 | query { hasId { name } } | ||
| ^^^^^^^ The key-field "id" must be selected for proper Apollo Client store denormalisation purposes. | ||
#### 🔧 Autofix output | ||
1 | query { hasId { id | ||
2 | name } }" | ||
`; | ||
|
||
exports[` 2`] = ` | ||
"> 1 | query { keyField { id name } } | ||
| ^^^^^^^^^^ The key-field "objectId" must be selected for proper Apollo Client store denormalisation purposes." | ||
exports[`Invalid #2 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query { keyField { id name } } | ||
#### ⚙️ Options | ||
{ | ||
"typePolicies": { | ||
"KeyFieldType": { | ||
"keyFields": [ | ||
"objectId" | ||
] | ||
} | ||
} | ||
} | ||
#### ❌ Error | ||
> 1 | query { keyField { id name } } | ||
| ^^^^^^^^^^ The key-field "objectId" must be selected for proper Apollo Client store denormalisation purposes. | ||
#### 🔧 Autofix output | ||
1 | query { keyField { objectId | ||
2 | id name } }" | ||
`; |
40 changes: 31 additions & 9 deletions
40
...raphql-eslint-rules/src/__tests__/__snapshots__/operation-naming-conventions.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[` 1`] = ` | ||
"> 1 | query wrongName { user { id name } } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Operation should follow the naming conventions, the expected name is GraphqlEslintRulesUserQuery" | ||
exports[`Invalid #1 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query wrongName { user { id name } } | ||
#### ❌ Error | ||
> 1 | query wrongName { user { id name } } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Operation should follow the naming conventions, the expected name is GraphqlEslintRulesUserQuery | ||
#### 🔧 Autofix output | ||
1 | query GraphqlEslintRulesUserQuery { user { id name } }" | ||
`; | ||
|
||
exports[` 2`] = ` | ||
"> 1 | query GraphqlEslintRulesUserQuery { user { id name } } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules"" | ||
exports[`Invalid #2 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query GraphqlEslintRulesUserQuery { user { id name } } | ||
#### ❌ Error | ||
> 1 | query GraphqlEslintRulesUserQuery { user { id name } } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should start with the package directory name: "graphql-eslint-rules"" | ||
`; | ||
|
||
exports[` 3`] = ` | ||
"> 1 | query GraphqlEslintRulesUserQuery { user { id name } } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should end with the operation name (query/mutation/subscription) e.g. foo-query.graphql" | ||
exports[`Invalid #3 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query GraphqlEslintRulesUserQuery { user { id name } } | ||
#### ❌ Error | ||
> 1 | query GraphqlEslintRulesUserQuery { user { id name } } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Filename should end with the operation name (query/mutation/subscription) e.g. foo-query.graphql" | ||
`; |
47 changes: 47 additions & 0 deletions
47
...aphql-eslint-rules/src/__tests__/__snapshots__/strict-non-nullable-variables.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Invalid #1 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query Q ($number: Int = 3) { | ||
2 | sum(numbers: [1, $number, 3]) | ||
3 | } | ||
#### ❌ Error | ||
1 | query Q ($number: Int = 3) { | ||
> 2 | sum(numbers: [1, $number, 3]) | ||
| ^ Can't use nullable variable in non nullable position. | ||
3 | }" | ||
`; | ||
|
||
exports[`Invalid #2 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query Q ($number: Int = 3) { | ||
2 | addOne(number: $number) | ||
3 | addOneSafe(number: $number) | ||
4 | } | ||
#### ❌ Error | ||
1 | query Q ($number: Int = 3) { | ||
> 2 | addOne(number: $number) | ||
| ^ Can't use nullable variable in non nullable position. | ||
3 | addOneSafe(number: $number)" | ||
`; | ||
exports[`Invalid #3 1`] = ` | ||
"#### ⌨️ Code | ||
1 | query Q ($number: Int = 3) { | ||
2 | addTwo(input: { left: $number, right: 2 }) | ||
3 | } | ||
#### ❌ Error | ||
1 | query Q ($number: Int = 3) { | ||
> 2 | addTwo(input: { left: $number, right: 2 }) | ||
| ^ Can't use nullable variable in non nullable position. | ||
3 | }" | ||
`; |
Oops, something went wrong.