@graphql-eslint/eslint-plugin 3.1.0 → 3.1.1-alpha-f19a99b.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/index.js +33 -21
- package/index.mjs +33 -21
- package/package.json +4 -4
- package/rules/graphql-js-validation.d.ts +1 -1
package/index.js
CHANGED
@@ -335,30 +335,42 @@ function getLocation(loc, fieldName = '', offset) {
|
|
335
335
|
};
|
336
336
|
}
|
337
337
|
|
338
|
-
function
|
339
|
-
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
338
|
+
function validateDoc(sourceNode, context, schema, documentNode, rules) {
|
339
|
+
if (documentNode.definitions.length === 0) {
|
340
|
+
return;
|
341
|
+
}
|
342
|
+
try {
|
343
|
+
const validationErrors = schema
|
344
|
+
? graphql.validate(schema, documentNode, rules)
|
345
|
+
: validate.validateSDL(documentNode, null, rules);
|
346
|
+
for (const error of validationErrors) {
|
347
|
+
/*
|
348
|
+
* TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
|
349
|
+
* Example: loc.end always equal loc.start
|
350
|
+
* {
|
351
|
+
* token: {
|
352
|
+
* type: 'Name',
|
353
|
+
* loc: { start: { line: 4, column: 13 }, end: { line: 4, column: 13 } },
|
354
|
+
* value: 'veryBad',
|
355
|
+
* range: [ 40, 47 ]
|
356
|
+
* }
|
357
|
+
* }
|
358
|
+
*/
|
359
|
+
const { line, column } = error.locations[0];
|
360
|
+
const ancestors = context.getAncestors();
|
361
|
+
const token = ancestors[0].tokens.find(token => token.loc.start.line === line && token.loc.start.column === column);
|
356
362
|
context.report({
|
357
|
-
|
358
|
-
message:
|
363
|
+
loc: getLocation({ start: error.locations[0] }, token === null || token === void 0 ? void 0 : token.value),
|
364
|
+
message: error.message,
|
359
365
|
});
|
360
366
|
}
|
361
367
|
}
|
368
|
+
catch (e) {
|
369
|
+
context.report({
|
370
|
+
node: sourceNode,
|
371
|
+
message: e.message,
|
372
|
+
});
|
373
|
+
}
|
362
374
|
}
|
363
375
|
const isGraphQLImportFile = rawSDL => {
|
364
376
|
const trimmedRawSDL = rawSDL.trimLeft();
|
@@ -405,7 +417,7 @@ const validationToRule = (name, ruleName, docs, getDocumentNode) => {
|
|
405
417
|
if (isRealFile && getDocumentNode) {
|
406
418
|
documentNode = getDocumentNode(context);
|
407
419
|
}
|
408
|
-
validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn]
|
420
|
+
validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn]);
|
409
421
|
},
|
410
422
|
};
|
411
423
|
},
|
package/index.mjs
CHANGED
@@ -329,30 +329,42 @@ function getLocation(loc, fieldName = '', offset) {
|
|
329
329
|
};
|
330
330
|
}
|
331
331
|
|
332
|
-
function
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
332
|
+
function validateDoc(sourceNode, context, schema, documentNode, rules) {
|
333
|
+
if (documentNode.definitions.length === 0) {
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
try {
|
337
|
+
const validationErrors = schema
|
338
|
+
? validate(schema, documentNode, rules)
|
339
|
+
: validateSDL(documentNode, null, rules);
|
340
|
+
for (const error of validationErrors) {
|
341
|
+
/*
|
342
|
+
* TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
|
343
|
+
* Example: loc.end always equal loc.start
|
344
|
+
* {
|
345
|
+
* token: {
|
346
|
+
* type: 'Name',
|
347
|
+
* loc: { start: { line: 4, column: 13 }, end: { line: 4, column: 13 } },
|
348
|
+
* value: 'veryBad',
|
349
|
+
* range: [ 40, 47 ]
|
350
|
+
* }
|
351
|
+
* }
|
352
|
+
*/
|
353
|
+
const { line, column } = error.locations[0];
|
354
|
+
const ancestors = context.getAncestors();
|
355
|
+
const token = ancestors[0].tokens.find(token => token.loc.start.line === line && token.loc.start.column === column);
|
350
356
|
context.report({
|
351
|
-
|
352
|
-
message:
|
357
|
+
loc: getLocation({ start: error.locations[0] }, token === null || token === void 0 ? void 0 : token.value),
|
358
|
+
message: error.message,
|
353
359
|
});
|
354
360
|
}
|
355
361
|
}
|
362
|
+
catch (e) {
|
363
|
+
context.report({
|
364
|
+
node: sourceNode,
|
365
|
+
message: e.message,
|
366
|
+
});
|
367
|
+
}
|
356
368
|
}
|
357
369
|
const isGraphQLImportFile = rawSDL => {
|
358
370
|
const trimmedRawSDL = rawSDL.trimLeft();
|
@@ -399,7 +411,7 @@ const validationToRule = (name, ruleName, docs, getDocumentNode) => {
|
|
399
411
|
if (isRealFile && getDocumentNode) {
|
400
412
|
documentNode = getDocumentNode(context);
|
401
413
|
}
|
402
|
-
validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn]
|
414
|
+
validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn]);
|
403
415
|
},
|
404
416
|
};
|
405
417
|
},
|
package/package.json
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "3.1.0",
|
3
|
+
"version": "3.1.1-alpha-f19a99b.0",
|
4
4
|
"sideEffects": false,
|
5
5
|
"peerDependencies": {
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
7
7
|
},
|
8
8
|
"dependencies": {
|
9
9
|
"@babel/code-frame": "7.16.0",
|
10
|
-
"@graphql-tools/code-file-loader": "7.2.
|
10
|
+
"@graphql-tools/code-file-loader": "7.2.3",
|
11
11
|
"@graphql-tools/graphql-tag-pluck": "7.1.4",
|
12
|
-
"@graphql-tools/import": "6.6.
|
13
|
-
"@graphql-tools/utils": "8.5.
|
12
|
+
"@graphql-tools/import": "6.6.2",
|
13
|
+
"@graphql-tools/utils": "8.5.4",
|
14
14
|
"graphql-config": "4.1.0",
|
15
15
|
"graphql-depth-limit": "1.1.0",
|
16
16
|
"lodash.lowercase": "4.3.0"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { GraphQLSchema, DocumentNode, ASTNode, ValidationRule } from 'graphql';
|
2
2
|
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '../types';
|
3
3
|
import { GraphQLESTreeNode } from '../estree-parser';
|
4
|
-
export declare function validateDoc(sourceNode: GraphQLESTreeNode<ASTNode>, context: GraphQLESLintRuleContext, schema: GraphQLSchema | null, documentNode: DocumentNode, rules: ReadonlyArray<ValidationRule
|
4
|
+
export declare function validateDoc(sourceNode: GraphQLESTreeNode<ASTNode>, context: GraphQLESLintRuleContext, schema: GraphQLSchema | null, documentNode: DocumentNode, rules: ReadonlyArray<ValidationRule>): void;
|
5
5
|
export declare const GRAPHQL_JS_VALIDATIONS: Record<string, GraphQLESLintRule<any[], false>>;
|