@graphql-eslint/eslint-plugin 2.3.2-alpha-759bc9e.0 → 2.3.2-alpha-6c8a706.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 +27 -65
- package/index.mjs +27 -65
- package/package.json +1 -1
package/index.js
CHANGED
@@ -275,7 +275,7 @@ function validateDoc(sourceNode, context, schema, documentNode, rules, ruleName
|
|
275
275
|
for (const error of validationErrors) {
|
276
276
|
const validateRuleName = ruleName || `[${extractRuleName(error.stack)}]`;
|
277
277
|
context.report({
|
278
|
-
loc: error.locations[0],
|
278
|
+
loc: getLocation({ start: error.locations[0] }),
|
279
279
|
message: ruleName ? error.message : `${validateRuleName} ${error.message}`,
|
280
280
|
});
|
281
281
|
}
|
@@ -1050,23 +1050,13 @@ const rule$4 = {
|
|
1050
1050
|
for (const field of node.fields) {
|
1051
1051
|
const fieldName = field.name.value;
|
1052
1052
|
if (fieldName.toLowerCase().startsWith(lowerTypeName)) {
|
1053
|
-
const { start } = field.loc;
|
1054
1053
|
context.report({
|
1055
1054
|
data: {
|
1056
1055
|
fieldName,
|
1057
1056
|
typeName,
|
1058
1057
|
},
|
1059
1058
|
messageId: AVOID_TYPENAME_PREFIX,
|
1060
|
-
loc:
|
1061
|
-
start: {
|
1062
|
-
line: start.line,
|
1063
|
-
column: start.column - 1,
|
1064
|
-
},
|
1065
|
-
end: {
|
1066
|
-
line: start.line,
|
1067
|
-
column: start.column - 1 + lowerTypeName.length,
|
1068
|
-
},
|
1069
|
-
},
|
1059
|
+
loc: getLocation(field.loc, lowerTypeName),
|
1070
1060
|
});
|
1071
1061
|
}
|
1072
1062
|
}
|
@@ -1770,28 +1760,14 @@ const rule$9 = {
|
|
1770
1760
|
},
|
1771
1761
|
create(context) {
|
1772
1762
|
return {
|
1773
|
-
OperationDefinition(node) {
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
column: start.column - 1,
|
1782
|
-
line: start.line,
|
1783
|
-
},
|
1784
|
-
end: {
|
1785
|
-
column: start.column - 1 + node.operation.length,
|
1786
|
-
line: start.line,
|
1787
|
-
},
|
1788
|
-
},
|
1789
|
-
data: {
|
1790
|
-
operation: node.operation,
|
1791
|
-
},
|
1792
|
-
messageId: NO_ANONYMOUS_OPERATIONS,
|
1793
|
-
});
|
1794
|
-
}
|
1763
|
+
'OperationDefinition[name=undefined]'(node) {
|
1764
|
+
context.report({
|
1765
|
+
loc: getLocation(node.loc, node.operation),
|
1766
|
+
data: {
|
1767
|
+
operation: node.operation,
|
1768
|
+
},
|
1769
|
+
messageId: NO_ANONYMOUS_OPERATIONS,
|
1770
|
+
});
|
1795
1771
|
},
|
1796
1772
|
};
|
1797
1773
|
},
|
@@ -2516,15 +2492,17 @@ const rule$h = {
|
|
2516
2492
|
},
|
2517
2493
|
create(context) {
|
2518
2494
|
return {
|
2519
|
-
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2524
|
-
|
2525
|
-
|
2526
|
-
|
2527
|
-
|
2495
|
+
Directive(node) {
|
2496
|
+
if (node && node.name && node.name.value === 'deprecated') {
|
2497
|
+
const args = node.arguments || [];
|
2498
|
+
const reasonArg = args.find(arg => arg.name && arg.name.value === 'reason');
|
2499
|
+
const value = reasonArg ? String(valueFromNode(reasonArg.value) || '').trim() : null;
|
2500
|
+
if (!value) {
|
2501
|
+
context.report({
|
2502
|
+
node: node.name,
|
2503
|
+
message: 'Directive "@deprecated" must have a reason!',
|
2504
|
+
});
|
2505
|
+
}
|
2528
2506
|
}
|
2529
2507
|
},
|
2530
2508
|
};
|
@@ -2547,20 +2525,8 @@ const DESCRIBABLE_NODES = [
|
|
2547
2525
|
function verifyRule(context, node) {
|
2548
2526
|
if (node) {
|
2549
2527
|
if (!node.description || !node.description.value || node.description.value.trim().length === 0) {
|
2550
|
-
const { start, end } = ('name' in node ? node.name : node).loc;
|
2551
2528
|
context.report({
|
2552
|
-
loc:
|
2553
|
-
start: {
|
2554
|
-
line: start.line,
|
2555
|
-
column: start.column - 1,
|
2556
|
-
},
|
2557
|
-
end: {
|
2558
|
-
line: end.line,
|
2559
|
-
column:
|
2560
|
-
// node.name don't exist on SchemaDefinition
|
2561
|
-
'name' in node ? end.column - 1 + node.name.value.length : end.column,
|
2562
|
-
},
|
2563
|
-
},
|
2529
|
+
loc: getLocation(('name' in node ? node.name : node).loc, 'name' in node ? node.name.value : 'schema'),
|
2564
2530
|
messageId: REQUIRE_DESCRIPTION_ERROR,
|
2565
2531
|
data: {
|
2566
2532
|
nodeType: node.kind,
|
@@ -2681,22 +2647,18 @@ const rule$j = {
|
|
2681
2647
|
if (!mutationType || !queryType) {
|
2682
2648
|
return {};
|
2683
2649
|
}
|
2684
|
-
const selector = [
|
2685
|
-
`:matches(${graphql.Kind.OBJECT_TYPE_DEFINITION}, ${graphql.Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
|
2686
|
-
'>',
|
2687
|
-
graphql.Kind.FIELD_DEFINITION,
|
2688
|
-
graphql.Kind.NAMED_TYPE,
|
2689
|
-
].join(' ');
|
2650
|
+
const selector = `:matches(${graphql.Kind.OBJECT_TYPE_DEFINITION}, ${graphql.Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}] > ${graphql.Kind.FIELD_DEFINITION}`;
|
2690
2651
|
return {
|
2691
2652
|
[selector](node) {
|
2692
|
-
const
|
2653
|
+
const rawNode = node.rawNode();
|
2654
|
+
const typeName = getTypeName(rawNode);
|
2693
2655
|
const graphQLType = schema.getType(typeName);
|
2694
2656
|
if (graphql.isObjectType(graphQLType)) {
|
2695
2657
|
const { fields } = graphQLType.astNode;
|
2696
2658
|
const hasQueryType = fields.some(field => getTypeName(field) === queryType.name);
|
2697
2659
|
if (!hasQueryType) {
|
2698
2660
|
context.report({
|
2699
|
-
|
2661
|
+
node,
|
2700
2662
|
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}".`,
|
2701
2663
|
});
|
2702
2664
|
}
|
@@ -3035,7 +2997,7 @@ const rule$l = {
|
|
3035
2997
|
getDocument: () => document,
|
3036
2998
|
reportError: (error) => {
|
3037
2999
|
context.report({
|
3038
|
-
loc: error.locations[0],
|
3000
|
+
loc: getLocation({ start: error.locations[0] }),
|
3039
3001
|
message: error.message,
|
3040
3002
|
});
|
3041
3003
|
},
|
package/index.mjs
CHANGED
@@ -269,7 +269,7 @@ function validateDoc(sourceNode, context, schema, documentNode, rules, ruleName
|
|
269
269
|
for (const error of validationErrors) {
|
270
270
|
const validateRuleName = ruleName || `[${extractRuleName(error.stack)}]`;
|
271
271
|
context.report({
|
272
|
-
loc: error.locations[0],
|
272
|
+
loc: getLocation({ start: error.locations[0] }),
|
273
273
|
message: ruleName ? error.message : `${validateRuleName} ${error.message}`,
|
274
274
|
});
|
275
275
|
}
|
@@ -1044,23 +1044,13 @@ const rule$4 = {
|
|
1044
1044
|
for (const field of node.fields) {
|
1045
1045
|
const fieldName = field.name.value;
|
1046
1046
|
if (fieldName.toLowerCase().startsWith(lowerTypeName)) {
|
1047
|
-
const { start } = field.loc;
|
1048
1047
|
context.report({
|
1049
1048
|
data: {
|
1050
1049
|
fieldName,
|
1051
1050
|
typeName,
|
1052
1051
|
},
|
1053
1052
|
messageId: AVOID_TYPENAME_PREFIX,
|
1054
|
-
loc:
|
1055
|
-
start: {
|
1056
|
-
line: start.line,
|
1057
|
-
column: start.column - 1,
|
1058
|
-
},
|
1059
|
-
end: {
|
1060
|
-
line: start.line,
|
1061
|
-
column: start.column - 1 + lowerTypeName.length,
|
1062
|
-
},
|
1063
|
-
},
|
1053
|
+
loc: getLocation(field.loc, lowerTypeName),
|
1064
1054
|
});
|
1065
1055
|
}
|
1066
1056
|
}
|
@@ -1764,28 +1754,14 @@ const rule$9 = {
|
|
1764
1754
|
},
|
1765
1755
|
create(context) {
|
1766
1756
|
return {
|
1767
|
-
OperationDefinition(node) {
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
column: start.column - 1,
|
1776
|
-
line: start.line,
|
1777
|
-
},
|
1778
|
-
end: {
|
1779
|
-
column: start.column - 1 + node.operation.length,
|
1780
|
-
line: start.line,
|
1781
|
-
},
|
1782
|
-
},
|
1783
|
-
data: {
|
1784
|
-
operation: node.operation,
|
1785
|
-
},
|
1786
|
-
messageId: NO_ANONYMOUS_OPERATIONS,
|
1787
|
-
});
|
1788
|
-
}
|
1757
|
+
'OperationDefinition[name=undefined]'(node) {
|
1758
|
+
context.report({
|
1759
|
+
loc: getLocation(node.loc, node.operation),
|
1760
|
+
data: {
|
1761
|
+
operation: node.operation,
|
1762
|
+
},
|
1763
|
+
messageId: NO_ANONYMOUS_OPERATIONS,
|
1764
|
+
});
|
1789
1765
|
},
|
1790
1766
|
};
|
1791
1767
|
},
|
@@ -2510,15 +2486,17 @@ const rule$h = {
|
|
2510
2486
|
},
|
2511
2487
|
create(context) {
|
2512
2488
|
return {
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2519
|
-
|
2520
|
-
|
2521
|
-
|
2489
|
+
Directive(node) {
|
2490
|
+
if (node && node.name && node.name.value === 'deprecated') {
|
2491
|
+
const args = node.arguments || [];
|
2492
|
+
const reasonArg = args.find(arg => arg.name && arg.name.value === 'reason');
|
2493
|
+
const value = reasonArg ? String(valueFromNode(reasonArg.value) || '').trim() : null;
|
2494
|
+
if (!value) {
|
2495
|
+
context.report({
|
2496
|
+
node: node.name,
|
2497
|
+
message: 'Directive "@deprecated" must have a reason!',
|
2498
|
+
});
|
2499
|
+
}
|
2522
2500
|
}
|
2523
2501
|
},
|
2524
2502
|
};
|
@@ -2541,20 +2519,8 @@ const DESCRIBABLE_NODES = [
|
|
2541
2519
|
function verifyRule(context, node) {
|
2542
2520
|
if (node) {
|
2543
2521
|
if (!node.description || !node.description.value || node.description.value.trim().length === 0) {
|
2544
|
-
const { start, end } = ('name' in node ? node.name : node).loc;
|
2545
2522
|
context.report({
|
2546
|
-
loc:
|
2547
|
-
start: {
|
2548
|
-
line: start.line,
|
2549
|
-
column: start.column - 1,
|
2550
|
-
},
|
2551
|
-
end: {
|
2552
|
-
line: end.line,
|
2553
|
-
column:
|
2554
|
-
// node.name don't exist on SchemaDefinition
|
2555
|
-
'name' in node ? end.column - 1 + node.name.value.length : end.column,
|
2556
|
-
},
|
2557
|
-
},
|
2523
|
+
loc: getLocation(('name' in node ? node.name : node).loc, 'name' in node ? node.name.value : 'schema'),
|
2558
2524
|
messageId: REQUIRE_DESCRIPTION_ERROR,
|
2559
2525
|
data: {
|
2560
2526
|
nodeType: node.kind,
|
@@ -2675,22 +2641,18 @@ const rule$j = {
|
|
2675
2641
|
if (!mutationType || !queryType) {
|
2676
2642
|
return {};
|
2677
2643
|
}
|
2678
|
-
const selector = [
|
2679
|
-
`:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
|
2680
|
-
'>',
|
2681
|
-
Kind.FIELD_DEFINITION,
|
2682
|
-
Kind.NAMED_TYPE,
|
2683
|
-
].join(' ');
|
2644
|
+
const selector = `:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}] > ${Kind.FIELD_DEFINITION}`;
|
2684
2645
|
return {
|
2685
2646
|
[selector](node) {
|
2686
|
-
const
|
2647
|
+
const rawNode = node.rawNode();
|
2648
|
+
const typeName = getTypeName(rawNode);
|
2687
2649
|
const graphQLType = schema.getType(typeName);
|
2688
2650
|
if (isObjectType$1(graphQLType)) {
|
2689
2651
|
const { fields } = graphQLType.astNode;
|
2690
2652
|
const hasQueryType = fields.some(field => getTypeName(field) === queryType.name);
|
2691
2653
|
if (!hasQueryType) {
|
2692
2654
|
context.report({
|
2693
|
-
|
2655
|
+
node,
|
2694
2656
|
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}".`,
|
2695
2657
|
});
|
2696
2658
|
}
|
@@ -3029,7 +2991,7 @@ const rule$l = {
|
|
3029
2991
|
getDocument: () => document,
|
3030
2992
|
reportError: (error) => {
|
3031
2993
|
context.report({
|
3032
|
-
loc: error.locations[0],
|
2994
|
+
loc: getLocation({ start: error.locations[0] }),
|
3033
2995
|
message: error.message,
|
3034
2996
|
});
|
3035
2997
|
},
|
package/package.json
CHANGED