@graphql-eslint/eslint-plugin 4.0.0-alpha.6 → 4.0.0-alpha.7
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/cache.js +8 -36
- package/cjs/chunk-UIAXBAMD.js +8 -0
- package/cjs/configs/index.d.cts +15 -5
- package/cjs/configs/index.js +31 -45
- package/cjs/configs/operations-all.js +33 -26
- package/cjs/configs/operations-recommended.js +59 -52
- package/cjs/configs/schema-all.js +29 -22
- package/cjs/configs/schema-recommended.js +73 -66
- package/cjs/configs/schema-relay.js +17 -10
- package/cjs/documents.js +12 -37
- package/cjs/estree-converter/converter.js +16 -30
- package/cjs/estree-converter/index.js +3 -23
- package/cjs/estree-converter/types.js +1 -14
- package/cjs/estree-converter/utils.js +22 -40
- package/cjs/graphql-config.js +15 -41
- package/cjs/index.d.cts +164 -9
- package/cjs/index.js +24 -41
- package/cjs/meta.js +5 -25
- package/cjs/parser.js +29 -49
- package/cjs/processor.js +22 -35
- package/{esm/rules/alphabetize.d.ts → cjs/rules/alphabetize/index.d.cts} +3 -3
- package/cjs/rules/{alphabetize.js → alphabetize/index.js} +47 -71
- package/{esm/rules/description-style.d.ts → cjs/rules/description-style/index.d.cts} +3 -3
- package/cjs/rules/{description-style.js → description-style/index.js} +7 -27
- package/cjs/rules/graphql-js-validation.js +93 -70
- package/cjs/rules/index.d.cts +5 -5
- package/cjs/rules/index.js +74 -60
- package/{esm/rules/input-name.d.ts → cjs/rules/input-name/index.d.cts} +3 -3
- package/cjs/rules/{input-name.js → input-name/index.js} +10 -28
- package/{esm/rules/lone-executable-definition.d.ts → cjs/rules/lone-executable-definition/index.d.cts} +3 -3
- package/cjs/rules/{lone-executable-definition.js → lone-executable-definition/index.js} +13 -32
- package/cjs/rules/{match-document-filename.d.cts → match-document-filename/index.d.cts} +4 -4
- package/cjs/rules/{match-document-filename.js → match-document-filename/index.js} +20 -34
- package/{esm/rules/naming-convention.d.ts → cjs/rules/naming-convention/index.d.cts} +3 -3
- package/cjs/rules/{naming-convention.js → naming-convention/index.js} +41 -54
- package/cjs/rules/no-anonymous-operations/index.d.cts +13 -0
- package/cjs/rules/{no-anonymous-operations.js → no-anonymous-operations/index.js} +9 -28
- package/cjs/rules/{no-deprecated.d.cts → no-deprecated/index.d.cts} +3 -3
- package/cjs/rules/{no-deprecated.js → no-deprecated/index.js} +11 -30
- package/cjs/rules/no-duplicate-fields/index.d.cts +13 -0
- package/cjs/rules/{no-duplicate-fields.js → no-duplicate-fields/index.js} +8 -28
- package/cjs/rules/{no-hashtag-description.d.cts → no-hashtag-description/index.d.cts} +3 -3
- package/cjs/rules/{no-hashtag-description.js → no-hashtag-description/index.js} +11 -31
- package/cjs/rules/no-one-place-fragments/index.d.cts +13 -0
- package/cjs/rules/{no-one-place-fragments.js → no-one-place-fragments/index.js} +11 -29
- package/cjs/rules/{no-root-type.d.cts → no-root-type/index.d.cts} +3 -3
- package/cjs/rules/{no-root-type.js → no-root-type/index.js} +9 -29
- package/cjs/rules/no-scalar-result-type-on-mutation/index.d.cts +13 -0
- package/cjs/rules/no-scalar-result-type-on-mutation/index.js +69 -0
- package/cjs/rules/no-typename-prefix/index.d.cts +13 -0
- package/cjs/rules/{no-typename-prefix.js → no-typename-prefix/index.js} +5 -25
- package/cjs/rules/no-unreachable-types/index.d.cts +13 -0
- package/cjs/rules/no-unreachable-types/index.js +155 -0
- package/cjs/rules/no-unused-fields/index.d.cts +13 -0
- package/cjs/rules/{no-unused-fields.js → no-unused-fields/index.js} +12 -30
- package/{esm/rules/relay-arguments.d.ts → cjs/rules/relay-arguments/index.d.cts} +3 -3
- package/cjs/rules/{relay-arguments.js → relay-arguments/index.js} +11 -30
- package/{esm/rules/relay-connection-types.d.ts → cjs/rules/relay-connection-types/index.d.cts} +3 -3
- package/cjs/rules/{relay-connection-types.js → relay-connection-types/index.js} +19 -40
- package/{esm/rules/relay-edge-types.d.ts → cjs/rules/relay-edge-types/index.d.cts} +3 -3
- package/cjs/rules/{relay-edge-types.js → relay-edge-types/index.js} +30 -43
- package/cjs/rules/relay-page-info/index.d.cts +13 -0
- package/cjs/rules/{relay-page-info.js → relay-page-info/index.js} +12 -30
- package/{esm/rules/require-deprecation-date.d.ts → cjs/rules/require-deprecation-date/index.d.cts} +3 -3
- package/cjs/rules/{require-deprecation-date.js → require-deprecation-date/index.js} +13 -32
- package/cjs/rules/require-deprecation-reason/index.d.cts +13 -0
- package/cjs/rules/require-deprecation-reason/index.js +66 -0
- package/cjs/rules/{require-description.d.cts → require-description/index.d.cts} +3 -3
- package/cjs/rules/{require-description.js → require-description/index.js} +30 -44
- package/cjs/rules/require-field-of-type-query-in-mutation-result/index.d.cts +13 -0
- package/cjs/rules/{require-field-of-type-query-in-mutation-result.js → require-field-of-type-query-in-mutation-result/index.js} +10 -29
- package/cjs/rules/require-import-fragment/index.d.cts +13 -0
- package/cjs/rules/{require-import-fragment.js → require-import-fragment/index.js} +11 -38
- package/cjs/rules/require-nullable-fields-with-oneof/index.d.cts +13 -0
- package/cjs/rules/require-nullable-fields-with-oneof/index.js +62 -0
- package/cjs/rules/require-nullable-result-in-root/index.d.cts +13 -0
- package/cjs/rules/{require-nullable-result-in-root.js → require-nullable-result-in-root/index.js} +12 -31
- package/cjs/rules/{require-selections.d.cts → require-selections/index.d.cts} +3 -3
- package/cjs/rules/{require-selections.js → require-selections/index.js} +38 -43
- package/cjs/rules/require-type-pattern-with-oneof/index.d.cts +13 -0
- package/cjs/rules/require-type-pattern-with-oneof/index.js +63 -0
- package/{esm/rules/selection-set-depth.d.ts → cjs/rules/selection-set-depth/index.d.cts} +3 -3
- package/cjs/rules/{selection-set-depth.js → selection-set-depth/index.js} +15 -41
- package/cjs/rules/{strict-id-in-types.d.cts → strict-id-in-types/index.d.cts} +3 -3
- package/cjs/rules/{strict-id-in-types.js → strict-id-in-types/index.js} +26 -39
- package/cjs/rules/unique-enum-value-names/index.d.cts +13 -0
- package/cjs/rules/{unique-enum-value-names.js → unique-enum-value-names/index.js} +10 -29
- package/{esm/rules/unique-fragment-name.d.ts → cjs/rules/unique-fragment-name/index.d.cts} +3 -3
- package/cjs/rules/unique-fragment-name/index.js +87 -0
- package/cjs/rules/unique-operation-name/index.d.cts +13 -0
- package/cjs/rules/{unique-operation-name.js → unique-operation-name/index.js} +7 -27
- package/cjs/schema.js +11 -36
- package/cjs/siblings.js +17 -33
- package/cjs/types.js +1 -14
- package/cjs/utils.d.cts +2 -2
- package/cjs/utils.js +71 -115
- package/esm/configs/index.d.ts +15 -5
- package/esm/configs/index.js +17 -7
- package/esm/index.d.ts +164 -9
- package/esm/index.js +9 -2
- package/esm/meta.js +1 -1
- package/{cjs/rules/alphabetize.d.cts → esm/rules/alphabetize/index.d.ts} +3 -3
- package/esm/rules/{alphabetize.js → alphabetize/index.js} +2 -2
- package/{cjs/rules/description-style.d.cts → esm/rules/description-style/index.d.ts} +3 -3
- package/esm/rules/{description-style.js → description-style/index.js} +2 -2
- package/esm/rules/index.d.ts +5 -5
- package/esm/rules/index.js +34 -34
- package/{cjs/rules/input-name.d.cts → esm/rules/input-name/index.d.ts} +3 -3
- package/esm/rules/{input-name.js → input-name/index.js} +1 -1
- package/{cjs/rules/lone-executable-definition.d.cts → esm/rules/lone-executable-definition/index.d.ts} +3 -3
- package/esm/rules/{lone-executable-definition.js → lone-executable-definition/index.js} +2 -2
- package/esm/rules/{match-document-filename.d.ts → match-document-filename/index.d.ts} +4 -4
- package/esm/rules/{match-document-filename.js → match-document-filename/index.js} +2 -2
- package/{cjs/rules/naming-convention.d.cts → esm/rules/naming-convention/index.d.ts} +3 -3
- package/esm/rules/{naming-convention.js → naming-convention/index.js} +2 -2
- package/{cjs/rules/no-anonymous-operations.d.cts → esm/rules/no-anonymous-operations/index.d.ts} +3 -3
- package/esm/rules/{no-anonymous-operations.js → no-anonymous-operations/index.js} +2 -2
- package/esm/rules/{no-deprecated.d.ts → no-deprecated/index.d.ts} +3 -3
- package/esm/rules/{no-deprecated.js → no-deprecated/index.js} +2 -2
- package/{cjs/rules/no-one-place-fragments.d.cts → esm/rules/no-duplicate-fields/index.d.ts} +3 -3
- package/esm/rules/{no-duplicate-fields.js → no-duplicate-fields/index.js} +1 -1
- package/esm/rules/{no-hashtag-description.d.ts → no-hashtag-description/index.d.ts} +3 -3
- package/esm/rules/{no-hashtag-description.js → no-hashtag-description/index.js} +2 -2
- package/{cjs/rules/no-duplicate-fields.d.cts → esm/rules/no-one-place-fragments/index.d.ts} +3 -3
- package/esm/rules/{no-one-place-fragments.js → no-one-place-fragments/index.js} +2 -2
- package/esm/rules/{no-root-type.d.ts → no-root-type/index.d.ts} +3 -3
- package/esm/rules/{no-root-type.js → no-root-type/index.js} +2 -2
- package/{cjs/rules/no-scalar-result-type-on-mutation.d.cts → esm/rules/no-scalar-result-type-on-mutation/index.d.ts} +3 -3
- package/esm/rules/{no-scalar-result-type-on-mutation.js → no-scalar-result-type-on-mutation/index.js} +2 -2
- package/esm/rules/no-typename-prefix/index.d.ts +13 -0
- package/esm/rules/{no-typename-prefix.js → no-typename-prefix/index.js} +1 -1
- package/esm/rules/no-unreachable-types/index.d.ts +13 -0
- package/esm/rules/{no-unreachable-types.js → no-unreachable-types/index.js} +3 -3
- package/esm/rules/no-unused-fields/index.d.ts +13 -0
- package/esm/rules/{no-unused-fields.js → no-unused-fields/index.js} +3 -3
- package/{cjs/rules/relay-arguments.d.cts → esm/rules/relay-arguments/index.d.ts} +3 -3
- package/esm/rules/{relay-arguments.js → relay-arguments/index.js} +2 -2
- package/{cjs/rules/relay-connection-types.d.cts → esm/rules/relay-connection-types/index.d.ts} +3 -3
- package/esm/rules/{relay-connection-types.js → relay-connection-types/index.js} +1 -1
- package/{cjs/rules/relay-edge-types.d.cts → esm/rules/relay-edge-types/index.d.ts} +3 -3
- package/esm/rules/{relay-edge-types.js → relay-edge-types/index.js} +2 -2
- package/esm/rules/relay-page-info/index.d.ts +13 -0
- package/esm/rules/{relay-page-info.js → relay-page-info/index.js} +3 -3
- package/{cjs/rules/require-deprecation-date.d.cts → esm/rules/require-deprecation-date/index.d.ts} +3 -3
- package/esm/rules/{require-deprecation-date.js → require-deprecation-date/index.js} +3 -3
- package/esm/rules/require-deprecation-reason/index.d.ts +13 -0
- package/esm/rules/{require-deprecation-reason.js → require-deprecation-reason/index.js} +3 -3
- package/esm/rules/{require-description.d.ts → require-description/index.d.ts} +3 -3
- package/esm/rules/{require-description.js → require-description/index.js} +2 -2
- package/esm/rules/require-field-of-type-query-in-mutation-result/index.d.ts +13 -0
- package/esm/rules/{require-field-of-type-query-in-mutation-result.js → require-field-of-type-query-in-mutation-result/index.js} +2 -2
- package/esm/rules/require-import-fragment/index.d.ts +13 -0
- package/esm/rules/{require-import-fragment.js → require-import-fragment/index.js} +2 -2
- package/esm/rules/require-nullable-fields-with-oneof/index.d.ts +13 -0
- package/esm/rules/{require-nullable-fields-with-oneof.js → require-nullable-fields-with-oneof/index.js} +2 -2
- package/esm/rules/require-nullable-result-in-root/index.d.ts +13 -0
- package/esm/rules/{require-nullable-result-in-root.js → require-nullable-result-in-root/index.js} +2 -2
- package/esm/rules/{require-selections.d.ts → require-selections/index.d.ts} +3 -3
- package/esm/rules/{require-selections.js → require-selections/index.js} +3 -4
- package/esm/rules/require-type-pattern-with-oneof/index.d.ts +13 -0
- package/esm/rules/{require-type-pattern-with-oneof.js → require-type-pattern-with-oneof/index.js} +2 -2
- package/{cjs/rules/selection-set-depth.d.cts → esm/rules/selection-set-depth/index.d.ts} +3 -3
- package/esm/rules/{selection-set-depth.js → selection-set-depth/index.js} +2 -2
- package/esm/rules/{strict-id-in-types.d.ts → strict-id-in-types/index.d.ts} +3 -3
- package/esm/rules/{strict-id-in-types.js → strict-id-in-types/index.js} +2 -2
- package/esm/rules/unique-enum-value-names/index.d.ts +13 -0
- package/esm/rules/{unique-enum-value-names.js → unique-enum-value-names/index.js} +2 -2
- package/{cjs/rules/unique-fragment-name.d.cts → esm/rules/unique-fragment-name/index.d.ts} +3 -3
- package/esm/rules/{unique-fragment-name.js → unique-fragment-name/index.js} +3 -3
- package/esm/rules/unique-operation-name/index.d.ts +13 -0
- package/esm/rules/{unique-operation-name.js → unique-operation-name/index.js} +2 -2
- package/esm/utils.d.ts +2 -2
- package/esm/utils.js +2 -2
- package/index.browser.js +53 -44
- package/package.json +2 -2
- package/cjs/rules/no-scalar-result-type-on-mutation.js +0 -88
- package/cjs/rules/no-typename-prefix.d.cts +0 -13
- package/cjs/rules/no-unreachable-types.d.cts +0 -13
- package/cjs/rules/no-unreachable-types.js +0 -175
- package/cjs/rules/no-unused-fields.d.cts +0 -13
- package/cjs/rules/relay-page-info.d.cts +0 -13
- package/cjs/rules/require-deprecation-reason.d.cts +0 -13
- package/cjs/rules/require-deprecation-reason.js +0 -85
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.cts +0 -13
- package/cjs/rules/require-import-fragment.d.cts +0 -13
- package/cjs/rules/require-nullable-fields-with-oneof.d.cts +0 -13
- package/cjs/rules/require-nullable-fields-with-oneof.js +0 -81
- package/cjs/rules/require-nullable-result-in-root.d.cts +0 -13
- package/cjs/rules/require-type-pattern-with-oneof.d.cts +0 -13
- package/cjs/rules/require-type-pattern-with-oneof.js +0 -83
- package/cjs/rules/unique-enum-value-names.d.cts +0 -13
- package/cjs/rules/unique-fragment-name.js +0 -106
- package/cjs/rules/unique-operation-name.d.cts +0 -13
- package/esm/rules/no-anonymous-operations.d.ts +0 -13
- package/esm/rules/no-duplicate-fields.d.ts +0 -13
- package/esm/rules/no-one-place-fragments.d.ts +0 -13
- package/esm/rules/no-scalar-result-type-on-mutation.d.ts +0 -13
- package/esm/rules/no-typename-prefix.d.ts +0 -13
- package/esm/rules/no-unreachable-types.d.ts +0 -13
- package/esm/rules/no-unused-fields.d.ts +0 -13
- package/esm/rules/relay-page-info.d.ts +0 -13
- package/esm/rules/require-deprecation-reason.d.ts +0 -13
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.ts +0 -13
- package/esm/rules/require-import-fragment.d.ts +0 -13
- package/esm/rules/require-nullable-fields-with-oneof.d.ts +0 -13
- package/esm/rules/require-nullable-result-in-root.d.ts +0 -13
- package/esm/rules/require-type-pattern-with-oneof.d.ts +0 -13
- package/esm/rules/unique-enum-value-names.d.ts +0 -13
- package/esm/rules/unique-operation-name.d.ts +0 -13
@@ -1,30 +1,27 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
});
|
20
|
-
module.exports = __toCommonJS(require_selections_exports);
|
21
|
-
var import_graphql = require("graphql"), import_utils = require("@graphql-tools/utils"), import_estree_converter = require("../estree-converter/index.js"), import_utils2 = require("../utils.js");
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-UIAXBAMD.js');
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
var _graphql = require('graphql');
|
11
|
+
var _utils = require('@graphql-tools/utils');
|
12
|
+
var _indexjs = require('../../estree-converter/index.js');
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
var _utilsjs = require('../../utils.js');
|
22
19
|
const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
23
20
|
definitions: {
|
24
21
|
asString: {
|
25
22
|
type: "string"
|
26
23
|
},
|
27
|
-
asArray:
|
24
|
+
asArray: _utilsjs.ARRAY_DEFAULT_OPTIONS
|
28
25
|
},
|
29
26
|
type: "array",
|
30
27
|
maxItems: 1,
|
@@ -38,10 +35,9 @@ const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
|
38
35
|
}
|
39
36
|
}
|
40
37
|
}
|
41
|
-
}, rule = {
|
38
|
+
}, rule = exports.rule = {
|
42
39
|
meta: {
|
43
40
|
type: "suggestion",
|
44
|
-
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- false positive since we assign `problem.suggest` conditionally
|
45
41
|
hasSuggestions: !0,
|
46
42
|
docs: {
|
47
43
|
category: "Operations",
|
@@ -108,18 +104,18 @@ Include it in your selection set{{ addition }}.`
|
|
108
104
|
schema
|
109
105
|
},
|
110
106
|
create(context) {
|
111
|
-
const schema2 = (0,
|
107
|
+
const schema2 = _utilsjs.requireGraphQLSchemaFromContext.call(void 0, RULE_ID, context), siblings = _utilsjs.requireSiblingsOperations.call(void 0, RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = _utils.asArray.call(void 0, fieldName), selector = "OperationDefinition SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new (0, _graphql.TypeInfo)(schema2);
|
112
108
|
function checkFragments(node) {
|
113
109
|
for (const selection of node.selections) {
|
114
|
-
if (selection.kind !==
|
110
|
+
if (selection.kind !== _graphql.Kind.FRAGMENT_SPREAD)
|
115
111
|
continue;
|
116
112
|
const [foundSpread] = siblings.getFragment(selection.name.value);
|
117
113
|
if (!foundSpread)
|
118
114
|
continue;
|
119
|
-
const checkedFragmentSpreads = /* @__PURE__ */ new Set(), visitor = (0,
|
115
|
+
const checkedFragmentSpreads = /* @__PURE__ */ new Set(), visitor = _graphql.visitWithTypeInfo.call(void 0, typeInfo, {
|
120
116
|
SelectionSet(node2, key, _parent) {
|
121
117
|
const parent = _parent;
|
122
|
-
parent.kind ===
|
118
|
+
parent.kind === _graphql.Kind.FRAGMENT_DEFINITION ? checkedFragmentSpreads.add(parent.name.value) : parent.kind !== _graphql.Kind.INLINE_FRAGMENT && checkSelections(
|
123
119
|
node2,
|
124
120
|
typeInfo.getType(),
|
125
121
|
selection.loc.start,
|
@@ -128,16 +124,16 @@ Include it in your selection set{{ addition }}.`
|
|
128
124
|
);
|
129
125
|
}
|
130
126
|
});
|
131
|
-
(0,
|
127
|
+
_graphql.visit.call(void 0, foundSpread.document, visitor);
|
132
128
|
}
|
133
129
|
}
|
134
130
|
function checkSelections(node, type, loc, parent, checkedFragmentSpreads = /* @__PURE__ */ new Set()) {
|
135
|
-
const rawType = (0,
|
136
|
-
if (rawType instanceof
|
131
|
+
const rawType = _indexjs.getBaseType.call(void 0, type);
|
132
|
+
if (rawType instanceof _graphql.GraphQLObjectType || rawType instanceof _graphql.GraphQLInterfaceType)
|
137
133
|
checkFields(rawType);
|
138
|
-
else if (rawType instanceof
|
134
|
+
else if (rawType instanceof _graphql.GraphQLUnionType) {
|
139
135
|
for (const selection of node.selections)
|
140
|
-
if (selection.kind ===
|
136
|
+
if (selection.kind === _graphql.Kind.INLINE_FRAGMENT) {
|
141
137
|
const t = rawType.getTypes().find((t2) => t2.name === selection.typeCondition.name.value);
|
142
138
|
t && checkFields(t);
|
143
139
|
}
|
@@ -148,11 +144,11 @@ Include it in your selection set{{ addition }}.`
|
|
148
144
|
return;
|
149
145
|
function hasIdField({ selections }) {
|
150
146
|
return selections.some((selection) => {
|
151
|
-
if (selection.kind ===
|
147
|
+
if (selection.kind === _graphql.Kind.FIELD)
|
152
148
|
return selection.alias && idNames.includes(selection.alias.value) ? !0 : idNames.includes(selection.name.value);
|
153
|
-
if (selection.kind ===
|
149
|
+
if (selection.kind === _graphql.Kind.INLINE_FRAGMENT)
|
154
150
|
return hasIdField(selection.selectionSet);
|
155
|
-
if (selection.kind ===
|
151
|
+
if (selection.kind === _graphql.Kind.FRAGMENT_SPREAD) {
|
156
152
|
const [foundSpread] = siblings.getFragment(selection.name.value);
|
157
153
|
if (foundSpread) {
|
158
154
|
const fragmentSpread = foundSpread.document;
|
@@ -165,9 +161,9 @@ Include it in your selection set{{ addition }}.`
|
|
165
161
|
const hasId = hasIdField(node);
|
166
162
|
if (checkFragments(node), hasId)
|
167
163
|
return;
|
168
|
-
const pluralSuffix = idNames.length > 1 ? "s" : "", fieldName2 = (0,
|
164
|
+
const pluralSuffix = idNames.length > 1 ? "s" : "", fieldName2 = _utilsjs.englishJoinWords.call(void 0,
|
169
165
|
idNames.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
|
170
|
-
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${(0,
|
166
|
+
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${_utilsjs.englishJoinWords.call(void 0, [...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
171
167
|
loc,
|
172
168
|
messageId: RULE_ID,
|
173
169
|
data: {
|
@@ -180,7 +176,7 @@ Include it in your selection set{{ addition }}.`
|
|
180
176
|
desc: `Add \`${idName}\` selection`,
|
181
177
|
fix: (fixer) => {
|
182
178
|
let insertNode = node.selections[0];
|
183
|
-
return insertNode = insertNode.kind ===
|
179
|
+
return insertNode = insertNode.kind === _graphql.Kind.INLINE_FRAGMENT ? insertNode.selectionSet.selections[0] : insertNode, fixer.insertTextBefore(insertNode, `${idName} `);
|
184
180
|
}
|
185
181
|
}))), context.report(problem);
|
186
182
|
}
|
@@ -193,7 +189,6 @@ Include it in your selection set{{ addition }}.`
|
|
193
189
|
};
|
194
190
|
}
|
195
191
|
};
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
});
|
192
|
+
|
193
|
+
|
194
|
+
exports.rule = rule;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { GraphQLESLintRule } from '../../types.cjs';
|
2
|
+
import 'eslint';
|
3
|
+
import 'estree';
|
4
|
+
import 'graphql';
|
5
|
+
import 'graphql-config';
|
6
|
+
import 'json-schema-to-ts';
|
7
|
+
import '../../estree-converter/types.cjs';
|
8
|
+
import '../../siblings.cjs';
|
9
|
+
import '@graphql-tools/utils';
|
10
|
+
|
11
|
+
declare const rule: GraphQLESLintRule;
|
12
|
+
|
13
|
+
export { rule };
|
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../../chunk-UIAXBAMD.js');
|
2
|
+
var _utilsjs = require('../../utils.js');
|
3
|
+
const RULE_ID = "require-type-pattern-with-oneof", rule = exports.rule = {
|
4
|
+
meta: {
|
5
|
+
type: "suggestion",
|
6
|
+
docs: {
|
7
|
+
category: "Schema",
|
8
|
+
description: "Enforce types with `@oneOf` directive have `error` and `ok` fields.",
|
9
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
10
|
+
examples: [
|
11
|
+
{
|
12
|
+
title: "Correct",
|
13
|
+
code: (
|
14
|
+
/* GraphQL */
|
15
|
+
`
|
16
|
+
type Mutation {
|
17
|
+
doSomething: DoSomethingMutationResult!
|
18
|
+
}
|
19
|
+
|
20
|
+
interface Error {
|
21
|
+
message: String!
|
22
|
+
}
|
23
|
+
|
24
|
+
type DoSomethingMutationResult @oneOf {
|
25
|
+
ok: DoSomethingSuccess
|
26
|
+
error: Error
|
27
|
+
}
|
28
|
+
|
29
|
+
type DoSomethingSuccess {
|
30
|
+
# ...
|
31
|
+
}
|
32
|
+
`
|
33
|
+
)
|
34
|
+
}
|
35
|
+
]
|
36
|
+
},
|
37
|
+
messages: {
|
38
|
+
[RULE_ID]: '{{ nodeName }} is defined as output with "@oneOf" and must be defined with "{{ fieldName }}" field'
|
39
|
+
},
|
40
|
+
schema: []
|
41
|
+
},
|
42
|
+
create(context) {
|
43
|
+
return {
|
44
|
+
"Directive[name.value=oneOf][parent.kind=ObjectTypeDefinition]"({
|
45
|
+
parent
|
46
|
+
}) {
|
47
|
+
const requiredFields = ["error", "ok"];
|
48
|
+
for (const fieldName of requiredFields)
|
49
|
+
_optionalChain([parent, 'access', _ => _.fields, 'optionalAccess', _2 => _2.some, 'call', _3 => _3((field) => field.name.value === fieldName)]) || context.report({
|
50
|
+
node: parent.name,
|
51
|
+
messageId: RULE_ID,
|
52
|
+
data: {
|
53
|
+
nodeName: _utilsjs.displayNodeName.call(void 0, parent),
|
54
|
+
fieldName
|
55
|
+
}
|
56
|
+
});
|
57
|
+
}
|
58
|
+
};
|
59
|
+
}
|
60
|
+
};
|
61
|
+
|
62
|
+
|
63
|
+
exports.rule = rule;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import { GraphQLESLintRule } from '
|
2
|
+
import { GraphQLESLintRule } from '../../types.cjs';
|
3
3
|
import 'eslint';
|
4
4
|
import 'estree';
|
5
5
|
import 'graphql';
|
6
6
|
import 'graphql-config';
|
7
|
-
import '
|
8
|
-
import '
|
7
|
+
import '../../estree-converter/types.cjs';
|
8
|
+
import '../../siblings.cjs';
|
9
9
|
import '@graphql-tools/utils';
|
10
10
|
|
11
11
|
declare const schema: {
|
@@ -1,32 +1,7 @@
|
|
1
|
-
"use strict";
|
2
|
-
var
|
3
|
-
var
|
4
|
-
var
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
8
|
-
for (var name in all)
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
10
|
-
}, __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from == "object" || typeof from == "function")
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
return to;
|
15
|
-
};
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
22
|
-
mod
|
23
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
24
|
-
var selection_set_depth_exports = {};
|
25
|
-
__export(selection_set_depth_exports, {
|
26
|
-
rule: () => rule
|
27
|
-
});
|
28
|
-
module.exports = __toCommonJS(selection_set_depth_exports);
|
29
|
-
var import_graphql = require("graphql"), import_graphql_depth_limit = __toESM(require("graphql-depth-limit"), 1), import_utils = require("../utils.js");
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }require('../../chunk-UIAXBAMD.js');
|
2
|
+
var _graphql = require('graphql');
|
3
|
+
var _graphqldepthlimit = require('graphql-depth-limit'); var _graphqldepthlimit2 = _interopRequireDefault(_graphqldepthlimit);
|
4
|
+
var _utilsjs = require('../../utils.js');
|
30
5
|
const RULE_ID = "selection-set-depth", schema = {
|
31
6
|
type: "array",
|
32
7
|
minItems: 1,
|
@@ -39,10 +14,10 @@ const RULE_ID = "selection-set-depth", schema = {
|
|
39
14
|
maxDepth: {
|
40
15
|
type: "number"
|
41
16
|
},
|
42
|
-
ignore:
|
17
|
+
ignore: _utilsjs.ARRAY_DEFAULT_OPTIONS
|
43
18
|
}
|
44
19
|
}
|
45
|
-
}, rule = {
|
20
|
+
}, rule = exports.rule = {
|
46
21
|
meta: {
|
47
22
|
type: "suggestion",
|
48
23
|
hasSuggestions: !0,
|
@@ -100,18 +75,18 @@ const RULE_ID = "selection-set-depth", schema = {
|
|
100
75
|
create(context) {
|
101
76
|
let siblings = null;
|
102
77
|
try {
|
103
|
-
siblings = (0,
|
104
|
-
} catch {
|
105
|
-
|
78
|
+
siblings = _utilsjs.requireSiblingsOperations.call(void 0, RULE_ID, context);
|
79
|
+
} catch (e2) {
|
80
|
+
_utilsjs.logger.warn(
|
106
81
|
`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`
|
107
82
|
);
|
108
83
|
}
|
109
|
-
const { maxDepth, ignore = [] } = context.options[0], checkFn = (0,
|
84
|
+
const { maxDepth, ignore = [] } = context.options[0], checkFn = _graphqldepthlimit2.default.call(void 0, maxDepth, { ignore });
|
110
85
|
return {
|
111
86
|
"OperationDefinition, FragmentDefinition"(node) {
|
112
87
|
try {
|
113
88
|
const rawNode = node.rawNode(), fragmentsInUse = siblings ? siblings.getFragmentsInUse(rawNode) : [], document = {
|
114
|
-
kind:
|
89
|
+
kind: _graphql.Kind.DOCUMENT,
|
115
90
|
definitions: [rawNode, ...fragmentsInUse]
|
116
91
|
};
|
117
92
|
checkFn({
|
@@ -144,7 +119,7 @@ const RULE_ID = "selection-set-depth", schema = {
|
|
144
119
|
}
|
145
120
|
});
|
146
121
|
} catch (e) {
|
147
|
-
|
122
|
+
_utilsjs.logger.warn(
|
148
123
|
`Rule "${RULE_ID}" check failed due to a missing siblings operations. For more info: https://bit.ly/graphql-eslint-operations`,
|
149
124
|
e
|
150
125
|
);
|
@@ -153,7 +128,6 @@ const RULE_ID = "selection-set-depth", schema = {
|
|
153
128
|
};
|
154
129
|
}
|
155
130
|
};
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
});
|
131
|
+
|
132
|
+
|
133
|
+
exports.rule = rule;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import { GraphQLESLintRule } from '
|
2
|
+
import { GraphQLESLintRule } from '../../types.cjs';
|
3
3
|
import 'eslint';
|
4
4
|
import 'estree';
|
5
5
|
import 'graphql';
|
6
6
|
import 'graphql-config';
|
7
|
-
import '
|
8
|
-
import '
|
7
|
+
import '../../estree-converter/types.cjs';
|
8
|
+
import '../../siblings.cjs';
|
9
9
|
import '@graphql-tools/utils';
|
10
10
|
|
11
11
|
declare const schema: {
|
@@ -1,24 +1,12 @@
|
|
1
|
-
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
-
return to;
|
14
|
-
};
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
16
|
-
var strict_id_in_types_exports = {};
|
17
|
-
__export(strict_id_in_types_exports, {
|
18
|
-
rule: () => rule
|
19
|
-
});
|
20
|
-
module.exports = __toCommonJS(strict_id_in_types_exports);
|
21
|
-
var import_graphql = require("graphql"), import_utils = require("../utils.js");
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../../chunk-UIAXBAMD.js');
|
2
|
+
var _graphql = require('graphql');
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
var _utilsjs = require('../../utils.js');
|
22
10
|
const RULE_ID = "strict-id-in-types", schema = {
|
23
11
|
type: "array",
|
24
12
|
maxItems: 1,
|
@@ -27,11 +15,11 @@ const RULE_ID = "strict-id-in-types", schema = {
|
|
27
15
|
additionalProperties: !1,
|
28
16
|
properties: {
|
29
17
|
acceptedIdNames: {
|
30
|
-
...
|
18
|
+
..._utilsjs.ARRAY_DEFAULT_OPTIONS,
|
31
19
|
default: ["id"]
|
32
20
|
},
|
33
21
|
acceptedIdTypes: {
|
34
|
-
...
|
22
|
+
..._utilsjs.ARRAY_DEFAULT_OPTIONS,
|
35
23
|
default: ["ID"]
|
36
24
|
},
|
37
25
|
exceptions: {
|
@@ -39,18 +27,18 @@ const RULE_ID = "strict-id-in-types", schema = {
|
|
39
27
|
additionalProperties: !1,
|
40
28
|
properties: {
|
41
29
|
types: {
|
42
|
-
...
|
30
|
+
..._utilsjs.ARRAY_DEFAULT_OPTIONS,
|
43
31
|
description: "This is used to exclude types with names that match one of the specified values."
|
44
32
|
},
|
45
33
|
suffixes: {
|
46
|
-
...
|
34
|
+
..._utilsjs.ARRAY_DEFAULT_OPTIONS,
|
47
35
|
description: "This is used to exclude types with names with suffixes that match one of the specified values."
|
48
36
|
}
|
49
37
|
}
|
50
38
|
}
|
51
39
|
}
|
52
40
|
}
|
53
|
-
}, rule = {
|
41
|
+
}, rule = exports.rule = {
|
54
42
|
meta: {
|
55
43
|
type: "suggestion",
|
56
44
|
docs: {
|
@@ -135,34 +123,33 @@ const RULE_ID = "strict-id-in-types", schema = {
|
|
135
123
|
acceptedIdTypes: ["ID"],
|
136
124
|
exceptions: {},
|
137
125
|
...context.options[0]
|
138
|
-
}, schema2 = (0,
|
126
|
+
}, schema2 = _utilsjs.requireGraphQLSchemaFromContext.call(void 0, RULE_ID, context);
|
139
127
|
return {
|
140
128
|
[`ObjectTypeDefinition[name.value!=/^(${[
|
141
129
|
schema2.getQueryType(),
|
142
130
|
schema2.getMutationType(),
|
143
131
|
schema2.getSubscriptionType()
|
144
|
-
].filter(
|
132
|
+
].filter(_utilsjs.truthy).map((type) => type.name).join("|")})$/]`](node) {
|
145
133
|
const typeName = node.name.value;
|
146
|
-
if (options.exceptions.types
|
134
|
+
if (_optionalChain([options, 'access', _ => _.exceptions, 'access', _2 => _2.types, 'optionalAccess', _3 => _3.includes, 'call', _4 => _4(typeName)]) || _optionalChain([options, 'access', _5 => _5.exceptions, 'access', _6 => _6.suffixes, 'optionalAccess', _7 => _7.some, 'call', _8 => _8((suffix) => typeName.endsWith(suffix))]))
|
147
135
|
return;
|
148
|
-
if (node.fields
|
136
|
+
if (_optionalChain([node, 'access', _9 => _9.fields, 'optionalAccess', _10 => _10.filter, 'call', _11 => _11((field) => {
|
149
137
|
const fieldNode = field.rawNode(), isValidIdName = options.acceptedIdNames.includes(fieldNode.name.value);
|
150
138
|
let isValidIdType = !1;
|
151
|
-
return fieldNode.type.kind ===
|
152
|
-
})
|
139
|
+
return fieldNode.type.kind === _graphql.Kind.NON_NULL_TYPE && fieldNode.type.type.kind === _graphql.Kind.NAMED_TYPE && (isValidIdType = options.acceptedIdTypes.includes(fieldNode.type.type.name.value)), isValidIdName && isValidIdType;
|
140
|
+
}), 'optionalAccess', _12 => _12.length]) !== 1) {
|
153
141
|
const pluralNamesSuffix = options.acceptedIdNames.length > 1 ? "s" : "", pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? "s" : "";
|
154
142
|
context.report({
|
155
143
|
node: node.name,
|
156
|
-
message: `${(0,
|
157
|
-
Accepted name${pluralNamesSuffix}: ${(0,
|
158
|
-
Accepted type${pluralTypesSuffix}: ${(0,
|
144
|
+
message: `${_utilsjs.displayNodeName.call(void 0, node)} must have exactly one non-nullable unique identifier.
|
145
|
+
Accepted name${pluralNamesSuffix}: ${_utilsjs.englishJoinWords.call(void 0, options.acceptedIdNames)}.
|
146
|
+
Accepted type${pluralTypesSuffix}: ${_utilsjs.englishJoinWords.call(void 0, options.acceptedIdTypes)}.`
|
159
147
|
});
|
160
148
|
}
|
161
149
|
}
|
162
150
|
};
|
163
151
|
}
|
164
152
|
};
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
});
|
153
|
+
|
154
|
+
|
155
|
+
exports.rule = rule;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { GraphQLESLintRule } from '../../types.cjs';
|
2
|
+
import 'eslint';
|
3
|
+
import 'estree';
|
4
|
+
import 'graphql';
|
5
|
+
import 'graphql-config';
|
6
|
+
import 'json-schema-to-ts';
|
7
|
+
import '../../estree-converter/types.cjs';
|
8
|
+
import '../../siblings.cjs';
|
9
|
+
import '@graphql-tools/utils';
|
10
|
+
|
11
|
+
declare const rule: GraphQLESLintRule;
|
12
|
+
|
13
|
+
export { rule };
|
@@ -1,24 +1,6 @@
|
|
1
|
-
"use strict";
|
2
|
-
var
|
3
|
-
var
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
-
return to;
|
14
|
-
};
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
16
|
-
var unique_enum_value_names_exports = {};
|
17
|
-
__export(unique_enum_value_names_exports, {
|
18
|
-
rule: () => rule
|
19
|
-
});
|
20
|
-
module.exports = __toCommonJS(unique_enum_value_names_exports);
|
21
|
-
var import_graphql = require("graphql"), import_utils = require("../utils.js");
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../../chunk-UIAXBAMD.js');
|
2
|
+
var _graphql = require('graphql');
|
3
|
+
var _utilsjs = require('../../utils.js');
|
22
4
|
const rule = {
|
23
5
|
meta: {
|
24
6
|
type: "suggestion",
|
@@ -62,15 +44,15 @@ const rule = {
|
|
62
44
|
},
|
63
45
|
create(context) {
|
64
46
|
return {
|
65
|
-
[[
|
66
|
-
const duplicates = node.values
|
47
|
+
[[_graphql.Kind.ENUM_TYPE_DEFINITION, _graphql.Kind.ENUM_TYPE_EXTENSION].join(",")](node) {
|
48
|
+
const duplicates = _optionalChain([node, 'access', _ => _.values, 'optionalAccess', _2 => _2.filter, 'call', _3 => _3(
|
67
49
|
(item, index, array) => array.findIndex((v) => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index
|
68
|
-
);
|
50
|
+
)]);
|
69
51
|
for (const duplicate of duplicates || []) {
|
70
52
|
const enumName = duplicate.name.value;
|
71
53
|
context.report({
|
72
54
|
node: duplicate.name,
|
73
|
-
message: `Unexpected case-insensitive enum values duplicates for ${(0,
|
55
|
+
message: `Unexpected case-insensitive enum values duplicates for ${_utilsjs.getNodeName.call(void 0,
|
74
56
|
duplicate
|
75
57
|
)}`,
|
76
58
|
suggest: [
|
@@ -85,7 +67,6 @@ const rule = {
|
|
85
67
|
};
|
86
68
|
}
|
87
69
|
};
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
});
|
70
|
+
|
71
|
+
|
72
|
+
exports.rule = rule;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { ExecutableDefinitionNode } from 'graphql';
|
2
|
-
import { GraphQLESTreeNode } from '
|
3
|
-
import { GraphQLESLintRuleContext, GraphQLESLintRule } from '
|
2
|
+
import { GraphQLESTreeNode } from '../../estree-converter/types.cjs';
|
3
|
+
import { GraphQLESLintRuleContext, GraphQLESLintRule } from '../../types.cjs';
|
4
4
|
import 'eslint';
|
5
5
|
import 'estree';
|
6
6
|
import 'graphql-config';
|
7
7
|
import 'json-schema-to-ts';
|
8
|
-
import '
|
8
|
+
import '../../siblings.cjs';
|
9
9
|
import '@graphql-tools/utils';
|
10
10
|
|
11
11
|
declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string) => void;
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../../chunk-UIAXBAMD.js');
|
2
|
+
var _nodepath = require('node:path');
|
3
|
+
var _graphql = require('graphql');
|
4
|
+
var _utilsjs = require('../../utils.js');
|
5
|
+
const RULE_ID = "unique-fragment-name", checkNode = exports.checkNode = (context, node, ruleId) => {
|
6
|
+
const documentName = node.name.value, siblings = _utilsjs.requireSiblingsOperations.call(void 0, ruleId, context), siblingDocuments = node.kind === _graphql.Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName), filepath = context.filename, conflictingDocuments = siblingDocuments.filter((f) => {
|
7
|
+
const isSameName = _optionalChain([f, 'access', _ => _.document, 'access', _2 => _2.name, 'optionalAccess', _3 => _3.value]) === documentName, isSamePath = _utilsjs.slash.call(void 0, f.filePath) === _utilsjs.slash.call(void 0, filepath);
|
8
|
+
return isSameName && !isSamePath;
|
9
|
+
});
|
10
|
+
conflictingDocuments.length > 0 && context.report({
|
11
|
+
messageId: ruleId,
|
12
|
+
data: {
|
13
|
+
documentName,
|
14
|
+
summary: conflictingDocuments.map((f) => ` ${_nodepath.relative.call(void 0, _utilsjs.CWD, f.filePath.replace(_utilsjs.VIRTUAL_DOCUMENT_REGEX, ""))}`).join(`
|
15
|
+
`)
|
16
|
+
},
|
17
|
+
// @ts-expect-error name will exist
|
18
|
+
node: node.name
|
19
|
+
});
|
20
|
+
}, rule = exports.rule = {
|
21
|
+
meta: {
|
22
|
+
type: "suggestion",
|
23
|
+
docs: {
|
24
|
+
category: "Operations",
|
25
|
+
description: "Enforce unique fragment names across your project.",
|
26
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
27
|
+
requiresSiblings: !0,
|
28
|
+
recommended: !0,
|
29
|
+
examples: [
|
30
|
+
{
|
31
|
+
title: "Incorrect",
|
32
|
+
code: (
|
33
|
+
/* GraphQL */
|
34
|
+
`
|
35
|
+
# user.fragment.graphql
|
36
|
+
fragment UserFields on User {
|
37
|
+
id
|
38
|
+
name
|
39
|
+
fullName
|
40
|
+
}
|
41
|
+
|
42
|
+
# user-fields.graphql
|
43
|
+
fragment UserFields on User {
|
44
|
+
id
|
45
|
+
}
|
46
|
+
`
|
47
|
+
)
|
48
|
+
},
|
49
|
+
{
|
50
|
+
title: "Correct",
|
51
|
+
code: (
|
52
|
+
/* GraphQL */
|
53
|
+
`
|
54
|
+
# user.fragment.graphql
|
55
|
+
fragment AllUserFields on User {
|
56
|
+
id
|
57
|
+
name
|
58
|
+
fullName
|
59
|
+
}
|
60
|
+
|
61
|
+
# user-fields.graphql
|
62
|
+
fragment UserFields on User {
|
63
|
+
id
|
64
|
+
}
|
65
|
+
`
|
66
|
+
)
|
67
|
+
}
|
68
|
+
]
|
69
|
+
},
|
70
|
+
messages: {
|
71
|
+
[RULE_ID]: `Fragment named "{{ documentName }}" already defined in:
|
72
|
+
{{ summary }}`
|
73
|
+
},
|
74
|
+
schema: []
|
75
|
+
},
|
76
|
+
create(context) {
|
77
|
+
return {
|
78
|
+
FragmentDefinition(node) {
|
79
|
+
checkNode(context, node, RULE_ID);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
exports.checkNode = checkNode; exports.rule = rule;
|