@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
@@ -1,4 +1,4 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchemaFromContext, truthy } from "../utils.js";
|
3
3
|
const schema = {
|
4
4
|
type: "array",
|
@@ -6,7 +6,7 @@ const schema = {
|
|
6
6
|
maxItems: 1,
|
7
7
|
items: {
|
8
8
|
type: "object",
|
9
|
-
additionalProperties:
|
9
|
+
additionalProperties: !1,
|
10
10
|
required: ["disallow"],
|
11
11
|
properties: {
|
12
12
|
disallow: {
|
@@ -17,17 +17,15 @@ const schema = {
|
|
17
17
|
}
|
18
18
|
}
|
19
19
|
}
|
20
|
-
}
|
21
|
-
const rule = {
|
20
|
+
}, rule = {
|
22
21
|
meta: {
|
23
22
|
type: "suggestion",
|
24
|
-
hasSuggestions:
|
23
|
+
hasSuggestions: !0,
|
25
24
|
docs: {
|
26
25
|
category: "Schema",
|
27
26
|
description: "Disallow using root types `mutation` and/or `subscription`.",
|
28
27
|
url: "https://the-guild.dev/graphql/eslint/rules/no-root-type",
|
29
|
-
requiresSchema:
|
30
|
-
isDisabledForAllConfig: true,
|
28
|
+
requiresSchema: !0,
|
31
29
|
examples: [
|
32
30
|
{
|
33
31
|
title: "Incorrect",
|
@@ -53,23 +51,18 @@ const rule = {
|
|
53
51
|
`
|
54
52
|
)
|
55
53
|
}
|
56
|
-
]
|
54
|
+
],
|
55
|
+
configOptions: [{ disallow: ["mutation", "subscription"] }]
|
57
56
|
},
|
58
57
|
schema
|
59
58
|
},
|
60
59
|
create(context) {
|
61
|
-
const schema2 = requireGraphQLSchemaFromContext("no-root-type", context)
|
62
|
-
const disallow = new Set(context.options[0].disallow);
|
63
|
-
const rootTypeNames = [
|
60
|
+
const schema2 = requireGraphQLSchemaFromContext("no-root-type", context), disallow = new Set(context.options[0].disallow), rootTypeNames = [
|
64
61
|
disallow.has("mutation") && schema2.getMutationType(),
|
65
62
|
disallow.has("subscription") && schema2.getSubscriptionType()
|
66
63
|
].filter(truthy).map((type) => type.name).join("|");
|
67
|
-
|
68
|
-
|
69
|
-
}
|
70
|
-
const selector = `:matches(ObjectTypeDefinition, ObjectTypeExtension) > .name[value=/^(${rootTypeNames})$/]`;
|
71
|
-
return {
|
72
|
-
[selector](node) {
|
64
|
+
return rootTypeNames ? {
|
65
|
+
[`:matches(ObjectTypeDefinition, ObjectTypeExtension) > .name[value=/^(${rootTypeNames})$/]`](node) {
|
73
66
|
const typeName = node.value;
|
74
67
|
context.report({
|
75
68
|
node,
|
@@ -82,7 +75,7 @@ const rule = {
|
|
82
75
|
]
|
83
76
|
});
|
84
77
|
}
|
85
|
-
};
|
78
|
+
} : {};
|
86
79
|
}
|
87
80
|
};
|
88
81
|
export {
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
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.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,16 +1,15 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { isScalarType, Kind } from "graphql";
|
3
3
|
import { getNodeName, requireGraphQLSchemaFromContext } from "../utils.js";
|
4
|
-
const RULE_ID = "no-scalar-result-type-on-mutation"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "no-scalar-result-type-on-mutation", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
|
-
hasSuggestions:
|
7
|
+
hasSuggestions: !0,
|
9
8
|
docs: {
|
10
9
|
category: "Schema",
|
11
10
|
description: "Avoid scalar result type on mutation type to make sure to return a valid state.",
|
12
11
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
13
|
-
requiresSchema:
|
12
|
+
requiresSchema: !0,
|
14
13
|
examples: [
|
15
14
|
{
|
16
15
|
title: "Incorrect",
|
@@ -39,24 +38,17 @@ const rule = {
|
|
39
38
|
schema: []
|
40
39
|
},
|
41
40
|
create(context) {
|
42
|
-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
"> FieldDefinition > .gqlType Name"
|
50
|
-
].join(" ");
|
51
|
-
return {
|
52
|
-
[selector](node) {
|
53
|
-
const typeName = node.value;
|
54
|
-
const graphQLType = schema.getType(typeName);
|
41
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID, context), mutationType = schema.getMutationType();
|
42
|
+
return mutationType ? {
|
43
|
+
[[
|
44
|
+
`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}]`,
|
45
|
+
"> FieldDefinition > .gqlType Name"
|
46
|
+
].join(" ")](node) {
|
47
|
+
const typeName = node.value, graphQLType = schema.getType(typeName);
|
55
48
|
if (isScalarType(graphQLType)) {
|
56
49
|
let fieldDef = node.parent;
|
57
|
-
|
50
|
+
for (; fieldDef.kind !== Kind.FIELD_DEFINITION; )
|
58
51
|
fieldDef = fieldDef.parent;
|
59
|
-
}
|
60
52
|
context.report({
|
61
53
|
node,
|
62
54
|
message: `Unexpected scalar result type \`${typeName}\` for ${getNodeName(fieldDef)}`,
|
@@ -69,7 +61,7 @@ const rule = {
|
|
69
61
|
});
|
70
62
|
}
|
71
63
|
}
|
72
|
-
};
|
64
|
+
} : {};
|
73
65
|
}
|
74
66
|
};
|
75
67
|
export {
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
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.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,13 +1,12 @@
|
|
1
|
-
import "../chunk-
|
2
|
-
const NO_TYPENAME_PREFIX = "NO_TYPENAME_PREFIX"
|
3
|
-
const rule = {
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
|
+
const NO_TYPENAME_PREFIX = "NO_TYPENAME_PREFIX", rule = {
|
4
3
|
meta: {
|
5
4
|
type: "suggestion",
|
6
|
-
hasSuggestions:
|
5
|
+
hasSuggestions: !0,
|
7
6
|
docs: {
|
8
7
|
category: "Schema",
|
9
8
|
description: "Enforces users to avoid using the type name in a field name while defining your schema.",
|
10
|
-
recommended:
|
9
|
+
recommended: !0,
|
11
10
|
url: "https://the-guild.dev/graphql/eslint/rules/no-typename-prefix",
|
12
11
|
examples: [
|
13
12
|
{
|
@@ -42,29 +41,26 @@ const rule = {
|
|
42
41
|
create(context) {
|
43
42
|
return {
|
44
43
|
"ObjectTypeDefinition, ObjectTypeExtension, InterfaceTypeDefinition, InterfaceTypeExtension"(node) {
|
45
|
-
const typeName = node.name.value;
|
46
|
-
const lowerTypeName = typeName.toLowerCase();
|
44
|
+
const typeName = node.name.value, lowerTypeName = typeName.toLowerCase();
|
47
45
|
for (const field of node.fields || []) {
|
48
46
|
const fieldName = field.name.value;
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
{
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
});
|
67
|
-
}
|
47
|
+
fieldName.toLowerCase().startsWith(lowerTypeName) && context.report({
|
48
|
+
data: {
|
49
|
+
fieldName,
|
50
|
+
typeName
|
51
|
+
},
|
52
|
+
messageId: NO_TYPENAME_PREFIX,
|
53
|
+
node: field.name,
|
54
|
+
suggest: [
|
55
|
+
{
|
56
|
+
desc: `Remove \`${fieldName.slice(0, typeName.length)}\` prefix`,
|
57
|
+
fix: (fixer) => fixer.replaceText(
|
58
|
+
field.name,
|
59
|
+
fieldName.replace(new RegExp(`^${typeName}`, "i"), "")
|
60
|
+
)
|
61
|
+
}
|
62
|
+
]
|
63
|
+
});
|
68
64
|
}
|
69
65
|
}
|
70
66
|
};
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
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.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import {
|
3
3
|
DirectiveLocation,
|
4
4
|
isInterfaceType,
|
@@ -7,8 +7,7 @@ import {
|
|
7
7
|
} from "graphql";
|
8
8
|
import lowerCase from "lodash.lowercase";
|
9
9
|
import { getTypeName, requireGraphQLSchemaFromContext } from "../utils.js";
|
10
|
-
const RULE_ID = "no-unreachable-types"
|
11
|
-
const KINDS = [
|
10
|
+
const RULE_ID = "no-unreachable-types", KINDS = [
|
12
11
|
Kind.DIRECTIVE_DEFINITION,
|
13
12
|
Kind.OBJECT_TYPE_DEFINITION,
|
14
13
|
Kind.OBJECT_TYPE_EXTENSION,
|
@@ -35,27 +34,21 @@ const RequestDirectiveLocations = /* @__PURE__ */ new Set([
|
|
35
34
|
DirectiveLocation.VARIABLE_DEFINITION
|
36
35
|
]);
|
37
36
|
function getReachableTypes(schema) {
|
38
|
-
if (reachableTypesCache)
|
37
|
+
if (reachableTypesCache)
|
39
38
|
return reachableTypesCache;
|
40
|
-
|
41
|
-
const reachableTypes = /* @__PURE__ */ new Set();
|
42
|
-
const collect = (node) => {
|
39
|
+
const reachableTypes = /* @__PURE__ */ new Set(), collect = (node) => {
|
43
40
|
const typeName = getTypeName(node);
|
44
|
-
if (reachableTypes.has(typeName))
|
41
|
+
if (reachableTypes.has(typeName))
|
45
42
|
return;
|
46
|
-
}
|
47
43
|
reachableTypes.add(typeName);
|
48
44
|
const type = schema.getType(typeName) || schema.getDirective(typeName);
|
49
45
|
if (isInterfaceType(type)) {
|
50
46
|
const { objects, interfaces } = schema.getImplementations(type);
|
51
|
-
for (const { astNode } of [...objects, ...interfaces])
|
47
|
+
for (const { astNode } of [...objects, ...interfaces])
|
52
48
|
visit(astNode, visitor);
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
};
|
58
|
-
const visitor = {
|
49
|
+
} else
|
50
|
+
type?.astNode && visit(type.astNode, visitor);
|
51
|
+
}, visitor = {
|
59
52
|
InterfaceTypeDefinition: collect,
|
60
53
|
ObjectTypeDefinition: collect,
|
61
54
|
InputValueDefinition: collect,
|
@@ -70,24 +63,17 @@ function getReachableTypes(schema) {
|
|
70
63
|
schema.getQueryType(),
|
71
64
|
schema.getMutationType(),
|
72
65
|
schema.getSubscriptionType()
|
73
|
-
])
|
74
|
-
|
75
|
-
|
76
|
-
}
|
77
|
-
}
|
78
|
-
for (const node of schema.getDirectives()) {
|
66
|
+
])
|
67
|
+
type?.astNode && visit(type.astNode, visitor);
|
68
|
+
for (const node of schema.getDirectives())
|
79
69
|
if (node.locations.some((location) => RequestDirectiveLocations.has(location))) {
|
80
70
|
reachableTypes.add(node.name);
|
81
71
|
for (const arg of node.args) {
|
82
72
|
const argTypeName = "name" in arg.type && arg.type.name;
|
83
|
-
|
84
|
-
reachableTypes.add(argTypeName);
|
85
|
-
}
|
73
|
+
argTypeName && reachableTypes.add(argTypeName);
|
86
74
|
}
|
87
75
|
}
|
88
|
-
|
89
|
-
reachableTypesCache = reachableTypes;
|
90
|
-
return reachableTypesCache;
|
76
|
+
return reachableTypesCache = reachableTypes, reachableTypesCache;
|
91
77
|
}
|
92
78
|
const rule = {
|
93
79
|
meta: {
|
@@ -98,7 +84,7 @@ const rule = {
|
|
98
84
|
description: "Requires all types to be reachable at some level by root level fields.",
|
99
85
|
category: "Schema",
|
100
86
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
101
|
-
requiresSchema:
|
87
|
+
requiresSchema: !0,
|
102
88
|
examples: [
|
103
89
|
{
|
104
90
|
title: "Incorrect",
|
@@ -133,15 +119,14 @@ const rule = {
|
|
133
119
|
)
|
134
120
|
}
|
135
121
|
],
|
136
|
-
recommended:
|
122
|
+
recommended: !0
|
137
123
|
},
|
138
124
|
type: "suggestion",
|
139
125
|
schema: [],
|
140
|
-
hasSuggestions:
|
126
|
+
hasSuggestions: !0
|
141
127
|
},
|
142
128
|
create(context) {
|
143
|
-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
|
144
|
-
const reachableTypes = getReachableTypes(schema);
|
129
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID, context), reachableTypes = getReachableTypes(schema);
|
145
130
|
return {
|
146
131
|
[`:matches(${KINDS}) > .name`](node) {
|
147
132
|
const typeName = node.value;
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
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.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,33 +1,22 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { TypeInfo, visit, visitWithTypeInfo } from "graphql";
|
3
3
|
import { requireGraphQLSchemaFromContext, requireSiblingsOperations } from "../utils.js";
|
4
4
|
const RULE_ID = "no-unused-fields";
|
5
5
|
let usedFieldsCache;
|
6
6
|
function getUsedFields(schema, operations) {
|
7
|
-
if (usedFieldsCache)
|
7
|
+
if (usedFieldsCache)
|
8
8
|
return usedFieldsCache;
|
9
|
-
|
10
|
-
const usedFields = /* @__PURE__ */ Object.create(null);
|
11
|
-
const typeInfo = new TypeInfo(schema);
|
12
|
-
const visitor = visitWithTypeInfo(typeInfo, {
|
9
|
+
const usedFields = /* @__PURE__ */ Object.create(null), typeInfo = new TypeInfo(schema), visitor = visitWithTypeInfo(typeInfo, {
|
13
10
|
Field(node) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
const parentTypeName = typeInfo.getParentType().name;
|
20
|
-
const fieldName = node.name.value;
|
21
|
-
(_a = usedFields[parentTypeName]) != null ? _a : usedFields[parentTypeName] = /* @__PURE__ */ new Set();
|
22
|
-
usedFields[parentTypeName].add(fieldName);
|
11
|
+
if (!typeInfo.getFieldDef())
|
12
|
+
return !1;
|
13
|
+
const parentTypeName = typeInfo.getParentType().name, fieldName = node.name.value;
|
14
|
+
usedFields[parentTypeName] ??= /* @__PURE__ */ new Set(), usedFields[parentTypeName].add(fieldName);
|
23
15
|
}
|
24
|
-
});
|
25
|
-
const
|
26
|
-
for (const { document } of allDocuments) {
|
16
|
+
}), allDocuments = [...operations.getOperations(), ...operations.getFragments()];
|
17
|
+
for (const { document } of allDocuments)
|
27
18
|
visit(document, visitor);
|
28
|
-
|
29
|
-
usedFieldsCache = usedFields;
|
30
|
-
return usedFieldsCache;
|
19
|
+
return usedFieldsCache = usedFields, usedFieldsCache;
|
31
20
|
}
|
32
21
|
const rule = {
|
33
22
|
meta: {
|
@@ -38,9 +27,10 @@ const rule = {
|
|
38
27
|
description: "Requires all fields to be used at some level by siblings operations.",
|
39
28
|
category: "Schema",
|
40
29
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
41
|
-
requiresSiblings:
|
42
|
-
requiresSchema:
|
43
|
-
|
30
|
+
requiresSiblings: !0,
|
31
|
+
requiresSchema: !0,
|
32
|
+
// Requires documents to be set
|
33
|
+
isDisabledForAllConfig: !0,
|
44
34
|
examples: [
|
45
35
|
{
|
46
36
|
title: "Incorrect",
|
@@ -93,22 +83,14 @@ const rule = {
|
|
93
83
|
},
|
94
84
|
type: "suggestion",
|
95
85
|
schema: [],
|
96
|
-
hasSuggestions:
|
86
|
+
hasSuggestions: !0
|
97
87
|
},
|
98
88
|
create(context) {
|
99
|
-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
|
100
|
-
const siblingsOperations = requireSiblingsOperations(RULE_ID, context);
|
101
|
-
const usedFields = getUsedFields(schema, siblingsOperations);
|
89
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID, context), siblingsOperations = requireSiblingsOperations(RULE_ID, context), usedFields = getUsedFields(schema, siblingsOperations);
|
102
90
|
return {
|
103
91
|
FieldDefinition(node) {
|
104
|
-
|
105
|
-
|
106
|
-
const parentTypeName = node.parent.name.value;
|
107
|
-
const isUsed = (_a = usedFields[parentTypeName]) == null ? void 0 : _a.has(fieldName);
|
108
|
-
if (isUsed) {
|
109
|
-
return;
|
110
|
-
}
|
111
|
-
context.report({
|
92
|
+
const fieldName = node.name.value, parentTypeName = node.parent.name.value;
|
93
|
+
usedFields[parentTypeName]?.has(fieldName) || context.report({
|
112
94
|
node: node.name,
|
113
95
|
messageId: RULE_ID,
|
114
96
|
data: { fieldName },
|
@@ -116,10 +98,7 @@ const rule = {
|
|
116
98
|
{
|
117
99
|
desc: `Remove \`${fieldName}\` field`,
|
118
100
|
fix(fixer) {
|
119
|
-
const sourceCode = context.getSourceCode();
|
120
|
-
const tokenBefore = sourceCode.getTokenBefore(node);
|
121
|
-
const tokenAfter = sourceCode.getTokenAfter(node);
|
122
|
-
const isEmptyType = tokenBefore.type === "{" && tokenAfter.type === "}";
|
101
|
+
const sourceCode = context.getSourceCode(), tokenBefore = sourceCode.getTokenBefore(node), tokenAfter = sourceCode.getTokenAfter(node), isEmptyType = tokenBefore.type === "{" && tokenAfter.type === "}";
|
123
102
|
return fixer.remove(isEmptyType ? node.parent : node);
|
124
103
|
}
|
125
104
|
}
|
@@ -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.mjs';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly type: "array";
|
@@ -1,25 +1,22 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { isScalarType, Kind } from "graphql";
|
3
3
|
import { requireGraphQLSchemaFromContext } from "../utils.js";
|
4
|
-
const RULE_ID = "relay-arguments"
|
5
|
-
const MISSING_ARGUMENTS = "MISSING_ARGUMENTS";
|
6
|
-
const schema = {
|
4
|
+
const RULE_ID = "relay-arguments", MISSING_ARGUMENTS = "MISSING_ARGUMENTS", schema = {
|
7
5
|
type: "array",
|
8
6
|
maxItems: 1,
|
9
7
|
items: {
|
10
8
|
type: "object",
|
11
|
-
additionalProperties:
|
9
|
+
additionalProperties: !1,
|
12
10
|
minProperties: 1,
|
13
11
|
properties: {
|
14
12
|
includeBoth: {
|
15
13
|
type: "boolean",
|
16
|
-
default:
|
14
|
+
default: !0,
|
17
15
|
description: "Enforce including both forward and backward pagination arguments"
|
18
16
|
}
|
19
17
|
}
|
20
18
|
}
|
21
|
-
}
|
22
|
-
const rule = {
|
19
|
+
}, rule = {
|
23
20
|
meta: {
|
24
21
|
type: "problem",
|
25
22
|
docs: {
|
@@ -38,7 +35,8 @@ const rule = {
|
|
38
35
|
"",
|
39
36
|
"- `last` takes a non-negative integer",
|
40
37
|
"- `before` takes the Cursor type"
|
41
|
-
].join(
|
38
|
+
].join(`
|
39
|
+
`),
|
42
40
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
43
41
|
examples: [
|
44
42
|
{
|
@@ -64,7 +62,7 @@ const rule = {
|
|
64
62
|
)
|
65
63
|
}
|
66
64
|
],
|
67
|
-
isDisabledForAllConfig:
|
65
|
+
isDisabledForAllConfig: !0
|
68
66
|
},
|
69
67
|
messages: {
|
70
68
|
[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."
|
@@ -72,20 +70,15 @@ const rule = {
|
|
72
70
|
schema
|
73
71
|
},
|
74
72
|
create(context) {
|
75
|
-
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
|
76
|
-
const { includeBoth = true } = context.options[0] || {};
|
73
|
+
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context), { includeBoth = !0 } = context.options[0] || {};
|
77
74
|
return {
|
78
75
|
"FieldDefinition > .gqlType Name[value=/Connection$/]"(node) {
|
79
|
-
var _a;
|
80
76
|
let fieldNode = node.parent;
|
81
|
-
|
77
|
+
for (; fieldNode.kind !== Kind.FIELD_DEFINITION; )
|
82
78
|
fieldNode = fieldNode.parent;
|
83
|
-
}
|
84
79
|
const args = Object.fromEntries(
|
85
|
-
|
86
|
-
);
|
87
|
-
const hasForwardPagination = !!(args.first && args.after);
|
88
|
-
const hasBackwardPagination = !!(args.last && args.before);
|
80
|
+
fieldNode.arguments?.map((argument) => [argument.name.value, argument]) || []
|
81
|
+
), hasForwardPagination = !!(args.first && args.after), hasBackwardPagination = !!(args.last && args.before);
|
89
82
|
if (!hasForwardPagination && !hasBackwardPagination) {
|
90
83
|
context.report({
|
91
84
|
node: fieldNode.name,
|
@@ -94,14 +87,9 @@ const rule = {
|
|
94
87
|
return;
|
95
88
|
}
|
96
89
|
function checkField(typeName, argumentName) {
|
97
|
-
const argument = args[argumentName];
|
98
|
-
const hasArgument = !!argument;
|
90
|
+
const argument = args[argumentName], hasArgument = !!argument;
|
99
91
|
let type = argument;
|
100
|
-
if (hasArgument && type.gqlType.kind === Kind.NON_NULL_TYPE) {
|
101
|
-
type = type.gqlType;
|
102
|
-
}
|
103
|
-
const isAllowedNonNullType = hasArgument && type.gqlType.kind === Kind.NAMED_TYPE && (type.gqlType.name.value === typeName || typeName === "String" && isScalarType(schema2.getType(type.gqlType.name.value)));
|
104
|
-
if (!isAllowedNonNullType) {
|
92
|
+
if (hasArgument && type.gqlType.kind === Kind.NON_NULL_TYPE && (type = type.gqlType), !(hasArgument && type.gqlType.kind === Kind.NAMED_TYPE && (type.gqlType.name.value === typeName || typeName === "String" && isScalarType(schema2.getType(type.gqlType.name.value))))) {
|
105
93
|
const returnType = typeName === "String" ? "String or Scalar" : typeName;
|
106
94
|
context.report({
|
107
95
|
node: (argument || fieldNode).name,
|
@@ -109,14 +97,7 @@ const rule = {
|
|
109
97
|
});
|
110
98
|
}
|
111
99
|
}
|
112
|
-
|
113
|
-
checkField("Int", "first");
|
114
|
-
checkField("String", "after");
|
115
|
-
}
|
116
|
-
if (includeBoth || args.last || args.before) {
|
117
|
-
checkField("Int", "last");
|
118
|
-
checkField("String", "before");
|
119
|
-
}
|
100
|
+
(includeBoth || args.first || args.after) && (checkField("Int", "first"), checkField("String", "after")), (includeBoth || args.last || args.before) && (checkField("Int", "last"), checkField("String", "before"));
|
120
101
|
}
|
121
102
|
};
|
122
103
|
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { Kind } from 'graphql';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const NON_OBJECT_TYPES: Kind[];
|
11
12
|
declare const rule: GraphQLESLintRule;
|