@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810160036-304c2c0
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
package/package.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "4.0.0-alpha-
|
3
|
+
"version": "4.0.0-alpha-20230810160036-304c2c0",
|
4
4
|
"description": "GraphQL plugin for ESLint",
|
5
5
|
"repository": "https://github.com/B2o5T/graphql-eslint",
|
6
6
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
7
7
|
"license": "MIT",
|
8
8
|
"engines": {
|
9
|
-
"node": ">=
|
9
|
+
"node": ">=18"
|
10
10
|
},
|
11
11
|
"main": "cjs/index.js",
|
12
|
-
"module": "esm/index.js",
|
13
12
|
"exports": {
|
14
13
|
"./package.json": "./package.json",
|
15
14
|
".": {
|
15
|
+
"browser": "./index.browser.mjs",
|
16
16
|
"require": {
|
17
17
|
"types": "./cjs/index.d.ts",
|
18
18
|
"default": "./cjs/index.js"
|
@@ -27,7 +27,6 @@
|
|
27
27
|
}
|
28
28
|
}
|
29
29
|
},
|
30
|
-
"typings": "esm/index.d.mts",
|
31
30
|
"keywords": [
|
32
31
|
"eslint",
|
33
32
|
"eslintplugin",
|
@@ -35,26 +34,22 @@
|
|
35
34
|
"graphql"
|
36
35
|
],
|
37
36
|
"peerDependencies": {
|
38
|
-
"
|
37
|
+
"eslint": ">=8.44.0",
|
38
|
+
"graphql": "^16"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
41
|
"@graphql-tools/code-file-loader": "^7.3.6",
|
42
42
|
"@graphql-tools/graphql-tag-pluck": "^7.3.6",
|
43
43
|
"@graphql-tools/utils": "^9.0.0",
|
44
|
-
"chalk": "^4.1.2",
|
45
44
|
"debug": "^4.3.4",
|
46
45
|
"fast-glob": "^3.2.12",
|
47
|
-
"graphql-config": "^4.
|
46
|
+
"graphql-config": "^4.5.0",
|
48
47
|
"graphql-depth-limit": "^1.1.0",
|
49
|
-
"lodash.lowercase": "^4.3.0"
|
50
|
-
"tslib": "^2.4.1"
|
48
|
+
"lodash.lowercase": "^4.3.0"
|
51
49
|
},
|
52
50
|
"publishConfig": {
|
53
51
|
"directory": "dist",
|
54
52
|
"access": "public"
|
55
53
|
},
|
56
|
-
"sideEffects": false
|
57
|
-
"typescript": {
|
58
|
-
"definition": "cjs/index.d.ts"
|
59
|
-
}
|
54
|
+
"sideEffects": false
|
60
55
|
}
|
@@ -1,241 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
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: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var require_id_when_available_exports = {};
|
20
|
-
__export(require_id_when_available_exports, {
|
21
|
-
rule: () => rule
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(require_id_when_available_exports);
|
24
|
-
var import_utils = require("@graphql-tools/utils");
|
25
|
-
var import_graphql = require("graphql");
|
26
|
-
var import_estree_converter = require("../estree-converter/index.js");
|
27
|
-
var import_utils2 = require("../utils.js");
|
28
|
-
const RULE_ID = "require-id-when-available";
|
29
|
-
const DEFAULT_ID_FIELD_NAME = "id";
|
30
|
-
const schema = {
|
31
|
-
definitions: {
|
32
|
-
asString: {
|
33
|
-
type: "string"
|
34
|
-
},
|
35
|
-
asArray: import_utils2.ARRAY_DEFAULT_OPTIONS
|
36
|
-
},
|
37
|
-
type: "array",
|
38
|
-
maxItems: 1,
|
39
|
-
items: {
|
40
|
-
type: "object",
|
41
|
-
additionalProperties: false,
|
42
|
-
properties: {
|
43
|
-
fieldName: {
|
44
|
-
oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asArray" }],
|
45
|
-
default: DEFAULT_ID_FIELD_NAME
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
};
|
50
|
-
const rule = {
|
51
|
-
meta: {
|
52
|
-
type: "suggestion",
|
53
|
-
hasSuggestions: true,
|
54
|
-
docs: {
|
55
|
-
category: "Operations",
|
56
|
-
description: "Enforce selecting specific fields when they are available on the GraphQL type.",
|
57
|
-
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
58
|
-
requiresSchema: true,
|
59
|
-
requiresSiblings: true,
|
60
|
-
examples: [
|
61
|
-
{
|
62
|
-
title: "Incorrect",
|
63
|
-
code: (
|
64
|
-
/* GraphQL */
|
65
|
-
`
|
66
|
-
# In your schema
|
67
|
-
type User {
|
68
|
-
id: ID!
|
69
|
-
name: String!
|
70
|
-
}
|
71
|
-
|
72
|
-
# Query
|
73
|
-
query {
|
74
|
-
user {
|
75
|
-
name
|
76
|
-
}
|
77
|
-
}
|
78
|
-
`
|
79
|
-
)
|
80
|
-
},
|
81
|
-
{
|
82
|
-
title: "Correct",
|
83
|
-
code: (
|
84
|
-
/* GraphQL */
|
85
|
-
`
|
86
|
-
# In your schema
|
87
|
-
type User {
|
88
|
-
id: ID!
|
89
|
-
name: String!
|
90
|
-
}
|
91
|
-
|
92
|
-
# Query
|
93
|
-
query {
|
94
|
-
user {
|
95
|
-
id
|
96
|
-
name
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
# Selecting \`id\` with an alias is also valid
|
101
|
-
query {
|
102
|
-
user {
|
103
|
-
id: name
|
104
|
-
}
|
105
|
-
}
|
106
|
-
`
|
107
|
-
)
|
108
|
-
}
|
109
|
-
],
|
110
|
-
recommended: true
|
111
|
-
},
|
112
|
-
messages: {
|
113
|
-
[RULE_ID]: "Field{{ pluralSuffix }} {{ fieldName }} must be selected when it's available on a type.\nInclude it in your selection set{{ addition }}."
|
114
|
-
},
|
115
|
-
schema
|
116
|
-
},
|
117
|
-
create(context) {
|
118
|
-
const schema2 = (0, import_utils2.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
119
|
-
const siblings = (0, import_utils2.requireSiblingsOperations)(RULE_ID, context);
|
120
|
-
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
|
121
|
-
const idNames = (0, import_utils.asArray)(fieldName);
|
122
|
-
const selector = "OperationDefinition SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]";
|
123
|
-
const typeInfo = new import_graphql.TypeInfo(schema2);
|
124
|
-
function checkFragments(node) {
|
125
|
-
for (const selection of node.selections) {
|
126
|
-
if (selection.kind !== import_graphql.Kind.FRAGMENT_SPREAD) {
|
127
|
-
continue;
|
128
|
-
}
|
129
|
-
const [foundSpread] = siblings.getFragment(selection.name.value);
|
130
|
-
if (!foundSpread) {
|
131
|
-
continue;
|
132
|
-
}
|
133
|
-
const checkedFragmentSpreads = /* @__PURE__ */ new Set();
|
134
|
-
const visitor = (0, import_graphql.visitWithTypeInfo)(typeInfo, {
|
135
|
-
SelectionSet(node2, key, _parent) {
|
136
|
-
const parent = _parent;
|
137
|
-
if (parent.kind === import_graphql.Kind.FRAGMENT_DEFINITION) {
|
138
|
-
checkedFragmentSpreads.add(parent.name.value);
|
139
|
-
} else if (parent.kind !== import_graphql.Kind.INLINE_FRAGMENT) {
|
140
|
-
checkSelections(
|
141
|
-
node2,
|
142
|
-
typeInfo.getType(),
|
143
|
-
selection.loc.start,
|
144
|
-
parent,
|
145
|
-
checkedFragmentSpreads
|
146
|
-
);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
});
|
150
|
-
(0, import_graphql.visit)(foundSpread.document, visitor);
|
151
|
-
}
|
152
|
-
}
|
153
|
-
function checkSelections(node, type, loc, parent, checkedFragmentSpreads = /* @__PURE__ */ new Set()) {
|
154
|
-
const rawType = (0, import_estree_converter.getBaseType)(type);
|
155
|
-
if (rawType instanceof import_graphql.GraphQLObjectType || rawType instanceof import_graphql.GraphQLInterfaceType) {
|
156
|
-
checkFields(rawType);
|
157
|
-
} else if (rawType instanceof import_graphql.GraphQLUnionType) {
|
158
|
-
for (const selection of node.selections) {
|
159
|
-
if (selection.kind === import_graphql.Kind.INLINE_FRAGMENT) {
|
160
|
-
const types = rawType.getTypes();
|
161
|
-
const t = types.find((t2) => t2.name === selection.typeCondition.name.value);
|
162
|
-
if (t) {
|
163
|
-
checkFields(t);
|
164
|
-
}
|
165
|
-
}
|
166
|
-
}
|
167
|
-
}
|
168
|
-
function checkFields(rawType2) {
|
169
|
-
const fields = rawType2.getFields();
|
170
|
-
const hasIdFieldInType = idNames.some((name) => fields[name]);
|
171
|
-
if (!hasIdFieldInType) {
|
172
|
-
return;
|
173
|
-
}
|
174
|
-
function hasIdField({ selections }) {
|
175
|
-
return selections.some((selection) => {
|
176
|
-
if (selection.kind === import_graphql.Kind.FIELD) {
|
177
|
-
if (selection.alias && idNames.includes(selection.alias.value)) {
|
178
|
-
return true;
|
179
|
-
}
|
180
|
-
return idNames.includes(selection.name.value);
|
181
|
-
}
|
182
|
-
if (selection.kind === import_graphql.Kind.INLINE_FRAGMENT) {
|
183
|
-
return hasIdField(selection.selectionSet);
|
184
|
-
}
|
185
|
-
if (selection.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
|
186
|
-
const [foundSpread] = siblings.getFragment(selection.name.value);
|
187
|
-
if (foundSpread) {
|
188
|
-
const fragmentSpread = foundSpread.document;
|
189
|
-
checkedFragmentSpreads.add(fragmentSpread.name.value);
|
190
|
-
return hasIdField(fragmentSpread.selectionSet);
|
191
|
-
}
|
192
|
-
}
|
193
|
-
return false;
|
194
|
-
});
|
195
|
-
}
|
196
|
-
const hasId = hasIdField(node);
|
197
|
-
checkFragments(node);
|
198
|
-
if (hasId) {
|
199
|
-
return;
|
200
|
-
}
|
201
|
-
const pluralSuffix = idNames.length > 1 ? "s" : "";
|
202
|
-
const fieldName2 = (0, import_utils2.englishJoinWords)(
|
203
|
-
idNames.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
|
204
|
-
);
|
205
|
-
const addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${(0, import_utils2.englishJoinWords)([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`;
|
206
|
-
const problem = {
|
207
|
-
loc,
|
208
|
-
messageId: RULE_ID,
|
209
|
-
data: {
|
210
|
-
pluralSuffix,
|
211
|
-
fieldName: fieldName2,
|
212
|
-
addition
|
213
|
-
}
|
214
|
-
};
|
215
|
-
if ("type" in node) {
|
216
|
-
problem.suggest = idNames.map((idName) => ({
|
217
|
-
desc: `Add \`${idName}\` selection`,
|
218
|
-
fix: (fixer) => {
|
219
|
-
let insertNode = node.selections[0];
|
220
|
-
insertNode = insertNode.kind === import_graphql.Kind.INLINE_FRAGMENT ? insertNode.selectionSet.selections[0] : insertNode;
|
221
|
-
return fixer.insertTextBefore(insertNode, `${idName} `);
|
222
|
-
}
|
223
|
-
}));
|
224
|
-
}
|
225
|
-
context.report(problem);
|
226
|
-
}
|
227
|
-
}
|
228
|
-
return {
|
229
|
-
[selector](node) {
|
230
|
-
const typeInfo2 = node.typeInfo();
|
231
|
-
if (typeInfo2.gqlType) {
|
232
|
-
checkSelections(node, typeInfo2.gqlType, node.loc.start, node.parent);
|
233
|
-
}
|
234
|
-
}
|
235
|
-
};
|
236
|
-
}
|
237
|
-
};
|
238
|
-
// Annotate the CommonJS export names for ESM import in node:
|
239
|
-
0 && (module.exports = {
|
240
|
-
rule
|
241
|
-
});
|
package/cjs/types-8d5f4ae0.d.ts
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
import { GraphQLParseOptions } from '@graphql-tools/utils';
|
2
|
-
import { Linter, Rule, AST } from 'eslint';
|
3
|
-
import * as ESTree from 'estree';
|
4
|
-
import { FragmentDefinitionNode, OperationDefinitionNode, SelectionSetNode, OperationTypeNode, GraphQLSchema, ASTKindToNode } from 'graphql';
|
5
|
-
import { GraphQLProjectConfig, IExtensions, IGraphQLProject } from 'graphql-config';
|
6
|
-
import { JSONSchema } from 'json-schema-to-ts';
|
7
|
-
import { GraphQLESTreeNode } from './estree-converter/types.js';
|
8
|
-
|
9
|
-
type FragmentSource = {
|
10
|
-
filePath: string;
|
11
|
-
document: FragmentDefinitionNode;
|
12
|
-
};
|
13
|
-
type OperationSource = {
|
14
|
-
filePath: string;
|
15
|
-
document: OperationDefinitionNode;
|
16
|
-
};
|
17
|
-
type SiblingOperations = {
|
18
|
-
available: boolean;
|
19
|
-
getFragment(fragmentName: string): FragmentSource[];
|
20
|
-
getFragments(): FragmentSource[];
|
21
|
-
getFragmentByType(typeName: string): FragmentSource[];
|
22
|
-
getFragmentsInUse(baseOperation: FragmentDefinitionNode | OperationDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
|
23
|
-
getOperation(operationName: string): OperationSource[];
|
24
|
-
getOperations(): OperationSource[];
|
25
|
-
getOperationByType(operationType: OperationTypeNode): OperationSource[];
|
26
|
-
};
|
27
|
-
declare function getSiblings(project?: GraphQLProjectConfig, documents?: ParserOptions['documents']): SiblingOperations;
|
28
|
-
|
29
|
-
type Schema = GraphQLSchema | null;
|
30
|
-
type Pointer = string | string[];
|
31
|
-
interface ParserOptions {
|
32
|
-
schema?: Pointer | Record<string, {
|
33
|
-
headers: Record<string, string>;
|
34
|
-
}>;
|
35
|
-
documents?: Pointer;
|
36
|
-
extensions?: IExtensions;
|
37
|
-
include?: Pointer;
|
38
|
-
exclude?: Pointer;
|
39
|
-
projects?: Record<string, IGraphQLProject>;
|
40
|
-
schemaOptions?: Omit<GraphQLParseOptions, 'assumeValidSDL'> & {
|
41
|
-
headers: Record<string, string>;
|
42
|
-
};
|
43
|
-
graphQLParserOptions?: Omit<GraphQLParseOptions, 'noLocation'>;
|
44
|
-
skipGraphQLConfig?: boolean;
|
45
|
-
filePath: string;
|
46
|
-
/** @deprecated Use `documents` instead */
|
47
|
-
operations?: Pointer;
|
48
|
-
}
|
49
|
-
type ParserServices = {
|
50
|
-
schema: Schema;
|
51
|
-
siblingOperations: SiblingOperations;
|
52
|
-
};
|
53
|
-
type GraphQLESLintParseResult = Linter.ESLintParseResult & {
|
54
|
-
services: ParserServices;
|
55
|
-
};
|
56
|
-
type Location = AST.SourceLocation | ESTree.Position;
|
57
|
-
type ReportDescriptorLocation = {
|
58
|
-
loc: Location;
|
59
|
-
} | {
|
60
|
-
node: {
|
61
|
-
loc: Location;
|
62
|
-
};
|
63
|
-
};
|
64
|
-
type ReportDescriptor = ReportDescriptorLocation & Rule.ReportDescriptorMessage & Rule.ReportDescriptorOptions;
|
65
|
-
type GraphQLESLintRuleContext<Options = any[]> = Omit<Rule.RuleContext, 'options' | 'parserServices' | 'report'> & {
|
66
|
-
options: Options;
|
67
|
-
parserServices: ParserServices;
|
68
|
-
report(descriptor: ReportDescriptor): void;
|
69
|
-
};
|
70
|
-
type CategoryType = 'Operations' | 'Schema';
|
71
|
-
type RuleMetaDataDocs = Required<Rule.RuleMetaData>['docs'];
|
72
|
-
type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & {
|
73
|
-
category: CategoryType | CategoryType[];
|
74
|
-
requiresSchema?: true;
|
75
|
-
requiresSiblings?: true;
|
76
|
-
examples?: {
|
77
|
-
title: string;
|
78
|
-
code: string;
|
79
|
-
usage?: T;
|
80
|
-
}[];
|
81
|
-
configOptions?: T | {
|
82
|
-
schema?: T;
|
83
|
-
operations?: T;
|
84
|
-
};
|
85
|
-
graphQLJSRuleName?: string;
|
86
|
-
isDisabledForAllConfig?: true;
|
87
|
-
};
|
88
|
-
type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
|
89
|
-
[K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
|
90
|
-
};
|
91
|
-
type GraphQLESLintRule<Options = [], WithTypeInfo extends boolean = false> = {
|
92
|
-
meta: Omit<Rule.RuleMetaData, 'docs' | 'schema'> & {
|
93
|
-
docs?: RuleDocsInfo<Options>;
|
94
|
-
schema: Readonly<JSONSchema> | [];
|
95
|
-
};
|
96
|
-
create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
|
97
|
-
};
|
98
|
-
type ValueOf<T> = T[keyof T];
|
99
|
-
type Id<T> = {
|
100
|
-
[P in keyof T]: T[P];
|
101
|
-
} & {};
|
102
|
-
type OmitDistributive<T, K extends PropertyKey> = T extends object ? Id<OmitRecursively<T, K>> : T;
|
103
|
-
type OmitRecursively<T extends object, K extends PropertyKey> = Omit<{
|
104
|
-
[P in keyof T]: OmitDistributive<T[P], K>;
|
105
|
-
}, K>;
|
106
|
-
|
107
|
-
export { CategoryType as C, FragmentSource as F, GraphQLESLintParseResult as G, OmitRecursively as O, ParserOptions as P, ReportDescriptor as R, Schema as S, ValueOf as V, Pointer as a, ParserServices as b, GraphQLESLintRuleContext as c, RuleDocsInfo as d, GraphQLESLintRuleListener as e, GraphQLESLintRule as f, SiblingOperations as g, OperationSource as h, getSiblings as i };
|
package/esm/types-ace77d86.d.ts
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
import { GraphQLParseOptions } from '@graphql-tools/utils';
|
2
|
-
import { Linter, Rule, AST } from 'eslint';
|
3
|
-
import * as ESTree from 'estree';
|
4
|
-
import { FragmentDefinitionNode, OperationDefinitionNode, SelectionSetNode, OperationTypeNode, GraphQLSchema, ASTKindToNode } from 'graphql';
|
5
|
-
import { GraphQLProjectConfig, IExtensions, IGraphQLProject } from 'graphql-config';
|
6
|
-
import { JSONSchema } from 'json-schema-to-ts';
|
7
|
-
import { GraphQLESTreeNode } from './estree-converter/types.mjs';
|
8
|
-
|
9
|
-
type FragmentSource = {
|
10
|
-
filePath: string;
|
11
|
-
document: FragmentDefinitionNode;
|
12
|
-
};
|
13
|
-
type OperationSource = {
|
14
|
-
filePath: string;
|
15
|
-
document: OperationDefinitionNode;
|
16
|
-
};
|
17
|
-
type SiblingOperations = {
|
18
|
-
available: boolean;
|
19
|
-
getFragment(fragmentName: string): FragmentSource[];
|
20
|
-
getFragments(): FragmentSource[];
|
21
|
-
getFragmentByType(typeName: string): FragmentSource[];
|
22
|
-
getFragmentsInUse(baseOperation: FragmentDefinitionNode | OperationDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
|
23
|
-
getOperation(operationName: string): OperationSource[];
|
24
|
-
getOperations(): OperationSource[];
|
25
|
-
getOperationByType(operationType: OperationTypeNode): OperationSource[];
|
26
|
-
};
|
27
|
-
declare function getSiblings(project?: GraphQLProjectConfig, documents?: ParserOptions['documents']): SiblingOperations;
|
28
|
-
|
29
|
-
type Schema = GraphQLSchema | null;
|
30
|
-
type Pointer = string | string[];
|
31
|
-
interface ParserOptions {
|
32
|
-
schema?: Pointer | Record<string, {
|
33
|
-
headers: Record<string, string>;
|
34
|
-
}>;
|
35
|
-
documents?: Pointer;
|
36
|
-
extensions?: IExtensions;
|
37
|
-
include?: Pointer;
|
38
|
-
exclude?: Pointer;
|
39
|
-
projects?: Record<string, IGraphQLProject>;
|
40
|
-
schemaOptions?: Omit<GraphQLParseOptions, 'assumeValidSDL'> & {
|
41
|
-
headers: Record<string, string>;
|
42
|
-
};
|
43
|
-
graphQLParserOptions?: Omit<GraphQLParseOptions, 'noLocation'>;
|
44
|
-
skipGraphQLConfig?: boolean;
|
45
|
-
filePath: string;
|
46
|
-
/** @deprecated Use `documents` instead */
|
47
|
-
operations?: Pointer;
|
48
|
-
}
|
49
|
-
type ParserServices = {
|
50
|
-
schema: Schema;
|
51
|
-
siblingOperations: SiblingOperations;
|
52
|
-
};
|
53
|
-
type GraphQLESLintParseResult = Linter.ESLintParseResult & {
|
54
|
-
services: ParserServices;
|
55
|
-
};
|
56
|
-
type Location = AST.SourceLocation | ESTree.Position;
|
57
|
-
type ReportDescriptorLocation = {
|
58
|
-
loc: Location;
|
59
|
-
} | {
|
60
|
-
node: {
|
61
|
-
loc: Location;
|
62
|
-
};
|
63
|
-
};
|
64
|
-
type ReportDescriptor = ReportDescriptorLocation & Rule.ReportDescriptorMessage & Rule.ReportDescriptorOptions;
|
65
|
-
type GraphQLESLintRuleContext<Options = any[]> = Omit<Rule.RuleContext, 'options' | 'parserServices' | 'report'> & {
|
66
|
-
options: Options;
|
67
|
-
parserServices: ParserServices;
|
68
|
-
report(descriptor: ReportDescriptor): void;
|
69
|
-
};
|
70
|
-
type CategoryType = 'Operations' | 'Schema';
|
71
|
-
type RuleMetaDataDocs = Required<Rule.RuleMetaData>['docs'];
|
72
|
-
type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & {
|
73
|
-
category: CategoryType | CategoryType[];
|
74
|
-
requiresSchema?: true;
|
75
|
-
requiresSiblings?: true;
|
76
|
-
examples?: {
|
77
|
-
title: string;
|
78
|
-
code: string;
|
79
|
-
usage?: T;
|
80
|
-
}[];
|
81
|
-
configOptions?: T | {
|
82
|
-
schema?: T;
|
83
|
-
operations?: T;
|
84
|
-
};
|
85
|
-
graphQLJSRuleName?: string;
|
86
|
-
isDisabledForAllConfig?: true;
|
87
|
-
};
|
88
|
-
type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
|
89
|
-
[K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
|
90
|
-
};
|
91
|
-
type GraphQLESLintRule<Options = [], WithTypeInfo extends boolean = false> = {
|
92
|
-
meta: Omit<Rule.RuleMetaData, 'docs' | 'schema'> & {
|
93
|
-
docs?: RuleDocsInfo<Options>;
|
94
|
-
schema: Readonly<JSONSchema> | [];
|
95
|
-
};
|
96
|
-
create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
|
97
|
-
};
|
98
|
-
type ValueOf<T> = T[keyof T];
|
99
|
-
type Id<T> = {
|
100
|
-
[P in keyof T]: T[P];
|
101
|
-
} & {};
|
102
|
-
type OmitDistributive<T, K extends PropertyKey> = T extends object ? Id<OmitRecursively<T, K>> : T;
|
103
|
-
type OmitRecursively<T extends object, K extends PropertyKey> = Omit<{
|
104
|
-
[P in keyof T]: OmitDistributive<T[P], K>;
|
105
|
-
}, K>;
|
106
|
-
|
107
|
-
export { CategoryType as C, FragmentSource as F, GraphQLESLintParseResult as G, OmitRecursively as O, ParserOptions as P, ReportDescriptor as R, Schema as S, ValueOf as V, Pointer as a, ParserServices as b, GraphQLESLintRuleContext as c, RuleDocsInfo as d, GraphQLESLintRuleListener as e, GraphQLESLintRule as f, SiblingOperations as g, OperationSource as h, getSiblings as i };
|
File without changes
|
File without changes
|
File without changes
|