@graphql-eslint/eslint-plugin 4.0.0-alpha.9 → 4.0.1-alpha-20241127205058-a4fec1a6cf7006ea913f13e6afbf7ed2d82503c3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/cache.js +1 -2
- package/cjs/configs/index.d.cts +427 -10
- package/cjs/configs/index.js +1 -2
- package/cjs/configs/operations-all.d.cts +8 -8
- package/cjs/configs/operations-all.js +30 -33
- package/cjs/configs/operations-recommended.d.cts +35 -35
- package/cjs/configs/operations-recommended.js +56 -59
- package/cjs/configs/schema-all.d.cts +12 -12
- package/cjs/configs/schema-all.js +26 -29
- package/cjs/configs/schema-recommended.d.cts +23 -23
- package/cjs/configs/schema-recommended.js +70 -73
- package/cjs/configs/schema-relay.d.cts +5 -5
- package/cjs/configs/schema-relay.js +14 -17
- package/cjs/documents.js +1 -2
- package/cjs/estree-converter/converter.js +1 -2
- package/cjs/estree-converter/utils.js +1 -2
- package/cjs/graphql-config.d.cts +6 -1
- package/cjs/graphql-config.js +9 -3
- package/cjs/index.d.cts +436 -16
- package/cjs/index.js +2 -3
- package/cjs/meta.js +1 -2
- package/cjs/parser.js +2 -6
- package/cjs/processor.js +5 -2
- package/cjs/rules/alphabetize/index.js +1 -2
- package/cjs/rules/description-style/index.js +1 -2
- package/cjs/rules/graphql-js-validation.js +4 -5
- package/cjs/rules/index.d.cts +6 -4
- package/cjs/rules/index.js +1 -2
- package/cjs/rules/input-name/index.js +1 -2
- package/cjs/rules/lone-executable-definition/index.js +1 -2
- package/cjs/rules/match-document-filename/index.js +1 -2
- package/cjs/rules/naming-convention/index.js +4 -3
- package/cjs/rules/no-anonymous-operations/index.js +1 -2
- package/cjs/rules/no-deprecated/index.js +20 -8
- package/cjs/rules/no-duplicate-fields/index.js +1 -2
- package/cjs/rules/no-hashtag-description/index.js +1 -2
- package/cjs/rules/no-one-place-fragments/index.js +2 -3
- package/cjs/rules/no-root-type/index.js +2 -3
- package/cjs/rules/no-scalar-result-type-on-mutation/index.js +2 -3
- package/cjs/rules/no-typename-prefix/index.js +1 -2
- package/cjs/rules/no-unreachable-types/index.js +4 -6
- package/cjs/rules/no-unused-fields/index.d.cts +24 -3
- package/cjs/rules/no-unused-fields/index.js +119 -10
- package/cjs/rules/relay-arguments/index.js +2 -3
- package/cjs/rules/relay-connection-types/index.js +1 -2
- package/cjs/rules/relay-edge-types/index.js +2 -3
- package/cjs/rules/relay-page-info/index.js +2 -3
- package/cjs/rules/require-deprecation-date/index.js +1 -2
- package/cjs/rules/require-deprecation-reason/index.js +1 -2
- package/cjs/rules/require-description/index.js +4 -8
- package/cjs/rules/require-field-of-type-query-in-mutation-result/index.js +2 -3
- package/cjs/rules/require-import-fragment/index.js +2 -3
- package/cjs/rules/require-nullable-fields-with-oneof/index.js +1 -2
- package/cjs/rules/require-nullable-result-in-root/index.js +2 -3
- package/cjs/rules/require-selections/index.js +14 -8
- package/cjs/rules/require-type-pattern-with-oneof/index.js +1 -2
- package/cjs/rules/selection-set-depth/index.js +4 -5
- package/cjs/rules/strict-id-in-types/index.js +2 -3
- package/cjs/rules/unique-enum-value-names/index.js +1 -2
- package/cjs/rules/unique-fragment-name/index.js +2 -3
- package/cjs/rules/unique-operation-name/index.js +1 -2
- package/cjs/schema.js +1 -2
- package/cjs/siblings.js +1 -2
- package/cjs/types.d.cts +1 -0
- package/cjs/utils.d.cts +4 -4
- package/cjs/utils.js +7 -8
- package/esm/cache.js +0 -1
- package/esm/configs/index.d.ts +427 -10
- package/esm/configs/index.js +0 -1
- package/esm/configs/operations-all.d.ts +7 -7
- package/esm/configs/operations-all.js +28 -33
- package/esm/configs/operations-recommended.d.ts +34 -34
- package/esm/configs/operations-recommended.js +54 -59
- package/esm/configs/schema-all.d.ts +11 -11
- package/esm/configs/schema-all.js +24 -29
- package/esm/configs/schema-recommended.d.ts +22 -22
- package/esm/configs/schema-recommended.js +68 -73
- package/esm/configs/schema-relay.d.ts +4 -4
- package/esm/configs/schema-relay.js +12 -17
- package/esm/documents.js +0 -1
- package/esm/estree-converter/converter.js +0 -1
- package/esm/estree-converter/utils.js +0 -1
- package/esm/graphql-config.d.ts +6 -1
- package/esm/graphql-config.js +8 -2
- package/esm/index.d.ts +436 -16
- package/esm/index.js +3 -4
- package/esm/meta.js +1 -2
- package/esm/parser.js +3 -7
- package/esm/processor.js +4 -1
- package/esm/rules/alphabetize/index.js +0 -1
- package/esm/rules/description-style/index.js +0 -1
- package/esm/rules/graphql-js-validation.js +5 -6
- package/esm/rules/index.d.ts +6 -4
- package/esm/rules/index.js +0 -1
- package/esm/rules/input-name/index.js +0 -1
- package/esm/rules/lone-executable-definition/index.js +0 -1
- package/esm/rules/match-document-filename/index.js +0 -1
- package/esm/rules/naming-convention/index.js +3 -2
- package/esm/rules/no-anonymous-operations/index.js +0 -1
- package/esm/rules/no-deprecated/index.js +20 -8
- package/esm/rules/no-duplicate-fields/index.js +0 -1
- package/esm/rules/no-hashtag-description/index.js +0 -1
- package/esm/rules/no-one-place-fragments/index.js +2 -3
- package/esm/rules/no-root-type/index.js +2 -3
- package/esm/rules/no-scalar-result-type-on-mutation/index.js +2 -3
- package/esm/rules/no-typename-prefix/index.js +0 -1
- package/esm/rules/no-unreachable-types/index.js +5 -7
- package/esm/rules/no-unused-fields/index.d.ts +24 -3
- package/esm/rules/no-unused-fields/index.js +119 -10
- package/esm/rules/relay-arguments/index.js +2 -3
- package/esm/rules/relay-connection-types/index.js +0 -1
- package/esm/rules/relay-edge-types/index.js +2 -3
- package/esm/rules/relay-page-info/index.js +2 -3
- package/esm/rules/require-deprecation-date/index.js +0 -1
- package/esm/rules/require-deprecation-reason/index.js +0 -1
- package/esm/rules/require-description/index.js +4 -8
- package/esm/rules/require-field-of-type-query-in-mutation-result/index.js +2 -3
- package/esm/rules/require-import-fragment/index.js +2 -3
- package/esm/rules/require-nullable-fields-with-oneof/index.js +0 -1
- package/esm/rules/require-nullable-result-in-root/index.js +2 -3
- package/esm/rules/require-selections/index.js +15 -9
- package/esm/rules/require-type-pattern-with-oneof/index.js +0 -1
- package/esm/rules/selection-set-depth/index.js +4 -5
- package/esm/rules/strict-id-in-types/index.js +2 -3
- package/esm/rules/unique-enum-value-names/index.js +0 -1
- package/esm/rules/unique-fragment-name/index.js +2 -3
- package/esm/rules/unique-operation-name/index.js +0 -1
- package/esm/schema.js +0 -1
- package/esm/siblings.js +0 -1
- package/esm/types.d.ts +1 -0
- package/esm/utils.d.ts +4 -4
- package/esm/utils.js +7 -8
- package/index.browser.js +508 -423
- package/package.json +2 -2
- package/cjs/chunk-UIAXBAMD.js +0 -8
- package/esm/chunk-UIAXBAMD.js +0 -8
@@ -1,4 +1,3 @@
|
|
1
|
-
import "../../chunk-UIAXBAMD.js";
|
2
1
|
import {
|
3
2
|
GraphQLInterfaceType,
|
4
3
|
GraphQLObjectType,
|
@@ -13,8 +12,8 @@ import { getBaseType } from "../../estree-converter/index.js";
|
|
13
12
|
import {
|
14
13
|
ARRAY_DEFAULT_OPTIONS,
|
15
14
|
englishJoinWords,
|
16
|
-
|
17
|
-
|
15
|
+
requireGraphQLOperations,
|
16
|
+
requireGraphQLSchema
|
18
17
|
} from "../../utils.js";
|
19
18
|
const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
20
19
|
definitions: {
|
@@ -95,7 +94,8 @@ const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
|
95
94
|
)
|
96
95
|
}
|
97
96
|
],
|
98
|
-
recommended: !0
|
97
|
+
recommended: !0,
|
98
|
+
whenNotToUseIt: "Relay Compiler automatically adds an `id` field to any type that has an `id` field, even if it hasn't been explicitly requested. Requesting a field that is not used directly in the code can conflict with another Relay rule: `relay/unused-fields`."
|
99
99
|
},
|
100
100
|
messages: {
|
101
101
|
[RULE_ID]: `Field{{ pluralSuffix }} {{ fieldName }} must be selected when it's available on a type.
|
@@ -104,7 +104,7 @@ Include it in your selection set{{ addition }}.`
|
|
104
104
|
schema
|
105
105
|
},
|
106
106
|
create(context) {
|
107
|
-
const schema2 =
|
107
|
+
const schema2 = requireGraphQLSchema(RULE_ID, context), siblings = requireGraphQLOperations(RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = asArray(fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo(schema2);
|
108
108
|
function checkFragments(node) {
|
109
109
|
for (const selection of node.selections) {
|
110
110
|
if (selection.kind !== Kind.FRAGMENT_SPREAD)
|
@@ -131,13 +131,19 @@ Include it in your selection set{{ addition }}.`
|
|
131
131
|
const rawType = getBaseType(type);
|
132
132
|
if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType)
|
133
133
|
checkFields(rawType);
|
134
|
-
else if (rawType instanceof GraphQLUnionType)
|
135
|
-
for (const selection of node.selections)
|
134
|
+
else if (rawType instanceof GraphQLUnionType)
|
135
|
+
for (const selection of node.selections) {
|
136
|
+
const types = rawType.getTypes();
|
136
137
|
if (selection.kind === Kind.INLINE_FRAGMENT) {
|
137
|
-
const t =
|
138
|
+
const t = types.find((t2) => t2.name === selection.typeCondition.name.value);
|
138
139
|
t && checkFields(t);
|
140
|
+
} else if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
141
|
+
const [foundSpread] = siblings.getFragment(selection.name.value);
|
142
|
+
if (!foundSpread) return;
|
143
|
+
const fragmentSpread = foundSpread.document, t = fragmentSpread.typeCondition.name.value === rawType.name ? rawType : types.find((t2) => t2.name === fragmentSpread.typeCondition.name.value);
|
144
|
+
checkedFragmentSpreads.add(fragmentSpread.name.value), checkSelections(fragmentSpread.selectionSet, t, loc, parent, checkedFragmentSpreads);
|
139
145
|
}
|
140
|
-
|
146
|
+
}
|
141
147
|
function checkFields(rawType2) {
|
142
148
|
const fields = rawType2.getFields();
|
143
149
|
if (!idNames.some((name) => fields[name]))
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import "../../chunk-UIAXBAMD.js";
|
2
1
|
import { Kind } from "graphql";
|
3
2
|
import depthLimit from "graphql-depth-limit";
|
4
|
-
import { ARRAY_DEFAULT_OPTIONS, logger,
|
3
|
+
import { ARRAY_DEFAULT_OPTIONS, logger, requireGraphQLOperations } from "../../utils.js";
|
5
4
|
const RULE_ID = "selection-set-depth", schema = {
|
6
5
|
type: "array",
|
7
6
|
minItems: 1,
|
@@ -75,10 +74,10 @@ const RULE_ID = "selection-set-depth", schema = {
|
|
75
74
|
create(context) {
|
76
75
|
let siblings = null;
|
77
76
|
try {
|
78
|
-
siblings =
|
77
|
+
siblings = requireGraphQLOperations(RULE_ID, context);
|
79
78
|
} catch {
|
80
79
|
logger.warn(
|
81
|
-
`Rule "${RULE_ID}" works best with siblings operations loaded.
|
80
|
+
`Rule "${RULE_ID}" works best with siblings operations loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`
|
82
81
|
);
|
83
82
|
}
|
84
83
|
const { maxDepth, ignore = [] } = context.options[0], checkFn = depthLimit(maxDepth, { ignore });
|
@@ -120,7 +119,7 @@ const RULE_ID = "selection-set-depth", schema = {
|
|
120
119
|
});
|
121
120
|
} catch (e) {
|
122
121
|
logger.warn(
|
123
|
-
`Rule "${RULE_ID}" check failed due to a missing siblings operations.
|
122
|
+
`Rule "${RULE_ID}" check failed due to a missing siblings operations. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`,
|
124
123
|
e
|
125
124
|
);
|
126
125
|
}
|
@@ -1,10 +1,9 @@
|
|
1
|
-
import "../../chunk-UIAXBAMD.js";
|
2
1
|
import { Kind } from "graphql";
|
3
2
|
import {
|
4
3
|
ARRAY_DEFAULT_OPTIONS,
|
5
4
|
displayNodeName,
|
6
5
|
englishJoinWords,
|
7
|
-
|
6
|
+
requireGraphQLSchema,
|
8
7
|
truthy
|
9
8
|
} from "../../utils.js";
|
10
9
|
const RULE_ID = "strict-id-in-types", schema = {
|
@@ -123,7 +122,7 @@ const RULE_ID = "strict-id-in-types", schema = {
|
|
123
122
|
acceptedIdTypes: ["ID"],
|
124
123
|
exceptions: {},
|
125
124
|
...context.options[0]
|
126
|
-
}, schema2 =
|
125
|
+
}, schema2 = requireGraphQLSchema(RULE_ID, context);
|
127
126
|
return {
|
128
127
|
[`ObjectTypeDefinition[name.value!=/^(${[
|
129
128
|
schema2.getQueryType(),
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import "../../chunk-UIAXBAMD.js";
|
2
1
|
import { relative } from "node:path";
|
3
2
|
import { Kind } from "graphql";
|
4
|
-
import { CWD,
|
3
|
+
import { CWD, requireGraphQLOperations, slash, VIRTUAL_DOCUMENT_REGEX } from "../../utils.js";
|
5
4
|
const RULE_ID = "unique-fragment-name", checkNode = (context, node, ruleId) => {
|
6
|
-
const documentName = node.name.value, siblings =
|
5
|
+
const documentName = node.name.value, siblings = requireGraphQLOperations(ruleId, context), siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName), filepath = context.filename, conflictingDocuments = siblingDocuments.filter((f) => {
|
7
6
|
const isSameName = f.document.name?.value === documentName, isSamePath = slash(f.filePath) === slash(filepath);
|
8
7
|
return isSameName && !isSamePath;
|
9
8
|
});
|
package/esm/schema.js
CHANGED
package/esm/siblings.js
CHANGED
package/esm/types.d.ts
CHANGED
@@ -52,6 +52,7 @@ type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & {
|
|
52
52
|
};
|
53
53
|
graphQLJSRuleName?: string;
|
54
54
|
isDisabledForAllConfig?: true;
|
55
|
+
whenNotToUseIt?: string;
|
55
56
|
};
|
56
57
|
type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
|
57
58
|
[K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
|
package/esm/utils.d.ts
CHANGED
@@ -8,8 +8,8 @@ import '@graphql-tools/utils';
|
|
8
8
|
import 'graphql-config';
|
9
9
|
import 'json-schema-to-ts';
|
10
10
|
|
11
|
-
declare function
|
12
|
-
declare function
|
11
|
+
declare function requireGraphQLOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
|
12
|
+
declare function requireGraphQLSchema(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
|
13
13
|
declare const logger: {
|
14
14
|
error: (...args: unknown[]) => void;
|
15
15
|
warn: (...args: unknown[]) => void;
|
@@ -39,7 +39,7 @@ declare const ARRAY_DEFAULT_OPTIONS: {
|
|
39
39
|
declare const englishJoinWords: (words: string[]) => string;
|
40
40
|
type Truthy<T> = T extends '' | 0 | false | null | undefined ? never : T;
|
41
41
|
declare function truthy<T>(value: T): value is Truthy<T>;
|
42
|
-
declare function displayNodeName(node: GraphQLESTreeNode<ASTNode>): string;
|
42
|
+
declare function displayNodeName(node: GraphQLESTreeNode<ASTNode, boolean>): string;
|
43
43
|
declare function getNodeName(node: GraphQLESTreeNode<ASTNode>): string;
|
44
44
|
|
45
|
-
export { ARRAY_DEFAULT_OPTIONS, CWD, type CaseStyle, REPORT_ON_FIRST_CHARACTER, TYPES_KINDS, VIRTUAL_DOCUMENT_REGEX, camelCase, convertCase, displayNodeName, englishJoinWords, getLocation, getNodeName, getTypeName, logger, pascalCase,
|
45
|
+
export { ARRAY_DEFAULT_OPTIONS, CWD, type CaseStyle, REPORT_ON_FIRST_CHARACTER, TYPES_KINDS, VIRTUAL_DOCUMENT_REGEX, camelCase, convertCase, displayNodeName, englishJoinWords, getLocation, getNodeName, getTypeName, logger, pascalCase, requireGraphQLOperations, requireGraphQLSchema, slash, truthy };
|
package/esm/utils.js
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
import "./chunk-UIAXBAMD.js";
|
2
1
|
import { Kind } from "graphql";
|
3
2
|
import lowerCase from "lodash.lowercase";
|
4
|
-
function
|
3
|
+
function requireGraphQLOperations(ruleId, context) {
|
5
4
|
const { siblingOperations } = context.sourceCode.parserServices;
|
6
5
|
if (!siblingOperations.available)
|
7
6
|
throw new Error(
|
8
|
-
`Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/
|
7
|
+
`Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`
|
9
8
|
);
|
10
9
|
return siblingOperations;
|
11
10
|
}
|
12
|
-
function
|
11
|
+
function requireGraphQLSchema(ruleId, context) {
|
13
12
|
const { schema } = context.sourceCode.parserServices;
|
14
13
|
if (!schema)
|
15
14
|
throw new Error(
|
16
|
-
`Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/
|
15
|
+
`Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-schema for more info`
|
17
16
|
);
|
18
17
|
return schema;
|
19
18
|
}
|
@@ -123,7 +122,7 @@ const DisplayNodeNameMap = {
|
|
123
122
|
[Kind.VARIABLE]: "variable"
|
124
123
|
};
|
125
124
|
function displayNodeName(node) {
|
126
|
-
return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value}"`;
|
125
|
+
return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value || node.value}"`;
|
127
126
|
}
|
128
127
|
function getNodeName(node) {
|
129
128
|
switch (node.kind) {
|
@@ -160,8 +159,8 @@ export {
|
|
160
159
|
getTypeName,
|
161
160
|
logger,
|
162
161
|
pascalCase,
|
163
|
-
|
164
|
-
|
162
|
+
requireGraphQLOperations,
|
163
|
+
requireGraphQLSchema,
|
165
164
|
slash,
|
166
165
|
truthy
|
167
166
|
};
|