@graphql-eslint/eslint-plugin 3.5.0 → 3.6.0-alpha-56305a5.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/docs/rules/strict-id-in-types.md +1 -1
- package/index.js +28 -19
- package/index.mjs +28 -19
- package/package.json +1 -1
- package/rules/index.d.ts +1 -5
- package/rules/strict-id-in-types.d.ts +5 -6
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
- Category: `Schema`
|
6
6
|
- Rule name: `@graphql-eslint/strict-id-in-types`
|
7
|
-
- Requires GraphQL Schema: `
|
7
|
+
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
8
8
|
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
9
9
|
|
10
10
|
Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.
|
package/index.js
CHANGED
@@ -3157,28 +3157,26 @@ const rule$k = {
|
|
3157
3157
|
},
|
3158
3158
|
};
|
3159
3159
|
|
3160
|
-
const
|
3161
|
-
const rawNode = node.rawNode();
|
3162
|
-
if (exceptions.types && exceptions.types.includes(rawNode.name.value)) {
|
3163
|
-
return true;
|
3164
|
-
}
|
3165
|
-
if (exceptions.suffixes && exceptions.suffixes.some(suffix => rawNode.name.value.endsWith(suffix))) {
|
3166
|
-
return true;
|
3167
|
-
}
|
3168
|
-
return false;
|
3169
|
-
};
|
3160
|
+
const RULE_ID$4 = 'strict-id-in-types';
|
3170
3161
|
const rule$l = {
|
3171
3162
|
meta: {
|
3172
3163
|
type: 'suggestion',
|
3173
3164
|
docs: {
|
3174
|
-
description:
|
3165
|
+
description: `Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.`,
|
3175
3166
|
category: 'Schema',
|
3176
3167
|
recommended: true,
|
3177
|
-
url:
|
3168
|
+
url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_ID$4}.md`,
|
3169
|
+
requiresSchema: true,
|
3178
3170
|
examples: [
|
3179
3171
|
{
|
3180
3172
|
title: 'Incorrect',
|
3181
|
-
usage: [
|
3173
|
+
usage: [
|
3174
|
+
{
|
3175
|
+
acceptedIdNames: ['id', '_id'],
|
3176
|
+
acceptedIdTypes: ['ID'],
|
3177
|
+
exceptions: { suffixes: ['Payload'] },
|
3178
|
+
},
|
3179
|
+
],
|
3182
3180
|
code: /* GraphQL */ `
|
3183
3181
|
# Incorrect field name
|
3184
3182
|
type InvalidFieldName {
|
@@ -3280,6 +3278,9 @@ const rule$l = {
|
|
3280
3278
|
},
|
3281
3279
|
},
|
3282
3280
|
},
|
3281
|
+
messages: {
|
3282
|
+
[RULE_ID$4]: `{{ typeName }} must have exactly one non-nullable unique identifier. Accepted name(s): {{ acceptedNamesString }}; Accepted type(s): {{ acceptedTypesString }}.`,
|
3283
|
+
},
|
3283
3284
|
},
|
3284
3285
|
create(context) {
|
3285
3286
|
const options = {
|
@@ -3288,9 +3289,18 @@ const rule$l = {
|
|
3288
3289
|
exceptions: {},
|
3289
3290
|
...context.options[0],
|
3290
3291
|
};
|
3292
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID$4, context);
|
3293
|
+
const rootTypeNames = [schema.getQueryType(), schema.getMutationType(), schema.getSubscriptionType()]
|
3294
|
+
.filter(Boolean)
|
3295
|
+
.map(type => type.name);
|
3296
|
+
const selector = `ObjectTypeDefinition[name.value!=/^(${rootTypeNames.join('|')})$/]`;
|
3291
3297
|
return {
|
3292
|
-
|
3293
|
-
|
3298
|
+
[selector](node) {
|
3299
|
+
var _a, _b;
|
3300
|
+
const typeName = node.name.value;
|
3301
|
+
const shouldIgnoreNode = ((_a = options.exceptions.types) === null || _a === void 0 ? void 0 : _a.includes(typeName)) ||
|
3302
|
+
((_b = options.exceptions.suffixes) === null || _b === void 0 ? void 0 : _b.some(suffix => typeName.endsWith(suffix)));
|
3303
|
+
if (shouldIgnoreNode) {
|
3294
3304
|
return;
|
3295
3305
|
}
|
3296
3306
|
const validIds = node.fields.filter(field => {
|
@@ -3303,18 +3313,17 @@ const rule$l = {
|
|
3303
3313
|
}
|
3304
3314
|
return isValidIdName && isValidIdType;
|
3305
3315
|
});
|
3306
|
-
const typeName = node.name.value;
|
3307
3316
|
// Usually, there should be only one unique identifier field per type.
|
3308
3317
|
// Some clients allow multiple fields to be used. If more people need this,
|
3309
3318
|
// we can extend this rule later.
|
3310
3319
|
if (validIds.length !== 1) {
|
3311
3320
|
context.report({
|
3312
3321
|
loc: getLocation(node.name.loc, typeName),
|
3313
|
-
|
3322
|
+
messageId: RULE_ID$4,
|
3314
3323
|
data: {
|
3315
3324
|
typeName,
|
3316
|
-
acceptedNamesString: options.acceptedIdNames.join(','),
|
3317
|
-
acceptedTypesString: options.acceptedIdTypes.join(','),
|
3325
|
+
acceptedNamesString: options.acceptedIdNames.join(', '),
|
3326
|
+
acceptedTypesString: options.acceptedIdTypes.join(', '),
|
3318
3327
|
},
|
3319
3328
|
});
|
3320
3329
|
}
|
package/index.mjs
CHANGED
@@ -3151,28 +3151,26 @@ const rule$k = {
|
|
3151
3151
|
},
|
3152
3152
|
};
|
3153
3153
|
|
3154
|
-
const
|
3155
|
-
const rawNode = node.rawNode();
|
3156
|
-
if (exceptions.types && exceptions.types.includes(rawNode.name.value)) {
|
3157
|
-
return true;
|
3158
|
-
}
|
3159
|
-
if (exceptions.suffixes && exceptions.suffixes.some(suffix => rawNode.name.value.endsWith(suffix))) {
|
3160
|
-
return true;
|
3161
|
-
}
|
3162
|
-
return false;
|
3163
|
-
};
|
3154
|
+
const RULE_ID$4 = 'strict-id-in-types';
|
3164
3155
|
const rule$l = {
|
3165
3156
|
meta: {
|
3166
3157
|
type: 'suggestion',
|
3167
3158
|
docs: {
|
3168
|
-
description:
|
3159
|
+
description: `Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.`,
|
3169
3160
|
category: 'Schema',
|
3170
3161
|
recommended: true,
|
3171
|
-
url:
|
3162
|
+
url: `https://github.com/dotansimha/graphql-eslint/blob/master/docs/rules/${RULE_ID$4}.md`,
|
3163
|
+
requiresSchema: true,
|
3172
3164
|
examples: [
|
3173
3165
|
{
|
3174
3166
|
title: 'Incorrect',
|
3175
|
-
usage: [
|
3167
|
+
usage: [
|
3168
|
+
{
|
3169
|
+
acceptedIdNames: ['id', '_id'],
|
3170
|
+
acceptedIdTypes: ['ID'],
|
3171
|
+
exceptions: { suffixes: ['Payload'] },
|
3172
|
+
},
|
3173
|
+
],
|
3176
3174
|
code: /* GraphQL */ `
|
3177
3175
|
# Incorrect field name
|
3178
3176
|
type InvalidFieldName {
|
@@ -3274,6 +3272,9 @@ const rule$l = {
|
|
3274
3272
|
},
|
3275
3273
|
},
|
3276
3274
|
},
|
3275
|
+
messages: {
|
3276
|
+
[RULE_ID$4]: `{{ typeName }} must have exactly one non-nullable unique identifier. Accepted name(s): {{ acceptedNamesString }}; Accepted type(s): {{ acceptedTypesString }}.`,
|
3277
|
+
},
|
3277
3278
|
},
|
3278
3279
|
create(context) {
|
3279
3280
|
const options = {
|
@@ -3282,9 +3283,18 @@ const rule$l = {
|
|
3282
3283
|
exceptions: {},
|
3283
3284
|
...context.options[0],
|
3284
3285
|
};
|
3286
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID$4, context);
|
3287
|
+
const rootTypeNames = [schema.getQueryType(), schema.getMutationType(), schema.getSubscriptionType()]
|
3288
|
+
.filter(Boolean)
|
3289
|
+
.map(type => type.name);
|
3290
|
+
const selector = `ObjectTypeDefinition[name.value!=/^(${rootTypeNames.join('|')})$/]`;
|
3285
3291
|
return {
|
3286
|
-
|
3287
|
-
|
3292
|
+
[selector](node) {
|
3293
|
+
var _a, _b;
|
3294
|
+
const typeName = node.name.value;
|
3295
|
+
const shouldIgnoreNode = ((_a = options.exceptions.types) === null || _a === void 0 ? void 0 : _a.includes(typeName)) ||
|
3296
|
+
((_b = options.exceptions.suffixes) === null || _b === void 0 ? void 0 : _b.some(suffix => typeName.endsWith(suffix)));
|
3297
|
+
if (shouldIgnoreNode) {
|
3288
3298
|
return;
|
3289
3299
|
}
|
3290
3300
|
const validIds = node.fields.filter(field => {
|
@@ -3297,18 +3307,17 @@ const rule$l = {
|
|
3297
3307
|
}
|
3298
3308
|
return isValidIdName && isValidIdType;
|
3299
3309
|
});
|
3300
|
-
const typeName = node.name.value;
|
3301
3310
|
// Usually, there should be only one unique identifier field per type.
|
3302
3311
|
// Some clients allow multiple fields to be used. If more people need this,
|
3303
3312
|
// we can extend this rule later.
|
3304
3313
|
if (validIds.length !== 1) {
|
3305
3314
|
context.report({
|
3306
3315
|
loc: getLocation(node.name.loc, typeName),
|
3307
|
-
|
3316
|
+
messageId: RULE_ID$4,
|
3308
3317
|
data: {
|
3309
3318
|
typeName,
|
3310
|
-
acceptedNamesString: options.acceptedIdNames.join(','),
|
3311
|
-
acceptedTypesString: options.acceptedIdTypes.join(','),
|
3319
|
+
acceptedNamesString: options.acceptedIdNames.join(', '),
|
3320
|
+
acceptedTypesString: options.acceptedIdTypes.join(', '),
|
3312
3321
|
},
|
3313
3322
|
});
|
3314
3323
|
}
|
package/package.json
CHANGED
package/rules/index.d.ts
CHANGED
@@ -53,11 +53,7 @@ export declare const rules: {
|
|
53
53
|
maxDepth: number;
|
54
54
|
ignore?: string[];
|
55
55
|
}], false>;
|
56
|
-
'strict-id-in-types': import("..").GraphQLESLintRule<[
|
57
|
-
acceptedIdNames?: string[];
|
58
|
-
acceptedIdTypes?: string[];
|
59
|
-
exceptions?: import("./strict-id-in-types").ExceptionRule;
|
60
|
-
}], false>;
|
56
|
+
'strict-id-in-types': import("..").GraphQLESLintRule<[import("./strict-id-in-types").StrictIdInTypesRuleConfig], false>;
|
61
57
|
'unique-fragment-name': import("..").GraphQLESLintRule<any[], false>;
|
62
58
|
'unique-operation-name': import("..").GraphQLESLintRule<any[], false>;
|
63
59
|
};
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import { GraphQLESLintRule } from '../types';
|
2
|
-
export
|
3
|
-
types?: string[];
|
4
|
-
suffixes?: string[];
|
5
|
-
}
|
6
|
-
declare type StrictIdInTypesRuleConfig = {
|
2
|
+
export declare type StrictIdInTypesRuleConfig = {
|
7
3
|
acceptedIdNames?: string[];
|
8
4
|
acceptedIdTypes?: string[];
|
9
|
-
exceptions?:
|
5
|
+
exceptions?: {
|
6
|
+
types?: string[];
|
7
|
+
suffixes?: string[];
|
8
|
+
};
|
10
9
|
};
|
11
10
|
declare const rule: GraphQLESLintRule<[StrictIdInTypesRuleConfig]>;
|
12
11
|
export default rule;
|