Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strict-non-nullable-variables rule #421

Merged
merged 10 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"lage": "^2.7.1",
"patch-package": "^6.4.7",
"prettier": "^2.8.7",
"ts-jest": "^29.0.5",
"@graphql-eslint/eslint-plugin": "^3.7.0"
"ts-jest": "^29.0.5"
},
"resolutions": {
"cross-fetch": "^3.1.5",
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-eslint-rules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
"just": "monorepo-scripts"
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "^3.7.0",
"@graphql-eslint/eslint-plugin": "^3.20.0",
"@types/jest": "^26.0.22",
"@types/lodash.camelcase": "^4.3.6",
"@types/lodash.kebabcase": "^4.1.6",
"@typescript-eslint/utils": "^5.10.1",
"graphql": "^15.0.0",
"json-schema-to-ts": "2.9.1",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"monorepo-scripts": "*"
},
"peerDependencies": {
"graphql": "^15.0.0",
"lodash.kebabcase": "^4.1.1",
"lodash.camelcase": "^4.3.0"
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1"
},
"publishConfig": {
"main": "./lib/index",
Expand Down
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 | }"
`;
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"
`;
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 } }"
`;
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"
`;
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 | }"
`;
Loading
Loading