@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810155929-e89edf7
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/cjs/cache.js +10 -19
- package/cjs/configs/index.d.ts +42 -16
- package/cjs/configs/index.js +10 -19
- package/cjs/configs/operations-all.d.ts +4 -3
- package/cjs/configs/operations-all.js +5 -4
- package/cjs/configs/operations-recommended.d.ts +3 -1
- package/cjs/configs/operations-recommended.js +3 -1
- package/cjs/configs/schema-all.d.ts +6 -1
- package/cjs/configs/schema-all.js +5 -2
- package/cjs/configs/schema-recommended.d.ts +19 -1
- package/cjs/configs/schema-recommended.js +22 -2
- package/cjs/documents.js +17 -32
- package/cjs/estree-converter/converter.js +14 -27
- package/cjs/estree-converter/index.js +4 -7
- package/cjs/estree-converter/types.js +3 -5
- package/cjs/estree-converter/utils.d.ts +2 -3
- package/cjs/estree-converter/utils.js +15 -45
- package/cjs/flat-configs.d.ts +59 -12
- package/cjs/flat-configs.js +9 -14
- package/cjs/graphql-config.d.ts +4 -3
- package/cjs/graphql-config.js +23 -44
- package/cjs/index.d.ts +10 -4
- package/cjs/index.js +8 -16
- package/cjs/parser.d.ts +4 -3
- package/cjs/parser.js +38 -45
- package/cjs/processor.d.ts +5 -1
- package/cjs/processor.js +25 -57
- package/cjs/rules/alphabetize.d.ts +6 -16
- package/cjs/rules/alphabetize.js +60 -132
- package/cjs/rules/description-style.d.ts +4 -3
- package/cjs/rules/description-style.js +11 -18
- package/cjs/rules/graphql-js-validation.d.ts +4 -3
- package/cjs/rules/graphql-js-validation.js +151 -225
- package/cjs/rules/index.d.ts +15 -13
- package/cjs/rules/index.js +8 -45
- package/cjs/rules/input-name.d.ts +4 -3
- package/cjs/rules/input-name.js +43 -59
- package/cjs/rules/lone-executable-definition.d.ts +6 -5
- package/cjs/rules/lone-executable-definition.js +14 -28
- package/cjs/rules/match-document-filename.d.ts +4 -3
- package/cjs/rules/match-document-filename.js +39 -70
- package/cjs/rules/naming-convention.d.ts +4 -3
- package/cjs/rules/naming-convention.js +56 -74
- package/cjs/rules/no-anonymous-operations.d.ts +4 -3
- package/cjs/rules/no-anonymous-operations.js +11 -18
- package/cjs/rules/no-deprecated.d.ts +4 -3
- package/cjs/rules/no-deprecated.js +15 -29
- package/cjs/rules/no-duplicate-fields.d.ts +4 -3
- package/cjs/rules/no-duplicate-fields.js +13 -23
- package/cjs/rules/no-hashtag-description.d.ts +4 -3
- package/cjs/rules/no-hashtag-description.js +16 -29
- package/cjs/rules/no-one-place-fragments.d.ts +4 -3
- package/cjs/rules/no-one-place-fragments.js +17 -29
- package/cjs/rules/no-root-type.d.ts +4 -3
- package/cjs/rules/no-root-type.js +15 -25
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
- package/cjs/rules/no-typename-prefix.d.ts +4 -3
- package/cjs/rules/no-typename-prefix.js +26 -33
- package/cjs/rules/no-unreachable-types.d.ts +4 -3
- package/cjs/rules/no-unreachable-types.js +25 -47
- package/cjs/rules/no-unused-fields.d.ts +4 -3
- package/cjs/rules/no-unused-fields.js +24 -49
- package/cjs/rules/relay-arguments.d.ts +4 -3
- package/cjs/rules/relay-arguments.js +20 -43
- package/cjs/rules/relay-connection-types.d.ts +4 -3
- package/cjs/rules/relay-connection-types.js +14 -45
- package/cjs/rules/relay-edge-types.d.ts +4 -3
- package/cjs/rules/relay-edge-types.js +48 -99
- package/cjs/rules/relay-page-info.d.ts +4 -3
- package/cjs/rules/relay-page-info.js +21 -44
- package/cjs/rules/require-deprecation-date.d.ts +4 -3
- package/cjs/rules/require-deprecation-date.js +15 -31
- package/cjs/rules/require-deprecation-reason.d.ts +4 -3
- package/cjs/rules/require-deprecation-reason.js +12 -20
- package/cjs/rules/require-description.d.ts +4 -3
- package/cjs/rules/require-description.js +39 -65
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
- package/cjs/rules/require-import-fragment.d.ts +4 -3
- package/cjs/rules/require-import-fragment.js +22 -40
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
- package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
- package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
- package/cjs/rules/require-nullable-result-in-root.js +34 -44
- package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
- package/cjs/rules/require-selections.js +198 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
- package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
- package/cjs/rules/selection-set-depth.d.ts +4 -3
- package/cjs/rules/selection-set-depth.js +18 -34
- package/cjs/rules/strict-id-in-types.d.ts +4 -3
- package/cjs/rules/strict-id-in-types.js +25 -43
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
- package/cjs/rules/unique-fragment-name.d.ts +3 -2
- package/cjs/rules/unique-fragment-name.js +24 -36
- package/cjs/rules/unique-operation-name.d.ts +4 -3
- package/cjs/rules/unique-operation-name.js +10 -12
- package/cjs/schema.d.ts +4 -3
- package/cjs/schema.js +14 -27
- package/cjs/siblings.d.ts +24 -8
- package/cjs/siblings.js +42 -82
- package/cjs/types.d.ts +74 -7
- package/cjs/types.js +3 -5
- package/cjs/utils.d.ts +3 -2
- package/cjs/utils.js +27 -44
- package/esm/cache.js +4 -8
- package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
- package/esm/configs/index.d.mts +42 -16
- package/esm/configs/index.js +4 -4
- package/esm/configs/operations-all.d.mts +4 -3
- package/esm/configs/operations-all.js +6 -5
- package/esm/configs/operations-recommended.d.mts +3 -1
- package/esm/configs/operations-recommended.js +4 -2
- package/esm/configs/schema-all.d.mts +6 -1
- package/esm/configs/schema-all.js +6 -3
- package/esm/configs/schema-recommended.d.mts +19 -1
- package/esm/configs/schema-recommended.js +23 -3
- package/esm/configs/{relay.js → schema-relay.js} +4 -4
- package/esm/documents.js +10 -17
- package/esm/estree-converter/converter.js +9 -18
- package/esm/estree-converter/utils.d.mts +2 -3
- package/esm/estree-converter/utils.js +11 -38
- package/esm/flat-configs.d.mts +59 -12
- package/esm/flat-configs.js +4 -5
- package/esm/graphql-config.d.mts +4 -3
- package/esm/graphql-config.js +18 -34
- package/esm/index.d.mts +10 -4
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +4 -3
- package/esm/parser.js +33 -27
- package/esm/processor.d.mts +5 -1
- package/esm/processor.js +21 -46
- package/esm/rules/alphabetize.d.mts +6 -16
- package/esm/rules/alphabetize.js +53 -118
- package/esm/rules/description-style.d.mts +4 -3
- package/esm/rules/description-style.js +7 -11
- package/esm/rules/graphql-js-validation.d.mts +4 -3
- package/esm/rules/graphql-js-validation.js +178 -218
- package/esm/rules/index.d.mts +15 -13
- package/esm/rules/index.js +5 -5
- package/esm/rules/input-name.d.mts +4 -3
- package/esm/rules/input-name.js +39 -52
- package/esm/rules/lone-executable-definition.d.mts +6 -5
- package/esm/rules/lone-executable-definition.js +10 -20
- package/esm/rules/match-document-filename.d.mts +4 -3
- package/esm/rules/match-document-filename.js +35 -61
- package/esm/rules/naming-convention.d.mts +4 -3
- package/esm/rules/naming-convention.js +51 -65
- package/esm/rules/no-anonymous-operations.d.mts +4 -3
- package/esm/rules/no-anonymous-operations.js +6 -9
- package/esm/rules/no-deprecated.d.mts +4 -3
- package/esm/rules/no-deprecated.js +10 -20
- package/esm/rules/no-duplicate-fields.d.mts +4 -3
- package/esm/rules/no-duplicate-fields.js +9 -16
- package/esm/rules/no-hashtag-description.d.mts +4 -3
- package/esm/rules/no-hashtag-description.js +11 -20
- package/esm/rules/no-one-place-fragments.d.mts +4 -3
- package/esm/rules/no-one-place-fragments.js +12 -19
- package/esm/rules/no-root-type.d.mts +4 -3
- package/esm/rules/no-root-type.js +11 -18
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
- package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
- package/esm/rules/no-typename-prefix.d.mts +4 -3
- package/esm/rules/no-typename-prefix.js +22 -26
- package/esm/rules/no-unreachable-types.d.mts +4 -3
- package/esm/rules/no-unreachable-types.js +18 -33
- package/esm/rules/no-unused-fields.d.mts +4 -3
- package/esm/rules/no-unused-fields.js +19 -40
- package/esm/rules/relay-arguments.d.mts +4 -3
- package/esm/rules/relay-arguments.js +15 -34
- package/esm/rules/relay-connection-types.d.mts +4 -3
- package/esm/rules/relay-connection-types.js +10 -38
- package/esm/rules/relay-edge-types.d.mts +4 -3
- package/esm/rules/relay-edge-types.js +43 -89
- package/esm/rules/relay-page-info.d.mts +4 -3
- package/esm/rules/relay-page-info.js +16 -34
- package/esm/rules/require-deprecation-date.d.mts +4 -3
- package/esm/rules/require-deprecation-date.js +10 -22
- package/esm/rules/require-deprecation-reason.d.mts +4 -3
- package/esm/rules/require-deprecation-reason.js +7 -11
- package/esm/rules/require-description.d.mts +4 -3
- package/esm/rules/require-description.js +34 -55
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
- package/esm/rules/require-import-fragment.d.mts +4 -3
- package/esm/rules/require-import-fragment.js +14 -26
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
- package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
- package/esm/rules/require-nullable-result-in-root.js +29 -35
- package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
- package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
- package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
- package/esm/rules/require-type-pattern-with-oneof.js +11 -16
- package/esm/rules/selection-set-depth.d.mts +4 -3
- package/esm/rules/selection-set-depth.js +11 -20
- package/esm/rules/strict-id-in-types.d.mts +4 -3
- package/esm/rules/strict-id-in-types.js +20 -34
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
- package/esm/rules/unique-fragment-name.d.mts +3 -2
- package/esm/rules/unique-fragment-name.js +20 -27
- package/esm/rules/unique-operation-name.d.mts +4 -3
- package/esm/rules/unique-operation-name.js +6 -5
- package/esm/schema.d.mts +4 -3
- package/esm/schema.js +7 -12
- package/esm/siblings.d.mts +24 -8
- package/esm/siblings.js +37 -73
- package/esm/types.d.mts +74 -7
- package/esm/utils.d.mts +3 -2
- package/esm/utils.js +20 -31
- package/index.browser.mjs +5323 -0
- package/package.json +8 -13
- package/cjs/rules/require-id-when-available.js +0 -241
- package/cjs/types-8d5f4ae0.d.ts +0 -107
- package/esm/types-ace77d86.d.ts +0 -107
- /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
- /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
- /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
@@ -3,18 +3,14 @@ var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
7
|
var __export = (target, all) => {
|
9
8
|
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
11
|
-
}
|
12
|
-
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
14
12
|
for (let key of __getOwnPropNames(from))
|
15
|
-
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
14
|
return to;
|
19
15
|
};
|
20
16
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
@@ -22,20 +18,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
22
18
|
// file that has been converted to a CommonJS file using a Babel-
|
23
19
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
20
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
26
22
|
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
29
24
|
var no_unreachable_types_exports = {};
|
30
25
|
__export(no_unreachable_types_exports, {
|
31
26
|
rule: () => rule
|
32
27
|
});
|
33
28
|
module.exports = __toCommonJS(no_unreachable_types_exports);
|
34
|
-
var import_graphql = require("graphql");
|
35
|
-
|
36
|
-
var import_utils = require("../utils.js");
|
37
|
-
const RULE_ID = "no-unreachable-types";
|
38
|
-
const KINDS = [
|
29
|
+
var import_graphql = require("graphql"), import_lodash = __toESM(require("lodash.lowercase")), import_utils = require("../utils.js");
|
30
|
+
const RULE_ID = "no-unreachable-types", KINDS = [
|
39
31
|
import_graphql.Kind.DIRECTIVE_DEFINITION,
|
40
32
|
import_graphql.Kind.OBJECT_TYPE_DEFINITION,
|
41
33
|
import_graphql.Kind.OBJECT_TYPE_EXTENSION,
|
@@ -62,27 +54,21 @@ const RequestDirectiveLocations = /* @__PURE__ */ new Set([
|
|
62
54
|
import_graphql.DirectiveLocation.VARIABLE_DEFINITION
|
63
55
|
]);
|
64
56
|
function getReachableTypes(schema) {
|
65
|
-
if (reachableTypesCache)
|
57
|
+
if (reachableTypesCache)
|
66
58
|
return reachableTypesCache;
|
67
|
-
|
68
|
-
const reachableTypes = /* @__PURE__ */ new Set();
|
69
|
-
const collect = (node) => {
|
59
|
+
const reachableTypes = /* @__PURE__ */ new Set(), collect = (node) => {
|
70
60
|
const typeName = (0, import_utils.getTypeName)(node);
|
71
|
-
if (reachableTypes.has(typeName))
|
61
|
+
if (reachableTypes.has(typeName))
|
72
62
|
return;
|
73
|
-
}
|
74
63
|
reachableTypes.add(typeName);
|
75
64
|
const type = schema.getType(typeName) || schema.getDirective(typeName);
|
76
65
|
if ((0, import_graphql.isInterfaceType)(type)) {
|
77
66
|
const { objects, interfaces } = schema.getImplementations(type);
|
78
|
-
for (const { astNode } of [...objects, ...interfaces])
|
67
|
+
for (const { astNode } of [...objects, ...interfaces])
|
79
68
|
(0, import_graphql.visit)(astNode, visitor);
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
};
|
85
|
-
const visitor = {
|
69
|
+
} else
|
70
|
+
type?.astNode && (0, import_graphql.visit)(type.astNode, visitor);
|
71
|
+
}, visitor = {
|
86
72
|
InterfaceTypeDefinition: collect,
|
87
73
|
ObjectTypeDefinition: collect,
|
88
74
|
InputValueDefinition: collect,
|
@@ -97,24 +83,17 @@ function getReachableTypes(schema) {
|
|
97
83
|
schema.getQueryType(),
|
98
84
|
schema.getMutationType(),
|
99
85
|
schema.getSubscriptionType()
|
100
|
-
])
|
101
|
-
|
102
|
-
|
103
|
-
}
|
104
|
-
}
|
105
|
-
for (const node of schema.getDirectives()) {
|
86
|
+
])
|
87
|
+
type?.astNode && (0, import_graphql.visit)(type.astNode, visitor);
|
88
|
+
for (const node of schema.getDirectives())
|
106
89
|
if (node.locations.some((location) => RequestDirectiveLocations.has(location))) {
|
107
90
|
reachableTypes.add(node.name);
|
108
91
|
for (const arg of node.args) {
|
109
92
|
const argTypeName = "name" in arg.type && arg.type.name;
|
110
|
-
|
111
|
-
reachableTypes.add(argTypeName);
|
112
|
-
}
|
93
|
+
argTypeName && reachableTypes.add(argTypeName);
|
113
94
|
}
|
114
95
|
}
|
115
|
-
|
116
|
-
reachableTypesCache = reachableTypes;
|
117
|
-
return reachableTypesCache;
|
96
|
+
return reachableTypesCache = reachableTypes, reachableTypesCache;
|
118
97
|
}
|
119
98
|
const rule = {
|
120
99
|
meta: {
|
@@ -125,7 +104,7 @@ const rule = {
|
|
125
104
|
description: "Requires all types to be reachable at some level by root level fields.",
|
126
105
|
category: "Schema",
|
127
106
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
128
|
-
requiresSchema:
|
107
|
+
requiresSchema: !0,
|
129
108
|
examples: [
|
130
109
|
{
|
131
110
|
title: "Incorrect",
|
@@ -160,15 +139,14 @@ const rule = {
|
|
160
139
|
)
|
161
140
|
}
|
162
141
|
],
|
163
|
-
recommended:
|
142
|
+
recommended: !0
|
164
143
|
},
|
165
144
|
type: "suggestion",
|
166
145
|
schema: [],
|
167
|
-
hasSuggestions:
|
146
|
+
hasSuggestions: !0
|
168
147
|
},
|
169
148
|
create(context) {
|
170
|
-
const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
171
|
-
const reachableTypes = getReachableTypes(schema);
|
149
|
+
const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context), reachableTypes = getReachableTypes(schema);
|
172
150
|
return {
|
173
151
|
[`:matches(${KINDS}) > .name`](node) {
|
174
152
|
const typeName = node.value;
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.js';
|
3
2
|
import 'eslint';
|
4
3
|
import 'estree';
|
5
4
|
import 'graphql';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.js';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.js';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -5,51 +5,36 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
7
|
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable:
|
9
|
-
}
|
10
|
-
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
12
11
|
for (let key of __getOwnPropNames(from))
|
13
|
-
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
13
|
return to;
|
17
14
|
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value:
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
19
16
|
var no_unused_fields_exports = {};
|
20
17
|
__export(no_unused_fields_exports, {
|
21
18
|
rule: () => rule
|
22
19
|
});
|
23
20
|
module.exports = __toCommonJS(no_unused_fields_exports);
|
24
|
-
var import_graphql = require("graphql");
|
25
|
-
var import_utils = require("../utils.js");
|
21
|
+
var import_graphql = require("graphql"), import_utils = require("../utils.js");
|
26
22
|
const RULE_ID = "no-unused-fields";
|
27
23
|
let usedFieldsCache;
|
28
24
|
function getUsedFields(schema, operations) {
|
29
|
-
if (usedFieldsCache)
|
25
|
+
if (usedFieldsCache)
|
30
26
|
return usedFieldsCache;
|
31
|
-
|
32
|
-
const usedFields = /* @__PURE__ */ Object.create(null);
|
33
|
-
const typeInfo = new import_graphql.TypeInfo(schema);
|
34
|
-
const visitor = (0, import_graphql.visitWithTypeInfo)(typeInfo, {
|
27
|
+
const usedFields = /* @__PURE__ */ Object.create(null), typeInfo = new import_graphql.TypeInfo(schema), visitor = (0, import_graphql.visitWithTypeInfo)(typeInfo, {
|
35
28
|
Field(node) {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
41
|
-
const parentTypeName = typeInfo.getParentType().name;
|
42
|
-
const fieldName = node.name.value;
|
43
|
-
(_a = usedFields[parentTypeName]) != null ? _a : usedFields[parentTypeName] = /* @__PURE__ */ new Set();
|
44
|
-
usedFields[parentTypeName].add(fieldName);
|
29
|
+
if (!typeInfo.getFieldDef())
|
30
|
+
return !1;
|
31
|
+
const parentTypeName = typeInfo.getParentType().name, fieldName = node.name.value;
|
32
|
+
usedFields[parentTypeName] ??= /* @__PURE__ */ new Set(), usedFields[parentTypeName].add(fieldName);
|
45
33
|
}
|
46
|
-
});
|
47
|
-
const
|
48
|
-
for (const { document } of allDocuments) {
|
34
|
+
}), allDocuments = [...operations.getOperations(), ...operations.getFragments()];
|
35
|
+
for (const { document } of allDocuments)
|
49
36
|
(0, import_graphql.visit)(document, visitor);
|
50
|
-
|
51
|
-
usedFieldsCache = usedFields;
|
52
|
-
return usedFieldsCache;
|
37
|
+
return usedFieldsCache = usedFields, usedFieldsCache;
|
53
38
|
}
|
54
39
|
const rule = {
|
55
40
|
meta: {
|
@@ -60,9 +45,10 @@ const rule = {
|
|
60
45
|
description: "Requires all fields to be used at some level by siblings operations.",
|
61
46
|
category: "Schema",
|
62
47
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
63
|
-
requiresSiblings:
|
64
|
-
requiresSchema:
|
65
|
-
|
48
|
+
requiresSiblings: !0,
|
49
|
+
requiresSchema: !0,
|
50
|
+
// Requires documents to be set
|
51
|
+
isDisabledForAllConfig: !0,
|
66
52
|
examples: [
|
67
53
|
{
|
68
54
|
title: "Incorrect",
|
@@ -115,22 +101,14 @@ const rule = {
|
|
115
101
|
},
|
116
102
|
type: "suggestion",
|
117
103
|
schema: [],
|
118
|
-
hasSuggestions:
|
104
|
+
hasSuggestions: !0
|
119
105
|
},
|
120
106
|
create(context) {
|
121
|
-
const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
122
|
-
const siblingsOperations = (0, import_utils.requireSiblingsOperations)(RULE_ID, context);
|
123
|
-
const usedFields = getUsedFields(schema, siblingsOperations);
|
107
|
+
const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context), siblingsOperations = (0, import_utils.requireSiblingsOperations)(RULE_ID, context), usedFields = getUsedFields(schema, siblingsOperations);
|
124
108
|
return {
|
125
109
|
FieldDefinition(node) {
|
126
|
-
|
127
|
-
|
128
|
-
const parentTypeName = node.parent.name.value;
|
129
|
-
const isUsed = (_a = usedFields[parentTypeName]) == null ? void 0 : _a.has(fieldName);
|
130
|
-
if (isUsed) {
|
131
|
-
return;
|
132
|
-
}
|
133
|
-
context.report({
|
110
|
+
const fieldName = node.name.value, parentTypeName = node.parent.name.value;
|
111
|
+
usedFields[parentTypeName]?.has(fieldName) || context.report({
|
134
112
|
node: node.name,
|
135
113
|
messageId: RULE_ID,
|
136
114
|
data: { fieldName },
|
@@ -138,10 +116,7 @@ const rule = {
|
|
138
116
|
{
|
139
117
|
desc: `Remove \`${fieldName}\` field`,
|
140
118
|
fix(fixer) {
|
141
|
-
const sourceCode = context.getSourceCode();
|
142
|
-
const tokenBefore = sourceCode.getTokenBefore(node);
|
143
|
-
const tokenAfter = sourceCode.getTokenAfter(node);
|
144
|
-
const isEmptyType = tokenBefore.type === "{" && tokenAfter.type === "}";
|
119
|
+
const sourceCode = context.getSourceCode(), tokenBefore = sourceCode.getTokenBefore(node), tokenAfter = sourceCode.getTokenAfter(node), isEmptyType = tokenBefore.type === "{" && tokenAfter.type === "}";
|
145
120
|
return fixer.remove(isEmptyType ? node.parent : node);
|
146
121
|
}
|
147
122
|
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.js';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.js';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.js';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly type: "array";
|
@@ -5,43 +5,36 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
7
|
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable:
|
9
|
-
}
|
10
|
-
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
12
11
|
for (let key of __getOwnPropNames(from))
|
13
|
-
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
13
|
return to;
|
17
14
|
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value:
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
19
16
|
var relay_arguments_exports = {};
|
20
17
|
__export(relay_arguments_exports, {
|
21
18
|
rule: () => rule
|
22
19
|
});
|
23
20
|
module.exports = __toCommonJS(relay_arguments_exports);
|
24
|
-
var import_graphql = require("graphql");
|
25
|
-
|
26
|
-
const RULE_ID = "relay-arguments";
|
27
|
-
const MISSING_ARGUMENTS = "MISSING_ARGUMENTS";
|
28
|
-
const schema = {
|
21
|
+
var import_graphql = require("graphql"), import_utils = require("../utils.js");
|
22
|
+
const RULE_ID = "relay-arguments", MISSING_ARGUMENTS = "MISSING_ARGUMENTS", schema = {
|
29
23
|
type: "array",
|
30
24
|
maxItems: 1,
|
31
25
|
items: {
|
32
26
|
type: "object",
|
33
|
-
additionalProperties:
|
27
|
+
additionalProperties: !1,
|
34
28
|
minProperties: 1,
|
35
29
|
properties: {
|
36
30
|
includeBoth: {
|
37
31
|
type: "boolean",
|
38
|
-
default:
|
32
|
+
default: !0,
|
39
33
|
description: "Enforce including both forward and backward pagination arguments"
|
40
34
|
}
|
41
35
|
}
|
42
36
|
}
|
43
|
-
}
|
44
|
-
const rule = {
|
37
|
+
}, rule = {
|
45
38
|
meta: {
|
46
39
|
type: "problem",
|
47
40
|
docs: {
|
@@ -60,7 +53,8 @@ const rule = {
|
|
60
53
|
"",
|
61
54
|
"- `last` takes a non-negative integer",
|
62
55
|
"- `before` takes the Cursor type"
|
63
|
-
].join(
|
56
|
+
].join(`
|
57
|
+
`),
|
64
58
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
65
59
|
examples: [
|
66
60
|
{
|
@@ -86,7 +80,7 @@ const rule = {
|
|
86
80
|
)
|
87
81
|
}
|
88
82
|
],
|
89
|
-
isDisabledForAllConfig:
|
83
|
+
isDisabledForAllConfig: !0
|
90
84
|
},
|
91
85
|
messages: {
|
92
86
|
[MISSING_ARGUMENTS]: "A field that returns a Connection type must include forward pagination arguments (`first` and `after`), backward pagination arguments (`last` and `before`), or both."
|
@@ -94,20 +88,15 @@ const rule = {
|
|
94
88
|
schema
|
95
89
|
},
|
96
90
|
create(context) {
|
97
|
-
const schema2 = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
98
|
-
const { includeBoth = true } = context.options[0] || {};
|
91
|
+
const schema2 = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context), { includeBoth = !0 } = context.options[0] || {};
|
99
92
|
return {
|
100
93
|
"FieldDefinition > .gqlType Name[value=/Connection$/]"(node) {
|
101
|
-
var _a;
|
102
94
|
let fieldNode = node.parent;
|
103
|
-
|
95
|
+
for (; fieldNode.kind !== import_graphql.Kind.FIELD_DEFINITION; )
|
104
96
|
fieldNode = fieldNode.parent;
|
105
|
-
}
|
106
97
|
const args = Object.fromEntries(
|
107
|
-
|
108
|
-
);
|
109
|
-
const hasForwardPagination = !!(args.first && args.after);
|
110
|
-
const hasBackwardPagination = !!(args.last && args.before);
|
98
|
+
fieldNode.arguments?.map((argument) => [argument.name.value, argument]) || []
|
99
|
+
), hasForwardPagination = !!(args.first && args.after), hasBackwardPagination = !!(args.last && args.before);
|
111
100
|
if (!hasForwardPagination && !hasBackwardPagination) {
|
112
101
|
context.report({
|
113
102
|
node: fieldNode.name,
|
@@ -116,14 +105,9 @@ const rule = {
|
|
116
105
|
return;
|
117
106
|
}
|
118
107
|
function checkField(typeName, argumentName) {
|
119
|
-
const argument = args[argumentName];
|
120
|
-
const hasArgument = !!argument;
|
108
|
+
const argument = args[argumentName], hasArgument = !!argument;
|
121
109
|
let type = argument;
|
122
|
-
if (hasArgument && type.gqlType.kind === import_graphql.Kind.NON_NULL_TYPE) {
|
123
|
-
type = type.gqlType;
|
124
|
-
}
|
125
|
-
const isAllowedNonNullType = hasArgument && type.gqlType.kind === import_graphql.Kind.NAMED_TYPE && (type.gqlType.name.value === typeName || typeName === "String" && (0, import_graphql.isScalarType)(schema2.getType(type.gqlType.name.value)));
|
126
|
-
if (!isAllowedNonNullType) {
|
110
|
+
if (hasArgument && type.gqlType.kind === import_graphql.Kind.NON_NULL_TYPE && (type = type.gqlType), !(hasArgument && type.gqlType.kind === import_graphql.Kind.NAMED_TYPE && (type.gqlType.name.value === typeName || typeName === "String" && (0, import_graphql.isScalarType)(schema2.getType(type.gqlType.name.value))))) {
|
127
111
|
const returnType = typeName === "String" ? "String or Scalar" : typeName;
|
128
112
|
context.report({
|
129
113
|
node: (argument || fieldNode).name,
|
@@ -131,14 +115,7 @@ const rule = {
|
|
131
115
|
});
|
132
116
|
}
|
133
117
|
}
|
134
|
-
|
135
|
-
checkField("Int", "first");
|
136
|
-
checkField("String", "after");
|
137
|
-
}
|
138
|
-
if (includeBoth || args.last || args.before) {
|
139
|
-
checkField("Int", "last");
|
140
|
-
checkField("String", "before");
|
141
|
-
}
|
118
|
+
(includeBoth || args.first || args.after) && (checkField("Int", "first"), checkField("String", "after")), (includeBoth || args.last || args.before) && (checkField("Int", "last"), checkField("String", "before"));
|
142
119
|
}
|
143
120
|
};
|
144
121
|
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { Kind } from 'graphql';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.js';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.js';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.js';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const NON_OBJECT_TYPES: Kind[];
|
11
12
|
declare const rule: GraphQLESLintRule;
|
@@ -5,17 +5,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
7
|
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable:
|
9
|
-
}
|
10
|
-
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
12
11
|
for (let key of __getOwnPropNames(from))
|
13
|
-
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
13
|
return to;
|
17
14
|
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value:
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
19
16
|
var relay_connection_types_exports = {};
|
20
17
|
__export(relay_connection_types_exports, {
|
21
18
|
NON_OBJECT_TYPES: () => NON_OBJECT_TYPES,
|
@@ -23,13 +20,7 @@ __export(relay_connection_types_exports, {
|
|
23
20
|
});
|
24
21
|
module.exports = __toCommonJS(relay_connection_types_exports);
|
25
22
|
var import_graphql = require("graphql");
|
26
|
-
const MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE"
|
27
|
-
const MUST_CONTAIN_FIELD_EDGES = "MUST_CONTAIN_FIELD_EDGES";
|
28
|
-
const MUST_CONTAIN_FIELD_PAGE_INFO = "MUST_CONTAIN_FIELD_PAGE_INFO";
|
29
|
-
const MUST_HAVE_CONNECTION_SUFFIX = "MUST_HAVE_CONNECTION_SUFFIX";
|
30
|
-
const EDGES_FIELD_MUST_RETURN_LIST_TYPE = "EDGES_FIELD_MUST_RETURN_LIST_TYPE";
|
31
|
-
const PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE = "PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE";
|
32
|
-
const NON_OBJECT_TYPES = [
|
23
|
+
const MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE", MUST_CONTAIN_FIELD_EDGES = "MUST_CONTAIN_FIELD_EDGES", MUST_CONTAIN_FIELD_PAGE_INFO = "MUST_CONTAIN_FIELD_PAGE_INFO", MUST_HAVE_CONNECTION_SUFFIX = "MUST_HAVE_CONNECTION_SUFFIX", EDGES_FIELD_MUST_RETURN_LIST_TYPE = "EDGES_FIELD_MUST_RETURN_LIST_TYPE", PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE = "PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE", NON_OBJECT_TYPES = [
|
33
24
|
import_graphql.Kind.SCALAR_TYPE_DEFINITION,
|
34
25
|
import_graphql.Kind.UNION_TYPE_DEFINITION,
|
35
26
|
import_graphql.Kind.UNION_TYPE_EXTENSION,
|
@@ -39,17 +30,7 @@ const NON_OBJECT_TYPES = [
|
|
39
30
|
import_graphql.Kind.ENUM_TYPE_EXTENSION,
|
40
31
|
import_graphql.Kind.INTERFACE_TYPE_DEFINITION,
|
41
32
|
import_graphql.Kind.INTERFACE_TYPE_EXTENSION
|
42
|
-
]
|
43
|
-
const notConnectionTypesSelector = `:matches(${NON_OBJECT_TYPES})[name.value=/Connection$/] > .name`;
|
44
|
-
const hasEdgesField = (node) => {
|
45
|
-
var _a;
|
46
|
-
return (_a = node.fields) == null ? void 0 : _a.some((field) => field.name.value === "edges");
|
47
|
-
};
|
48
|
-
const hasPageInfoField = (node) => {
|
49
|
-
var _a;
|
50
|
-
return (_a = node.fields) == null ? void 0 : _a.some((field) => field.name.value === "pageInfo");
|
51
|
-
};
|
52
|
-
const rule = {
|
33
|
+
], notConnectionTypesSelector = `:matches(${NON_OBJECT_TYPES})[name.value=/Connection$/] > .name`, hasEdgesField = (node) => node.fields?.some((field) => field.name.value === "edges"), hasPageInfoField = (node) => node.fields?.some((field) => field.name.value === "pageInfo"), rule = {
|
53
34
|
meta: {
|
54
35
|
type: "problem",
|
55
36
|
docs: {
|
@@ -61,9 +42,10 @@ const rule = {
|
|
61
42
|
"- Connection type must be an Object type",
|
62
43
|
"- Connection type must contain a field `edges` that return a list type that wraps an edge type",
|
63
44
|
"- Connection type must contain a field `pageInfo` that return a non-null `PageInfo` Object type"
|
64
|
-
].join(
|
45
|
+
].join(`
|
46
|
+
`),
|
65
47
|
url: "https://the-guild.dev/graphql/eslint/rules/relay-connection-types",
|
66
|
-
isDisabledForAllConfig:
|
48
|
+
isDisabledForAllConfig: !0,
|
67
49
|
examples: [
|
68
50
|
{
|
69
51
|
title: "Incorrect",
|
@@ -108,29 +90,16 @@ const rule = {
|
|
108
90
|
context.report({ node, messageId: MUST_BE_OBJECT_TYPE });
|
109
91
|
},
|
110
92
|
":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value!=/Connection$/]"(node) {
|
111
|
-
|
112
|
-
context.report({ node: node.name, messageId: MUST_HAVE_CONNECTION_SUFFIX });
|
113
|
-
}
|
93
|
+
hasEdgesField(node) && hasPageInfoField(node) && context.report({ node: node.name, messageId: MUST_HAVE_CONNECTION_SUFFIX });
|
114
94
|
},
|
115
95
|
":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Connection$/]"(node) {
|
116
|
-
|
117
|
-
context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_EDGES });
|
118
|
-
}
|
119
|
-
if (!hasPageInfoField(node)) {
|
120
|
-
context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_PAGE_INFO });
|
121
|
-
}
|
96
|
+
hasEdgesField(node) || context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_EDGES }), hasPageInfoField(node) || context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_PAGE_INFO });
|
122
97
|
},
|
123
98
|
":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Connection$/] > FieldDefinition[name.value=edges] > .gqlType"(node) {
|
124
|
-
|
125
|
-
if (!isListType) {
|
126
|
-
context.report({ node, messageId: EDGES_FIELD_MUST_RETURN_LIST_TYPE });
|
127
|
-
}
|
99
|
+
node.kind === import_graphql.Kind.LIST_TYPE || node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.LIST_TYPE || context.report({ node, messageId: EDGES_FIELD_MUST_RETURN_LIST_TYPE });
|
128
100
|
},
|
129
101
|
":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Connection$/] > FieldDefinition[name.value=pageInfo] > .gqlType"(node) {
|
130
|
-
|
131
|
-
if (!isNonNullPageInfoType) {
|
132
|
-
context.report({ node, messageId: PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE });
|
133
|
-
}
|
102
|
+
node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.NAMED_TYPE && node.gqlType.name.value === "PageInfo" || context.report({ node, messageId: PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE });
|
134
103
|
}
|
135
104
|
};
|
136
105
|
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.js';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.js';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.js';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly type: "array";
|