Skip to content

Commit 61251e7

Browse files
committed
remove validate-against-schema rule
1 parent 6d4a356 commit 61251e7

File tree

11 files changed

+65
-258
lines changed

11 files changed

+65
-258
lines changed

.changeset/chilly-foxes-help.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
---
2-
"@graphql-eslint/eslint-plugin": minor
2+
'@graphql-eslint/eslint-plugin': major
33
---
44

55
feat: remove `prettier` rule, add related docs
6+
7+
### BREAKING CHANGE: Remove `prettier` Rule
8+
9+
Since prettier itself support now linting GraphQL code and syntax, we removed the need for this rule from this package.
10+
11+
For more information, see:
12+
13+
- [Migration guide and example](https://github.com/dotansimha/graphql-eslint#prettier-rule)
14+
- [Related PR](https://github.com/dotansimha/graphql-eslint/issues/395)

.changeset/new-seas-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': major
3+
---
4+
5+
Remove deprecated rule `validate-against-schema`

.changeset/rude-paws-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': major
3+
---
4+
5+
Bump dependencies and update minimum Node version to `v12`

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
- [`no-deprecated`](./rules/no-deprecated.md)
66
- [`unique-fragment-name`](./rules/unique-fragment-name.md)
77
- [`unique-operation-name`](./rules/unique-operation-name.md)
8-
- [`validate-against-schema`](./rules/validate-against-schema.md)
98
- [`no-hashtag-description`](./rules/no-hashtag-description.md)
109
- [`no-anonymous-operations`](./rules/no-anonymous-operations.md)
1110
- [`no-operation-name-suffix`](./rules/no-operation-name-suffix.md)

docs/rules/validate-against-schema.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/basic/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = {
1818
},
1919
],
2020
'@graphql-eslint/unique-fragment-name': 'warn',
21-
'@graphql-eslint/validate-against-schema': 'error',
2221
'@graphql-eslint/no-anonymous-operations': 'warn',
2322
'@graphql-eslint/no-operation-name-suffix': 'error',
2423
'@graphql-eslint/avoid-operation-name-prefix': [

examples/graphql-config-code-file/.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"rules": {
1212
"@graphql-eslint/require-id-when-available": "warn",
1313
"@graphql-eslint/no-anonymous-operations": "warn",
14-
"@graphql-eslint/no-operation-name-suffix": "error",
15-
"@graphql-eslint/validate-against-schema": "error"
14+
"@graphql-eslint/no-operation-name-suffix": "error"
1615
}
1716
}
1817
]

packages/plugin/src/rules/graphql-js-validation.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
1-
import { ValidationRule } from 'graphql';
2-
import { GraphQLESLintRule } from '../types';
3-
import { validateDoc } from './validate-against-schema';
1+
import { GraphQLESLintRule, GraphQLESlintRuleContext } from '../types';
42
import { requireGraphQLSchemaFromContext } from '../utils';
53

4+
import { validate, GraphQLSchema, DocumentNode, ASTNode, ValidationRule } from 'graphql';
5+
import { validateSDL } from 'graphql/validation/validate';
6+
import { GraphQLESTreeNode } from '../estree-parser';
7+
8+
function extractRuleName(stack: string | undefined): string | null {
9+
const match = (stack || '').match(/validation[/\\\\]rules[/\\\\](.*?)\.js:/);
10+
11+
if (!match) {
12+
return null;
13+
}
14+
15+
return match[1] || null;
16+
}
17+
18+
export function validateDoc(
19+
sourceNode: GraphQLESTreeNode<ASTNode>,
20+
context: GraphQLESlintRuleContext,
21+
schema: GraphQLSchema | null,
22+
documentNode: DocumentNode,
23+
rules: ReadonlyArray<ValidationRule>,
24+
ruleName: string | null = null
25+
): void {
26+
if (documentNode && documentNode.definitions && documentNode.definitions.length > 0) {
27+
try {
28+
const validationErrors = schema ? validate(schema, documentNode, rules) : validateSDL(documentNode, null, rules);
29+
30+
for (const error of validationErrors) {
31+
const validateRuleName = ruleName || `[${extractRuleName(error.stack)}]`;
32+
33+
context.report({
34+
loc: error.locations[0],
35+
message: ruleName ? error.message : `${validateRuleName} ${error.message}`,
36+
});
37+
}
38+
} catch (e) {
39+
context.report({
40+
node: sourceNode,
41+
message: e.message,
42+
});
43+
}
44+
}
45+
}
46+
647
const validationToRule = (
748
name: string,
849
ruleName: string,

packages/plugin/src/rules/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import validate from './validate-against-schema';
21
import noUnreachableTypes from './no-unreachable-types';
32
import noAnonymousOperations from './no-anonymous-operations';
43
import noOperationNameSuffix from './no-operation-name-suffix';
@@ -24,7 +23,6 @@ export const rules = {
2423
'no-deprecated': noDeprecated,
2524
'unique-fragment-name': uniqueFragmentName,
2625
'unique-operation-name': uniqueOperationName,
27-
'validate-against-schema': validate,
2826
'no-hashtag-description': noHashtagDescription,
2927
'no-anonymous-operations': noAnonymousOperations,
3028
'no-operation-name-suffix': noOperationNameSuffix,

packages/plugin/src/rules/validate-against-schema.ts

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)