@graphql-eslint/eslint-plugin 4.0.0-alpha.0 → 4.0.0-alpha.10
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/README.md +1 -1
- package/{esm/cache.d.mts → cjs/cache.d.cts} +1 -1
- package/cjs/cache.js +8 -36
- package/cjs/chunk-UIAXBAMD.js +8 -0
- package/cjs/configs/index.d.cts +24 -0
- package/cjs/configs/index.js +35 -38
- package/cjs/configs/operations-all.js +33 -26
- package/cjs/configs/operations-recommended.js +59 -52
- package/cjs/configs/schema-all.js +29 -22
- package/cjs/configs/schema-recommended.js +73 -66
- package/cjs/configs/schema-relay.js +17 -10
- package/cjs/documents.js +18 -38
- package/{esm/estree-converter/converter.d.mts → cjs/estree-converter/converter.d.cts} +1 -1
- package/cjs/estree-converter/converter.js +16 -30
- package/cjs/estree-converter/index.d.cts +8 -0
- package/cjs/estree-converter/index.js +3 -23
- package/{esm/estree-converter/types.d.mts → cjs/estree-converter/types.d.cts} +1 -1
- package/cjs/estree-converter/types.js +1 -14
- package/{esm/estree-converter/utils.d.mts → cjs/estree-converter/utils.d.cts} +3 -3
- package/cjs/estree-converter/utils.js +22 -40
- package/{esm/graphql-config.d.mts → cjs/graphql-config.d.cts} +3 -3
- package/cjs/graphql-config.js +16 -42
- package/cjs/index.d.cts +184 -0
- package/cjs/index.js +24 -41
- package/cjs/meta.d.cts +3 -0
- package/cjs/meta.js +5 -0
- package/cjs/package.json +1 -0
- package/{esm/parser.d.mts → cjs/parser.d.cts} +12 -5
- package/cjs/parser.js +35 -46
- package/{esm/processor.d.mts → cjs/processor.d.cts} +5 -1
- package/cjs/processor.js +25 -34
- package/cjs/rules/{alphabetize.d.ts → alphabetize/index.d.cts} +6 -6
- package/cjs/rules/{alphabetize.js → alphabetize/index.js} +69 -77
- package/{esm/rules/description-style.d.mts → cjs/rules/description-style/index.d.cts} +5 -5
- package/cjs/rules/{description-style.js → description-style/index.js} +7 -27
- package/{esm/rules/graphql-js-validation.d.mts → cjs/rules/graphql-js-validation.d.cts} +4 -4
- package/cjs/rules/graphql-js-validation.js +93 -70
- package/{esm/rules/index.d.mts → cjs/rules/index.d.cts} +11 -12
- package/cjs/rules/index.js +74 -60
- package/cjs/rules/{input-name.d.ts → input-name/index.d.cts} +8 -6
- package/cjs/rules/{input-name.js → input-name/index.js} +10 -28
- package/cjs/rules/{lone-executable-definition.d.ts → lone-executable-definition/index.d.cts} +5 -5
- package/cjs/rules/{lone-executable-definition.js → lone-executable-definition/index.js} +13 -32
- package/cjs/rules/{match-document-filename.d.ts → match-document-filename/index.d.cts} +6 -6
- package/cjs/rules/{match-document-filename.js → match-document-filename/index.js} +21 -35
- package/{esm/rules/naming-convention.d.mts → cjs/rules/naming-convention/index.d.cts} +8 -6
- package/cjs/rules/{naming-convention.js → naming-convention/index.js} +41 -54
- package/cjs/rules/no-anonymous-operations/index.d.cts +13 -0
- package/cjs/rules/{no-anonymous-operations.js → no-anonymous-operations/index.js} +9 -28
- package/{esm/rules/no-deprecated.d.mts → cjs/rules/no-deprecated/index.d.cts} +4 -4
- package/cjs/rules/{no-deprecated.js → no-deprecated/index.js} +11 -30
- package/cjs/rules/no-duplicate-fields/index.d.cts +13 -0
- package/cjs/rules/{no-duplicate-fields.js → no-duplicate-fields/index.js} +8 -28
- package/cjs/rules/{no-hashtag-description.d.ts → no-hashtag-description/index.d.cts} +4 -4
- package/cjs/rules/{no-hashtag-description.js → no-hashtag-description/index.js} +11 -31
- package/cjs/rules/no-one-place-fragments/index.d.cts +13 -0
- package/cjs/rules/{no-one-place-fragments.js → no-one-place-fragments/index.js} +11 -29
- package/cjs/rules/{no-root-type.d.ts → no-root-type/index.d.cts} +5 -5
- package/cjs/rules/{no-root-type.js → no-root-type/index.js} +9 -29
- package/cjs/rules/no-scalar-result-type-on-mutation/index.d.cts +13 -0
- package/cjs/rules/no-scalar-result-type-on-mutation/index.js +69 -0
- package/cjs/rules/no-typename-prefix/index.d.cts +13 -0
- package/cjs/rules/{no-typename-prefix.js → no-typename-prefix/index.js} +5 -25
- package/cjs/rules/no-unreachable-types/index.d.cts +13 -0
- package/cjs/rules/no-unreachable-types/index.js +155 -0
- package/cjs/rules/no-unused-fields/index.d.cts +13 -0
- package/cjs/rules/{no-unused-fields.js → no-unused-fields/index.js} +16 -34
- package/{esm/rules/relay-arguments.d.mts → cjs/rules/relay-arguments/index.d.cts} +5 -5
- package/cjs/rules/{relay-arguments.js → relay-arguments/index.js} +11 -30
- package/{esm/rules/relay-connection-types.d.mts → cjs/rules/relay-connection-types/index.d.cts} +4 -4
- package/cjs/rules/{relay-connection-types.js → relay-connection-types/index.js} +19 -40
- package/cjs/rules/{relay-edge-types.d.ts → relay-edge-types/index.d.cts} +8 -6
- package/cjs/rules/{relay-edge-types.js → relay-edge-types/index.js} +31 -44
- package/cjs/rules/relay-page-info/index.d.cts +13 -0
- package/cjs/rules/{relay-page-info.js → relay-page-info/index.js} +13 -31
- package/{esm/rules/require-deprecation-date.d.mts → cjs/rules/require-deprecation-date/index.d.cts} +5 -5
- package/cjs/rules/{require-deprecation-date.js → require-deprecation-date/index.js} +13 -32
- package/cjs/rules/require-deprecation-reason/index.d.cts +13 -0
- package/cjs/rules/require-deprecation-reason/index.js +66 -0
- package/{esm/rules/require-description.d.mts → cjs/rules/require-description/index.d.cts} +5 -5
- package/cjs/rules/{require-description.js → require-description/index.js} +30 -44
- package/cjs/rules/require-field-of-type-query-in-mutation-result/index.d.cts +13 -0
- package/cjs/rules/{require-field-of-type-query-in-mutation-result.js → require-field-of-type-query-in-mutation-result/index.js} +10 -29
- package/cjs/rules/require-import-fragment/index.d.cts +13 -0
- package/cjs/rules/{require-import-fragment.js → require-import-fragment/index.js} +20 -46
- package/cjs/rules/require-nullable-fields-with-oneof/index.d.cts +13 -0
- package/cjs/rules/require-nullable-fields-with-oneof/index.js +62 -0
- package/cjs/rules/require-nullable-result-in-root/index.d.cts +13 -0
- package/cjs/rules/{require-nullable-result-in-root.js → require-nullable-result-in-root/index.js} +12 -31
- package/{esm/rules/require-selections.d.mts → cjs/rules/require-selections/index.d.cts} +5 -5
- package/cjs/rules/{require-selections.js → require-selections/index.js} +47 -45
- package/cjs/rules/require-type-pattern-with-oneof/index.d.cts +13 -0
- package/cjs/rules/require-type-pattern-with-oneof/index.js +63 -0
- package/{esm/rules/selection-set-depth.d.mts → cjs/rules/selection-set-depth/index.d.cts} +5 -5
- package/cjs/rules/{selection-set-depth.js → selection-set-depth/index.js} +16 -42
- package/cjs/rules/{strict-id-in-types.d.ts → strict-id-in-types/index.d.cts} +8 -6
- package/cjs/rules/{strict-id-in-types.js → strict-id-in-types/index.js} +26 -39
- package/cjs/rules/unique-enum-value-names/index.d.cts +13 -0
- package/cjs/rules/{unique-enum-value-names.js → unique-enum-value-names/index.js} +10 -29
- package/{esm/rules/unique-fragment-name.d.mts → cjs/rules/unique-fragment-name/index.d.cts} +4 -4
- package/cjs/rules/unique-fragment-name/index.js +87 -0
- package/cjs/rules/unique-operation-name/index.d.cts +13 -0
- package/cjs/rules/{unique-operation-name.js → unique-operation-name/index.js} +7 -27
- package/{esm/schema.d.mts → cjs/schema.d.cts} +3 -3
- package/cjs/schema.js +11 -36
- package/{esm/siblings.d.mts → cjs/siblings.d.cts} +2 -2
- package/cjs/siblings.js +17 -33
- package/{esm/types.d.mts → cjs/types.d.cts} +5 -4
- package/cjs/types.js +1 -14
- package/{esm/utils.d.mts → cjs/utils.d.cts} +6 -6
- package/cjs/utils.js +94 -115
- package/{cjs → esm}/cache.d.ts +1 -1
- package/esm/cache.js +1 -1
- package/esm/configs/index.d.ts +24 -0
- package/esm/configs/index.js +23 -2
- package/esm/configs/operations-all.js +2 -2
- package/esm/configs/operations-recommended.js +1 -1
- package/esm/configs/schema-all.js +1 -1
- package/esm/configs/schema-recommended.js +1 -1
- package/esm/configs/schema-relay.js +1 -1
- package/esm/documents.js +9 -4
- package/esm/estree-converter/converter.js +1 -1
- package/{cjs → esm}/estree-converter/index.d.ts +2 -2
- package/{cjs → esm}/estree-converter/types.d.ts +1 -1
- package/{cjs → esm}/estree-converter/utils.d.ts +3 -3
- package/esm/estree-converter/utils.js +1 -1
- package/esm/graphql-config.js +3 -3
- package/esm/index.d.ts +184 -0
- package/esm/index.js +11 -5
- package/esm/meta.d.ts +3 -0
- package/esm/meta.js +5 -0
- package/{cjs → esm}/parser.d.ts +10 -3
- package/esm/parser.js +13 -4
- package/{cjs → esm}/processor.d.ts +5 -1
- package/esm/processor.js +6 -1
- package/esm/rules/{alphabetize.d.mts → alphabetize/index.d.ts} +6 -6
- package/esm/rules/{alphabetize.js → alphabetize/index.js} +26 -10
- package/{cjs/rules/description-style.d.ts → esm/rules/description-style/index.d.ts} +5 -5
- package/esm/rules/{description-style.js → description-style/index.js} +2 -2
- package/esm/rules/graphql-js-validation.js +1 -1
- package/{cjs → esm}/rules/index.d.ts +9 -10
- package/esm/rules/index.js +35 -35
- package/esm/rules/{input-name.d.mts → input-name/index.d.ts} +8 -6
- package/esm/rules/{input-name.js → input-name/index.js} +1 -1
- package/esm/rules/{lone-executable-definition.d.mts → lone-executable-definition/index.d.ts} +5 -5
- package/esm/rules/{lone-executable-definition.js → lone-executable-definition/index.js} +2 -2
- package/esm/rules/{match-document-filename.d.mts → match-document-filename/index.d.ts} +6 -6
- package/esm/rules/{match-document-filename.js → match-document-filename/index.js} +4 -4
- package/{cjs/rules/naming-convention.d.ts → esm/rules/naming-convention/index.d.ts} +8 -6
- package/esm/rules/{naming-convention.js → naming-convention/index.js} +2 -2
- package/{cjs/rules/no-one-place-fragments.d.ts → esm/rules/no-anonymous-operations/index.d.ts} +4 -4
- package/esm/rules/{no-anonymous-operations.js → no-anonymous-operations/index.js} +2 -2
- package/{cjs/rules/no-deprecated.d.ts → esm/rules/no-deprecated/index.d.ts} +4 -4
- package/esm/rules/{no-deprecated.js → no-deprecated/index.js} +2 -2
- package/{cjs/rules/no-scalar-result-type-on-mutation.d.ts → esm/rules/no-duplicate-fields/index.d.ts} +4 -4
- package/esm/rules/{no-duplicate-fields.js → no-duplicate-fields/index.js} +1 -1
- package/esm/rules/{no-hashtag-description.d.mts → no-hashtag-description/index.d.ts} +4 -4
- package/esm/rules/{no-hashtag-description.js → no-hashtag-description/index.js} +2 -2
- package/{cjs/rules/no-anonymous-operations.d.ts → esm/rules/no-one-place-fragments/index.d.ts} +4 -4
- package/esm/rules/{no-one-place-fragments.js → no-one-place-fragments/index.js} +2 -2
- package/esm/rules/{no-root-type.d.mts → no-root-type/index.d.ts} +5 -5
- package/esm/rules/{no-root-type.js → no-root-type/index.js} +2 -2
- package/{cjs/rules/no-duplicate-fields.d.ts → esm/rules/no-scalar-result-type-on-mutation/index.d.ts} +4 -4
- package/esm/rules/{no-scalar-result-type-on-mutation.js → no-scalar-result-type-on-mutation/index.js} +2 -2
- package/esm/rules/no-typename-prefix/index.d.ts +13 -0
- package/esm/rules/{no-typename-prefix.js → no-typename-prefix/index.js} +1 -1
- package/esm/rules/no-unreachable-types/index.d.ts +13 -0
- package/esm/rules/{no-unreachable-types.js → no-unreachable-types/index.js} +9 -10
- package/esm/rules/no-unused-fields/index.d.ts +13 -0
- package/esm/rules/{no-unused-fields.js → no-unused-fields/index.js} +8 -7
- package/{cjs/rules/relay-arguments.d.ts → esm/rules/relay-arguments/index.d.ts} +5 -5
- package/esm/rules/{relay-arguments.js → relay-arguments/index.js} +2 -2
- package/{cjs/rules/relay-connection-types.d.ts → esm/rules/relay-connection-types/index.d.ts} +4 -4
- package/esm/rules/{relay-connection-types.js → relay-connection-types/index.js} +1 -1
- package/esm/rules/{relay-edge-types.d.mts → relay-edge-types/index.d.ts} +8 -6
- package/esm/rules/{relay-edge-types.js → relay-edge-types/index.js} +4 -4
- package/esm/rules/relay-page-info/index.d.ts +13 -0
- package/esm/rules/{relay-page-info.js → relay-page-info/index.js} +4 -4
- package/{cjs/rules/require-deprecation-date.d.ts → esm/rules/require-deprecation-date/index.d.ts} +5 -5
- package/esm/rules/{require-deprecation-date.js → require-deprecation-date/index.js} +3 -3
- package/esm/rules/require-deprecation-reason/index.d.ts +13 -0
- package/esm/rules/{require-deprecation-reason.js → require-deprecation-reason/index.js} +3 -3
- package/{cjs/rules/require-description.d.ts → esm/rules/require-description/index.d.ts} +5 -5
- package/esm/rules/{require-description.js → require-description/index.js} +3 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result/index.d.ts +13 -0
- package/esm/rules/{require-field-of-type-query-in-mutation-result.js → require-field-of-type-query-in-mutation-result/index.js} +2 -2
- package/esm/rules/require-import-fragment/index.d.ts +13 -0
- package/esm/rules/{require-import-fragment.js → require-import-fragment/index.js} +13 -12
- package/esm/rules/require-nullable-fields-with-oneof/index.d.ts +13 -0
- package/esm/rules/{require-nullable-fields-with-oneof.js → require-nullable-fields-with-oneof/index.js} +2 -2
- package/esm/rules/require-nullable-result-in-root/index.d.ts +13 -0
- package/esm/rules/{require-nullable-result-in-root.js → require-nullable-result-in-root/index.js} +2 -2
- package/{cjs/rules/require-selections.d.ts → esm/rules/require-selections/index.d.ts} +5 -5
- package/esm/rules/{require-selections.js → require-selections/index.js} +14 -8
- package/esm/rules/require-type-pattern-with-oneof/index.d.ts +13 -0
- package/esm/rules/{require-type-pattern-with-oneof.js → require-type-pattern-with-oneof/index.js} +2 -2
- package/{cjs/rules/selection-set-depth.d.ts → esm/rules/selection-set-depth/index.d.ts} +5 -5
- package/esm/rules/{selection-set-depth.js → selection-set-depth/index.js} +3 -3
- package/esm/rules/{strict-id-in-types.d.mts → strict-id-in-types/index.d.ts} +8 -6
- package/esm/rules/{strict-id-in-types.js → strict-id-in-types/index.js} +2 -2
- package/esm/rules/unique-enum-value-names/index.d.ts +13 -0
- package/esm/rules/{unique-enum-value-names.js → unique-enum-value-names/index.js} +2 -2
- package/{cjs/rules/unique-fragment-name.d.ts → esm/rules/unique-fragment-name/index.d.ts} +4 -4
- package/esm/rules/{unique-fragment-name.js → unique-fragment-name/index.js} +3 -3
- package/esm/rules/unique-operation-name/index.d.ts +13 -0
- package/esm/rules/{unique-operation-name.js → unique-operation-name/index.js} +2 -2
- package/esm/schema.js +1 -1
- package/{cjs → esm}/siblings.d.ts +2 -2
- package/esm/siblings.js +1 -1
- package/{cjs → esm}/types.d.ts +4 -3
- package/{cjs → esm}/utils.d.ts +4 -4
- package/esm/utils.js +40 -17
- package/{index.browser.mjs → index.browser.js} +846 -790
- package/package.json +9 -13
- package/cjs/configs/index.d.ts +0 -174
- package/cjs/flat-configs.d.ts +0 -307
- package/cjs/flat-configs.js +0 -55
- package/cjs/index.d.ts +0 -27
- package/cjs/rules/no-scalar-result-type-on-mutation.js +0 -88
- package/cjs/rules/no-typename-prefix.d.ts +0 -13
- package/cjs/rules/no-unreachable-types.d.ts +0 -13
- package/cjs/rules/no-unreachable-types.js +0 -177
- package/cjs/rules/no-unused-fields.d.ts +0 -13
- package/cjs/rules/relay-page-info.d.ts +0 -13
- package/cjs/rules/require-deprecation-reason.d.ts +0 -13
- package/cjs/rules/require-deprecation-reason.js +0 -85
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +0 -13
- package/cjs/rules/require-import-fragment.d.ts +0 -13
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +0 -13
- package/cjs/rules/require-nullable-fields-with-oneof.js +0 -81
- package/cjs/rules/require-nullable-result-in-root.d.ts +0 -13
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +0 -13
- package/cjs/rules/require-type-pattern-with-oneof.js +0 -83
- package/cjs/rules/unique-enum-value-names.d.ts +0 -13
- package/cjs/rules/unique-fragment-name.js +0 -106
- package/cjs/rules/unique-operation-name.d.ts +0 -13
- package/esm/configs/index.d.mts +0 -174
- package/esm/estree-converter/index.d.mts +0 -8
- package/esm/flat-configs.d.mts +0 -307
- package/esm/flat-configs.js +0 -36
- package/esm/index.d.mts +0 -27
- package/esm/package.json +0 -1
- package/esm/rules/no-anonymous-operations.d.mts +0 -13
- package/esm/rules/no-duplicate-fields.d.mts +0 -13
- package/esm/rules/no-one-place-fragments.d.mts +0 -13
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +0 -13
- package/esm/rules/no-typename-prefix.d.mts +0 -13
- package/esm/rules/no-unreachable-types.d.mts +0 -13
- package/esm/rules/no-unused-fields.d.mts +0 -13
- package/esm/rules/relay-page-info.d.mts +0 -13
- package/esm/rules/require-deprecation-reason.d.mts +0 -13
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +0 -13
- package/esm/rules/require-import-fragment.d.mts +0 -13
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +0 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +0 -13
- package/esm/rules/require-type-pattern-with-oneof.d.mts +0 -13
- package/esm/rules/unique-enum-value-names.d.mts +0 -13
- package/esm/rules/unique-operation-name.d.mts +0 -13
- package/cjs/configs/{operations-all.d.ts → operations-all.d.cts} +0 -0
- package/cjs/configs/{operations-recommended.d.ts → operations-recommended.d.cts} +0 -0
- package/cjs/configs/{schema-all.d.ts → schema-all.d.cts} +0 -0
- package/cjs/configs/{schema-recommended.d.ts → schema-recommended.d.cts} +0 -0
- package/cjs/configs/{schema-relay.d.ts → schema-relay.d.cts} +0 -0
- package/{esm/documents.d.mts → cjs/documents.d.cts} +1 -1
- package/esm/{chunk-U3TKCM4X.js → chunk-UIAXBAMD.js} +0 -0
- package/esm/configs/{operations-all.d.mts → operations-all.d.ts} +0 -0
- package/esm/configs/{operations-recommended.d.mts → operations-recommended.d.ts} +0 -0
- package/esm/configs/{schema-all.d.mts → schema-all.d.ts} +0 -0
- package/esm/configs/{schema-recommended.d.mts → schema-recommended.d.ts} +0 -0
- package/esm/configs/{schema-relay.d.mts → schema-relay.d.ts} +0 -0
- package/{cjs → esm}/documents.d.ts +1 -1
- package/{cjs → esm}/estree-converter/converter.d.ts +0 -0
- package/{cjs → esm}/graphql-config.d.ts +1 -1
- package/{cjs → esm}/rules/graphql-js-validation.d.ts +2 -2
- package/{cjs → esm}/schema.d.ts +1 -1
|
@@ -35,7 +35,7 @@ var require_operations_all = __commonJS({
|
|
|
35
35
|
selections: ["OperationDefinition", "FragmentDefinition"],
|
|
36
36
|
variables: !0,
|
|
37
37
|
arguments: ["Field", "Directive"],
|
|
38
|
-
groups: ["
|
|
38
|
+
groups: ["...", "id", "*", "{"]
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
41
|
"@graphql-eslint/lone-executable-definition": "error",
|
|
@@ -237,9 +237,22 @@ var require_schema_relay = __commonJS({
|
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
// src/parser.ts
|
|
240
|
+
import debugFactory2 from "debug";
|
|
241
|
+
import { buildSchema, GraphQLError } from "graphql";
|
|
240
242
|
import { parseGraphQLSDL } from "@graphql-tools/utils";
|
|
243
|
+
|
|
244
|
+
// src/cache.ts
|
|
241
245
|
import debugFactory from "debug";
|
|
242
|
-
|
|
246
|
+
var log = debugFactory("graphql-eslint:ModuleCache"), ModuleCache = class {
|
|
247
|
+
map = /* @__PURE__ */ new Map();
|
|
248
|
+
set(cacheKey, result) {
|
|
249
|
+
}
|
|
250
|
+
get(cacheKey, settings = {
|
|
251
|
+
lifetime: 10
|
|
252
|
+
/* seconds */
|
|
253
|
+
}) {
|
|
254
|
+
}
|
|
255
|
+
};
|
|
243
256
|
|
|
244
257
|
// src/estree-converter/converter.ts
|
|
245
258
|
import {
|
|
@@ -374,6 +387,9 @@ function convertToESTree(node, schema15) {
|
|
|
374
387
|
);
|
|
375
388
|
}
|
|
376
389
|
|
|
390
|
+
// src/meta.ts
|
|
391
|
+
var version = process.env.VERSION;
|
|
392
|
+
|
|
377
393
|
// src/siblings.ts
|
|
378
394
|
import {
|
|
379
395
|
Kind as Kind3,
|
|
@@ -411,7 +427,7 @@ var chalk = {
|
|
|
411
427
|
// eslint-disable-next-line no-console
|
|
412
428
|
console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
|
|
413
429
|
)
|
|
414
|
-
},
|
|
430
|
+
}, slash = (path2) => path2.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = /[/\\]\d+_document.graphql$/, CWD = process.cwd(), getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = [
|
|
415
431
|
Kind2.OBJECT_TYPE_DEFINITION,
|
|
416
432
|
Kind2.INTERFACE_TYPE_DEFINITION,
|
|
417
433
|
Kind2.ENUM_TYPE_DEFINITION,
|
|
@@ -460,26 +476,49 @@ function truthy(value) {
|
|
|
460
476
|
return !!value;
|
|
461
477
|
}
|
|
462
478
|
var DisplayNodeNameMap = {
|
|
463
|
-
[Kind2.
|
|
464
|
-
[Kind2.
|
|
465
|
-
[Kind2.
|
|
466
|
-
[Kind2.
|
|
479
|
+
[Kind2.ARGUMENT]: "argument",
|
|
480
|
+
[Kind2.BOOLEAN]: "boolean",
|
|
481
|
+
[Kind2.DIRECTIVE_DEFINITION]: "directive",
|
|
482
|
+
[Kind2.DIRECTIVE]: "directive",
|
|
483
|
+
[Kind2.DOCUMENT]: "document",
|
|
467
484
|
[Kind2.ENUM_TYPE_DEFINITION]: "enum",
|
|
468
485
|
[Kind2.ENUM_TYPE_EXTENSION]: "enum",
|
|
469
|
-
[Kind2.
|
|
486
|
+
[Kind2.ENUM_VALUE_DEFINITION]: "enum value",
|
|
487
|
+
[Kind2.ENUM]: "enum",
|
|
488
|
+
[Kind2.FIELD_DEFINITION]: "field",
|
|
489
|
+
[Kind2.FIELD]: "field",
|
|
490
|
+
[Kind2.FLOAT]: "float",
|
|
491
|
+
[Kind2.FRAGMENT_DEFINITION]: "fragment",
|
|
492
|
+
[Kind2.FRAGMENT_SPREAD]: "fragment spread",
|
|
493
|
+
[Kind2.INLINE_FRAGMENT]: "inline fragment",
|
|
470
494
|
[Kind2.INPUT_OBJECT_TYPE_DEFINITION]: "input",
|
|
471
495
|
[Kind2.INPUT_OBJECT_TYPE_EXTENSION]: "input",
|
|
472
|
-
[Kind2.UNION_TYPE_DEFINITION]: "union",
|
|
473
|
-
[Kind2.UNION_TYPE_EXTENSION]: "union",
|
|
474
|
-
[Kind2.DIRECTIVE_DEFINITION]: "directive",
|
|
475
|
-
[Kind2.FIELD_DEFINITION]: "field",
|
|
476
|
-
[Kind2.ENUM_VALUE_DEFINITION]: "enum value",
|
|
477
496
|
[Kind2.INPUT_VALUE_DEFINITION]: "input value",
|
|
478
|
-
[Kind2.
|
|
479
|
-
[Kind2.
|
|
480
|
-
[Kind2.
|
|
497
|
+
[Kind2.INT]: "int",
|
|
498
|
+
[Kind2.INTERFACE_TYPE_DEFINITION]: "interface",
|
|
499
|
+
[Kind2.INTERFACE_TYPE_EXTENSION]: "interface",
|
|
500
|
+
[Kind2.LIST_TYPE]: "list type",
|
|
501
|
+
[Kind2.LIST]: "list",
|
|
502
|
+
[Kind2.NAME]: "name",
|
|
503
|
+
[Kind2.NAMED_TYPE]: "named type",
|
|
504
|
+
[Kind2.NON_NULL_TYPE]: "non-null type",
|
|
505
|
+
[Kind2.NULL]: "null",
|
|
506
|
+
[Kind2.OBJECT_FIELD]: "object field",
|
|
507
|
+
[Kind2.OBJECT_TYPE_DEFINITION]: "type",
|
|
508
|
+
[Kind2.OBJECT_TYPE_EXTENSION]: "type",
|
|
509
|
+
[Kind2.OBJECT]: "object",
|
|
481
510
|
[Kind2.OPERATION_DEFINITION]: "operation",
|
|
482
|
-
[Kind2.
|
|
511
|
+
[Kind2.OPERATION_TYPE_DEFINITION]: "operation type",
|
|
512
|
+
[Kind2.SCALAR_TYPE_DEFINITION]: "scalar",
|
|
513
|
+
[Kind2.SCALAR_TYPE_EXTENSION]: "scalar",
|
|
514
|
+
[Kind2.SCHEMA_DEFINITION]: "schema",
|
|
515
|
+
[Kind2.SCHEMA_EXTENSION]: "schema",
|
|
516
|
+
[Kind2.SELECTION_SET]: "selection set",
|
|
517
|
+
[Kind2.STRING]: "string",
|
|
518
|
+
[Kind2.UNION_TYPE_DEFINITION]: "union",
|
|
519
|
+
[Kind2.UNION_TYPE_EXTENSION]: "union",
|
|
520
|
+
[Kind2.VARIABLE_DEFINITION]: "variable",
|
|
521
|
+
[Kind2.VARIABLE]: "variable"
|
|
483
522
|
};
|
|
484
523
|
function displayNodeName(node) {
|
|
485
524
|
return `${node.kind === Kind2.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value}"`;
|
|
@@ -575,7 +614,7 @@ function getSiblings(documents) {
|
|
|
575
614
|
}
|
|
576
615
|
|
|
577
616
|
// src/parser.ts
|
|
578
|
-
var debug =
|
|
617
|
+
var debug = debugFactory2("graphql-eslint:parser");
|
|
579
618
|
debug("cwd %o", CWD);
|
|
580
619
|
var LEGACY_PARSER_OPTIONS_KEYS = [
|
|
581
620
|
"schema",
|
|
@@ -640,184 +679,581 @@ function parseForESLint(code, options) {
|
|
|
640
679
|
throw error;
|
|
641
680
|
}
|
|
642
681
|
}
|
|
682
|
+
var parser = {
|
|
683
|
+
parseForESLint,
|
|
684
|
+
meta: {
|
|
685
|
+
name: "@graphql-eslint/parser",
|
|
686
|
+
version
|
|
687
|
+
}
|
|
688
|
+
};
|
|
643
689
|
|
|
644
|
-
// src/rules/
|
|
690
|
+
// src/rules/alphabetize/index.ts
|
|
645
691
|
import {
|
|
646
|
-
Kind as Kind4
|
|
647
|
-
validate,
|
|
648
|
-
visit as visit3
|
|
692
|
+
Kind as Kind4
|
|
649
693
|
} from "graphql";
|
|
650
|
-
import
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
ValuesOfCorrectTypeRule,
|
|
679
|
-
VariablesAreInputTypesRule,
|
|
680
|
-
VariablesInAllowedPositionRule
|
|
681
|
-
} from "graphql/validation/index.js";
|
|
682
|
-
import { validateSDL } from "graphql/validation/validate.js";
|
|
683
|
-
function validateDocument({
|
|
684
|
-
context,
|
|
685
|
-
schema: schema15 = null,
|
|
686
|
-
documentNode,
|
|
687
|
-
rule: rule35,
|
|
688
|
-
hasDidYouMeanSuggestions
|
|
689
|
-
}) {
|
|
690
|
-
if (documentNode.definitions.length !== 0)
|
|
691
|
-
try {
|
|
692
|
-
let validationErrors = schema15 ? validate(schema15, documentNode, [rule35]) : validateSDL(documentNode, null, [rule35]);
|
|
693
|
-
for (let error of validationErrors) {
|
|
694
|
-
let { line, column } = error.locations[0], sourceCode = context.getSourceCode(), { tokens } = sourceCode.ast, token = tokens.find(
|
|
695
|
-
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
|
696
|
-
), loc = {
|
|
697
|
-
line,
|
|
698
|
-
column: column - 1
|
|
699
|
-
};
|
|
700
|
-
token && (loc = // if cursor on `@` symbol than use next node
|
|
701
|
-
token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc);
|
|
702
|
-
let didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)?.groups.content, matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
|
|
703
|
-
context.report({
|
|
704
|
-
loc,
|
|
705
|
-
message: error.message,
|
|
706
|
-
suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
|
|
707
|
-
let { name } = match.groups;
|
|
708
|
-
return {
|
|
709
|
-
desc: `Rename to \`${name}\``,
|
|
710
|
-
fix: (fixer) => fixer.replaceText(token, name)
|
|
711
|
-
};
|
|
712
|
-
}) : []
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
} catch (error) {
|
|
716
|
-
context.report({
|
|
717
|
-
loc: REPORT_ON_FIRST_CHARACTER,
|
|
718
|
-
message: error.message
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
723
|
-
let fragmentDefs = /* @__PURE__ */ new Set(), fragmentSpreads = /* @__PURE__ */ new Set();
|
|
724
|
-
return visit3(node, {
|
|
725
|
-
FragmentDefinition(node2) {
|
|
726
|
-
fragmentDefs.add(node2.name.value);
|
|
727
|
-
},
|
|
728
|
-
FragmentSpread(node2) {
|
|
729
|
-
fragmentSpreads.add(node2.name.value);
|
|
730
|
-
}
|
|
731
|
-
}), { fragmentDefs, fragmentSpreads };
|
|
732
|
-
}, getMissingFragments = (node) => {
|
|
733
|
-
let { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
|
734
|
-
return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
|
|
735
|
-
}, handleMissingFragments = ({ ruleId, context, node }) => {
|
|
736
|
-
let missingFragments = getMissingFragments(node);
|
|
737
|
-
if (missingFragments.length > 0) {
|
|
738
|
-
let siblings = requireSiblingsOperations(ruleId, context), fragmentsToAdd = [];
|
|
739
|
-
for (let fragmentName of missingFragments) {
|
|
740
|
-
let [foundFragment] = siblings.getFragment(fragmentName).map((source) => source.document);
|
|
741
|
-
foundFragment && fragmentsToAdd.push(foundFragment);
|
|
742
|
-
}
|
|
743
|
-
if (fragmentsToAdd.length > 0)
|
|
744
|
-
return handleMissingFragments({
|
|
745
|
-
ruleId,
|
|
746
|
-
context,
|
|
747
|
-
node: {
|
|
748
|
-
kind: Kind4.DOCUMENT,
|
|
749
|
-
definitions: [...node.definitions, ...fragmentsToAdd]
|
|
750
|
-
}
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
return node;
|
|
754
|
-
}, validationToRule = ({
|
|
755
|
-
ruleId,
|
|
756
|
-
rule: rule35,
|
|
757
|
-
getDocumentNode,
|
|
758
|
-
schema: schema15 = [],
|
|
759
|
-
hasDidYouMeanSuggestions
|
|
760
|
-
}, docs) => ({
|
|
761
|
-
[ruleId]: {
|
|
762
|
-
meta: {
|
|
763
|
-
docs: {
|
|
764
|
-
recommended: !0,
|
|
765
|
-
...docs,
|
|
766
|
-
graphQLJSRuleName: rule35.name,
|
|
767
|
-
url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
|
|
768
|
-
description: `${docs.description}
|
|
769
|
-
> This rule is a wrapper around a \`graphql-js\` validation function.`
|
|
694
|
+
import lowerCase2 from "lodash.lowercase";
|
|
695
|
+
var RULE_ID = "alphabetize", fieldsEnum = [
|
|
696
|
+
Kind4.OBJECT_TYPE_DEFINITION,
|
|
697
|
+
Kind4.INTERFACE_TYPE_DEFINITION,
|
|
698
|
+
Kind4.INPUT_OBJECT_TYPE_DEFINITION
|
|
699
|
+
], selectionsEnum = [
|
|
700
|
+
Kind4.OPERATION_DEFINITION,
|
|
701
|
+
Kind4.FRAGMENT_DEFINITION
|
|
702
|
+
], argumentsEnum = [
|
|
703
|
+
Kind4.FIELD_DEFINITION,
|
|
704
|
+
Kind4.FIELD,
|
|
705
|
+
Kind4.DIRECTIVE_DEFINITION,
|
|
706
|
+
Kind4.DIRECTIVE
|
|
707
|
+
], schema = {
|
|
708
|
+
type: "array",
|
|
709
|
+
minItems: 1,
|
|
710
|
+
maxItems: 1,
|
|
711
|
+
items: {
|
|
712
|
+
type: "object",
|
|
713
|
+
additionalProperties: !1,
|
|
714
|
+
minProperties: 1,
|
|
715
|
+
properties: {
|
|
716
|
+
fields: {
|
|
717
|
+
...ARRAY_DEFAULT_OPTIONS,
|
|
718
|
+
items: {
|
|
719
|
+
enum: fieldsEnum
|
|
720
|
+
},
|
|
721
|
+
description: "Fields of `type`, `interface`, and `input`."
|
|
770
722
|
},
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
723
|
+
values: {
|
|
724
|
+
type: "boolean",
|
|
725
|
+
description: "Values of `enum`."
|
|
726
|
+
},
|
|
727
|
+
selections: {
|
|
728
|
+
...ARRAY_DEFAULT_OPTIONS,
|
|
729
|
+
items: {
|
|
730
|
+
enum: selectionsEnum
|
|
731
|
+
},
|
|
732
|
+
description: "Selections of `fragment` and operations `query`, `mutation` and `subscription`."
|
|
733
|
+
},
|
|
734
|
+
variables: {
|
|
735
|
+
type: "boolean",
|
|
736
|
+
description: "Variables of operations `query`, `mutation` and `subscription`."
|
|
737
|
+
},
|
|
738
|
+
arguments: {
|
|
739
|
+
...ARRAY_DEFAULT_OPTIONS,
|
|
740
|
+
items: {
|
|
741
|
+
enum: argumentsEnum
|
|
742
|
+
},
|
|
743
|
+
description: "Arguments of fields and directives."
|
|
744
|
+
},
|
|
745
|
+
definitions: {
|
|
746
|
+
type: "boolean",
|
|
747
|
+
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
|
748
|
+
},
|
|
749
|
+
groups: {
|
|
750
|
+
...ARRAY_DEFAULT_OPTIONS,
|
|
751
|
+
minItems: 2,
|
|
752
|
+
description: [
|
|
753
|
+
"Order group. Example: `['...', 'id', '*', '{']` where:",
|
|
754
|
+
"- `...` stands for fragment spreads",
|
|
755
|
+
"- `id` stands for field with name `id`",
|
|
756
|
+
"- `*` stands for everything else",
|
|
757
|
+
"- `{` stands for fields `selection set`"
|
|
758
|
+
].join(`
|
|
759
|
+
`)
|
|
760
|
+
}
|
|
787
761
|
}
|
|
788
762
|
}
|
|
789
|
-
}
|
|
790
|
-
{
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
763
|
+
}, rule = {
|
|
764
|
+
meta: {
|
|
765
|
+
type: "suggestion",
|
|
766
|
+
fixable: "code",
|
|
767
|
+
docs: {
|
|
768
|
+
category: ["Schema", "Operations"],
|
|
769
|
+
description: "Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.",
|
|
770
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
|
771
|
+
examples: [
|
|
772
|
+
{
|
|
773
|
+
title: "Incorrect",
|
|
774
|
+
usage: [{ fields: [Kind4.OBJECT_TYPE_DEFINITION] }],
|
|
775
|
+
code: (
|
|
776
|
+
/* GraphQL */
|
|
777
|
+
`
|
|
778
|
+
type User {
|
|
779
|
+
password: String
|
|
780
|
+
firstName: String! # should be before "password"
|
|
781
|
+
age: Int # should be before "firstName"
|
|
782
|
+
lastName: String!
|
|
783
|
+
}
|
|
784
|
+
`
|
|
785
|
+
)
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
title: "Correct",
|
|
789
|
+
usage: [{ fields: [Kind4.OBJECT_TYPE_DEFINITION] }],
|
|
790
|
+
code: (
|
|
791
|
+
/* GraphQL */
|
|
792
|
+
`
|
|
793
|
+
type User {
|
|
794
|
+
age: Int
|
|
795
|
+
firstName: String!
|
|
796
|
+
lastName: String!
|
|
797
|
+
password: String
|
|
798
|
+
}
|
|
799
|
+
`
|
|
800
|
+
)
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
title: "Incorrect",
|
|
804
|
+
usage: [{ values: !0 }],
|
|
805
|
+
code: (
|
|
806
|
+
/* GraphQL */
|
|
807
|
+
`
|
|
808
|
+
enum Role {
|
|
809
|
+
SUPER_ADMIN
|
|
810
|
+
ADMIN # should be before "SUPER_ADMIN"
|
|
811
|
+
USER
|
|
812
|
+
GOD # should be before "USER"
|
|
813
|
+
}
|
|
814
|
+
`
|
|
815
|
+
)
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
title: "Correct",
|
|
819
|
+
usage: [{ values: !0 }],
|
|
820
|
+
code: (
|
|
821
|
+
/* GraphQL */
|
|
822
|
+
`
|
|
823
|
+
enum Role {
|
|
824
|
+
ADMIN
|
|
825
|
+
GOD
|
|
826
|
+
SUPER_ADMIN
|
|
827
|
+
USER
|
|
828
|
+
}
|
|
829
|
+
`
|
|
830
|
+
)
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
title: "Incorrect",
|
|
834
|
+
usage: [{ selections: [Kind4.OPERATION_DEFINITION] }],
|
|
835
|
+
code: (
|
|
836
|
+
/* GraphQL */
|
|
837
|
+
`
|
|
838
|
+
query {
|
|
839
|
+
me {
|
|
840
|
+
firstName
|
|
841
|
+
lastName
|
|
842
|
+
email # should be before "lastName"
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
`
|
|
846
|
+
)
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
title: "Correct",
|
|
850
|
+
usage: [{ selections: [Kind4.OPERATION_DEFINITION] }],
|
|
851
|
+
code: (
|
|
852
|
+
/* GraphQL */
|
|
853
|
+
`
|
|
854
|
+
query {
|
|
855
|
+
me {
|
|
856
|
+
email
|
|
857
|
+
firstName
|
|
858
|
+
lastName
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
`
|
|
862
|
+
)
|
|
863
|
+
}
|
|
864
|
+
],
|
|
865
|
+
configOptions: {
|
|
866
|
+
schema: [
|
|
867
|
+
{
|
|
868
|
+
definitions: !0,
|
|
869
|
+
fields: fieldsEnum,
|
|
870
|
+
values: !0,
|
|
871
|
+
arguments: argumentsEnum,
|
|
872
|
+
groups: ["id", "*", "createdAt", "updatedAt"]
|
|
873
|
+
}
|
|
874
|
+
],
|
|
875
|
+
operations: [
|
|
876
|
+
{
|
|
877
|
+
definitions: !0,
|
|
878
|
+
selections: selectionsEnum,
|
|
879
|
+
variables: !0,
|
|
880
|
+
arguments: [Kind4.FIELD, Kind4.DIRECTIVE],
|
|
881
|
+
groups: ["...", "id", "*", "{"]
|
|
882
|
+
}
|
|
883
|
+
]
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
messages: {
|
|
887
|
+
[RULE_ID]: "{{ currNode }} should be before {{ prevNode }}"
|
|
888
|
+
},
|
|
889
|
+
schema
|
|
890
|
+
},
|
|
891
|
+
create(context) {
|
|
892
|
+
let sourceCode = context.getSourceCode();
|
|
893
|
+
function isNodeAndCommentOnSameLine(node, comment) {
|
|
894
|
+
return node.loc.end.line === comment.loc.start.line;
|
|
895
|
+
}
|
|
896
|
+
function getBeforeComments(node) {
|
|
897
|
+
let commentsBefore = sourceCode.getCommentsBefore(node);
|
|
898
|
+
if (commentsBefore.length === 0)
|
|
899
|
+
return [];
|
|
900
|
+
let tokenBefore = sourceCode.getTokenBefore(node);
|
|
901
|
+
if (tokenBefore)
|
|
902
|
+
return commentsBefore.filter((comment) => !isNodeAndCommentOnSameLine(tokenBefore, comment));
|
|
903
|
+
let filteredComments = [], nodeLine = node.loc.start.line;
|
|
904
|
+
for (let i = commentsBefore.length - 1; i >= 0; i -= 1) {
|
|
905
|
+
let comment = commentsBefore[i];
|
|
906
|
+
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
|
907
|
+
break;
|
|
908
|
+
filteredComments.unshift(comment);
|
|
909
|
+
}
|
|
910
|
+
return filteredComments;
|
|
911
|
+
}
|
|
912
|
+
function getRangeWithComments(node) {
|
|
913
|
+
node.kind === Kind4.VARIABLE && (node = node.parent);
|
|
914
|
+
let [firstBeforeComment] = getBeforeComments(node), [firstAfterComment] = sourceCode.getCommentsAfter(node), from = firstBeforeComment || node, to = firstAfterComment && isNodeAndCommentOnSameLine(node, firstAfterComment) ? firstAfterComment : node;
|
|
915
|
+
return [from.range[0], to.range[1]];
|
|
916
|
+
}
|
|
917
|
+
function checkNodes(nodes = []) {
|
|
918
|
+
for (let i = 1; i < nodes.length; i += 1) {
|
|
919
|
+
let currNode = nodes[i], currName = getName(currNode);
|
|
920
|
+
if (!currName)
|
|
921
|
+
continue;
|
|
922
|
+
let prevNode = nodes[i - 1], prevName = getName(prevNode);
|
|
923
|
+
if (prevName) {
|
|
924
|
+
let compareResult = prevName.localeCompare(currName), { groups } = opts, shouldSortByGroup = !1;
|
|
925
|
+
if (groups?.length) {
|
|
926
|
+
if (!groups.includes("*"))
|
|
927
|
+
throw new Error("`groups` option should contain `*` string.");
|
|
928
|
+
let indexForPrev = getIndex({ node: prevNode, groups }), indexForCurr = getIndex({ node: currNode, groups });
|
|
929
|
+
if (shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
context.report({
|
|
936
|
+
// @ts-expect-error can't be undefined
|
|
937
|
+
node: "alias" in currNode && currNode.alias || currNode.name,
|
|
938
|
+
messageId: RULE_ID,
|
|
939
|
+
data: {
|
|
940
|
+
currNode: displayNodeName(currNode),
|
|
941
|
+
prevNode: prevName ? displayNodeName(prevNode) : lowerCase2(prevNode.kind)
|
|
942
|
+
},
|
|
943
|
+
*fix(fixer) {
|
|
944
|
+
let prevRange = getRangeWithComments(prevNode), currRange = getRangeWithComments(currNode);
|
|
945
|
+
yield fixer.replaceTextRange(
|
|
946
|
+
prevRange,
|
|
947
|
+
sourceCode.getText({ range: currRange })
|
|
948
|
+
), yield fixer.replaceTextRange(
|
|
949
|
+
currRange,
|
|
950
|
+
sourceCode.getText({ range: prevRange })
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
let opts = context.options[0], fields = new Set(opts.fields ?? []), listeners = {}, fieldsSelector = [
|
|
957
|
+
fields.has(Kind4.OBJECT_TYPE_DEFINITION) && [
|
|
958
|
+
Kind4.OBJECT_TYPE_DEFINITION,
|
|
959
|
+
Kind4.OBJECT_TYPE_EXTENSION
|
|
960
|
+
],
|
|
961
|
+
fields.has(Kind4.INTERFACE_TYPE_DEFINITION) && [
|
|
962
|
+
Kind4.INTERFACE_TYPE_DEFINITION,
|
|
963
|
+
Kind4.INTERFACE_TYPE_EXTENSION
|
|
964
|
+
],
|
|
965
|
+
fields.has(Kind4.INPUT_OBJECT_TYPE_DEFINITION) && [
|
|
966
|
+
Kind4.INPUT_OBJECT_TYPE_DEFINITION,
|
|
967
|
+
Kind4.INPUT_OBJECT_TYPE_EXTENSION
|
|
968
|
+
]
|
|
969
|
+
].filter(truthy).flat().join(","), selectionsSelector = opts.selections?.join(","), argumentsSelector = opts.arguments?.join(",");
|
|
970
|
+
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
|
971
|
+
checkNodes(node.fields);
|
|
972
|
+
}), opts.values) {
|
|
973
|
+
let enumValuesSelector = [Kind4.ENUM_TYPE_DEFINITION, Kind4.ENUM_TYPE_EXTENSION].join(",");
|
|
974
|
+
listeners[enumValuesSelector] = (node) => {
|
|
975
|
+
checkNodes(node.values);
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
return selectionsSelector && (listeners[`:matches(${selectionsSelector}) SelectionSet`] = (node) => {
|
|
979
|
+
checkNodes(node.selections);
|
|
980
|
+
}), opts.variables && (listeners.OperationDefinition = (node) => {
|
|
981
|
+
checkNodes(node.variableDefinitions?.map((varDef) => varDef.variable));
|
|
982
|
+
}), argumentsSelector && (listeners[argumentsSelector] = (node) => {
|
|
983
|
+
checkNodes(node.arguments);
|
|
984
|
+
}), opts.definitions && (listeners.Document = (node) => {
|
|
985
|
+
checkNodes(node.definitions);
|
|
986
|
+
}), listeners;
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
function getIndex({
|
|
990
|
+
node,
|
|
991
|
+
groups
|
|
992
|
+
}) {
|
|
993
|
+
let index = groups.indexOf(getName(node));
|
|
994
|
+
return index === -1 && "selectionSet" in node && node.selectionSet && (index = groups.indexOf("{")), index === -1 && node.kind === Kind4.FRAGMENT_SPREAD && (index = groups.indexOf("...")), index === -1 && (index = groups.indexOf("*")), index;
|
|
995
|
+
}
|
|
996
|
+
function getName(node) {
|
|
997
|
+
return "alias" in node && node.alias?.value || //
|
|
998
|
+
"name" in node && node.name?.value || "";
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// src/rules/description-style/index.ts
|
|
1002
|
+
var schema2 = {
|
|
1003
|
+
type: "array",
|
|
1004
|
+
maxItems: 1,
|
|
1005
|
+
items: {
|
|
1006
|
+
type: "object",
|
|
1007
|
+
additionalProperties: !1,
|
|
1008
|
+
minProperties: 1,
|
|
1009
|
+
properties: {
|
|
1010
|
+
style: {
|
|
1011
|
+
enum: ["block", "inline"],
|
|
1012
|
+
default: "block"
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}, rule2 = {
|
|
1017
|
+
meta: {
|
|
1018
|
+
type: "suggestion",
|
|
1019
|
+
hasSuggestions: !0,
|
|
1020
|
+
docs: {
|
|
1021
|
+
examples: [
|
|
1022
|
+
{
|
|
1023
|
+
title: "Incorrect",
|
|
1024
|
+
usage: [{ style: "inline" }],
|
|
1025
|
+
code: (
|
|
1026
|
+
/* GraphQL */
|
|
1027
|
+
`
|
|
1028
|
+
""" Description """
|
|
1029
|
+
type someTypeName {
|
|
1030
|
+
# ...
|
|
1031
|
+
}
|
|
1032
|
+
`
|
|
1033
|
+
)
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
title: "Correct",
|
|
1037
|
+
usage: [{ style: "inline" }],
|
|
1038
|
+
code: (
|
|
1039
|
+
/* GraphQL */
|
|
1040
|
+
`
|
|
1041
|
+
" Description "
|
|
1042
|
+
type someTypeName {
|
|
1043
|
+
# ...
|
|
1044
|
+
}
|
|
1045
|
+
`
|
|
1046
|
+
)
|
|
1047
|
+
}
|
|
1048
|
+
],
|
|
1049
|
+
description: "Require all comments to follow the same style (either block or inline).",
|
|
1050
|
+
category: "Schema",
|
|
1051
|
+
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
|
|
1052
|
+
recommended: !0
|
|
1053
|
+
},
|
|
1054
|
+
schema: schema2
|
|
1055
|
+
},
|
|
1056
|
+
create(context) {
|
|
1057
|
+
let { style = "block" } = context.options[0] || {}, isBlock = style === "block";
|
|
1058
|
+
return {
|
|
1059
|
+
[`.description[type=StringValue][block!=${isBlock}]`](node) {
|
|
1060
|
+
context.report({
|
|
1061
|
+
loc: isBlock ? node.loc : node.loc.start,
|
|
1062
|
+
message: `Unexpected ${isBlock ? "inline" : "block"} description for ${getNodeName(
|
|
1063
|
+
node.parent
|
|
1064
|
+
)}`,
|
|
1065
|
+
suggest: [
|
|
1066
|
+
{
|
|
1067
|
+
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
|
|
1068
|
+
fix(fixer) {
|
|
1069
|
+
let originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
|
1070
|
+
return fixer.replaceText(node, newText);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
]
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
// src/rules/graphql-js-validation.ts
|
|
1081
|
+
import {
|
|
1082
|
+
Kind as Kind5,
|
|
1083
|
+
validate,
|
|
1084
|
+
visit as visit3
|
|
1085
|
+
} from "graphql";
|
|
1086
|
+
import {
|
|
1087
|
+
ExecutableDefinitionsRule,
|
|
1088
|
+
FieldsOnCorrectTypeRule,
|
|
1089
|
+
FragmentsOnCompositeTypesRule,
|
|
1090
|
+
KnownArgumentNamesRule,
|
|
1091
|
+
KnownDirectivesRule,
|
|
1092
|
+
KnownFragmentNamesRule,
|
|
1093
|
+
KnownTypeNamesRule,
|
|
1094
|
+
LoneAnonymousOperationRule,
|
|
1095
|
+
LoneSchemaDefinitionRule,
|
|
1096
|
+
NoFragmentCyclesRule,
|
|
1097
|
+
NoUndefinedVariablesRule,
|
|
1098
|
+
NoUnusedFragmentsRule,
|
|
1099
|
+
NoUnusedVariablesRule,
|
|
1100
|
+
OverlappingFieldsCanBeMergedRule,
|
|
1101
|
+
PossibleFragmentSpreadsRule,
|
|
1102
|
+
PossibleTypeExtensionsRule,
|
|
1103
|
+
ProvidedRequiredArgumentsRule,
|
|
1104
|
+
ScalarLeafsRule,
|
|
1105
|
+
SingleFieldSubscriptionsRule,
|
|
1106
|
+
UniqueArgumentNamesRule,
|
|
1107
|
+
UniqueDirectiveNamesRule,
|
|
1108
|
+
UniqueDirectivesPerLocationRule,
|
|
1109
|
+
UniqueFieldDefinitionNamesRule,
|
|
1110
|
+
UniqueInputFieldNamesRule,
|
|
1111
|
+
UniqueOperationTypesRule,
|
|
1112
|
+
UniqueTypeNamesRule,
|
|
1113
|
+
UniqueVariableNamesRule,
|
|
1114
|
+
ValuesOfCorrectTypeRule,
|
|
1115
|
+
VariablesAreInputTypesRule,
|
|
1116
|
+
VariablesInAllowedPositionRule
|
|
1117
|
+
} from "graphql/validation/index.js";
|
|
1118
|
+
import { validateSDL } from "graphql/validation/validate.js";
|
|
1119
|
+
function validateDocument({
|
|
1120
|
+
context,
|
|
1121
|
+
schema: schema15 = null,
|
|
1122
|
+
documentNode,
|
|
1123
|
+
rule: rule35,
|
|
1124
|
+
hasDidYouMeanSuggestions
|
|
1125
|
+
}) {
|
|
1126
|
+
if (documentNode.definitions.length !== 0)
|
|
1127
|
+
try {
|
|
1128
|
+
let validationErrors = schema15 ? validate(schema15, documentNode, [rule35]) : validateSDL(documentNode, null, [rule35]);
|
|
1129
|
+
for (let error of validationErrors) {
|
|
1130
|
+
let { line, column } = error.locations[0], sourceCode = context.getSourceCode(), { tokens } = sourceCode.ast, token = tokens.find(
|
|
1131
|
+
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
|
1132
|
+
), loc = {
|
|
1133
|
+
line,
|
|
1134
|
+
column: column - 1
|
|
1135
|
+
};
|
|
1136
|
+
token && (loc = // if cursor on `@` symbol than use next node
|
|
1137
|
+
token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc);
|
|
1138
|
+
let didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)?.groups.content, matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
|
|
1139
|
+
context.report({
|
|
1140
|
+
loc,
|
|
1141
|
+
message: error.message,
|
|
1142
|
+
suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
|
|
1143
|
+
let { name } = match.groups;
|
|
1144
|
+
return {
|
|
1145
|
+
desc: `Rename to \`${name}\``,
|
|
1146
|
+
fix: (fixer) => fixer.replaceText(token, name)
|
|
1147
|
+
};
|
|
1148
|
+
}) : []
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
} catch (error) {
|
|
1152
|
+
context.report({
|
|
1153
|
+
loc: REPORT_ON_FIRST_CHARACTER,
|
|
1154
|
+
message: error.message
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
1159
|
+
let fragmentDefs = /* @__PURE__ */ new Set(), fragmentSpreads = /* @__PURE__ */ new Set();
|
|
1160
|
+
return visit3(node, {
|
|
1161
|
+
FragmentDefinition(node2) {
|
|
1162
|
+
fragmentDefs.add(node2.name.value);
|
|
1163
|
+
},
|
|
1164
|
+
FragmentSpread(node2) {
|
|
1165
|
+
fragmentSpreads.add(node2.name.value);
|
|
1166
|
+
}
|
|
1167
|
+
}), { fragmentDefs, fragmentSpreads };
|
|
1168
|
+
}, getMissingFragments = (node) => {
|
|
1169
|
+
let { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
|
1170
|
+
return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
|
|
1171
|
+
}, handleMissingFragments = ({ ruleId, context, node }) => {
|
|
1172
|
+
let missingFragments = getMissingFragments(node);
|
|
1173
|
+
if (missingFragments.length > 0) {
|
|
1174
|
+
let siblings = requireSiblingsOperations(ruleId, context), fragmentsToAdd = [];
|
|
1175
|
+
for (let fragmentName of missingFragments) {
|
|
1176
|
+
let [foundFragment] = siblings.getFragment(fragmentName).map((source) => source.document);
|
|
1177
|
+
foundFragment && fragmentsToAdd.push(foundFragment);
|
|
1178
|
+
}
|
|
1179
|
+
if (fragmentsToAdd.length > 0)
|
|
1180
|
+
return handleMissingFragments({
|
|
1181
|
+
ruleId,
|
|
1182
|
+
context,
|
|
1183
|
+
node: {
|
|
1184
|
+
kind: Kind5.DOCUMENT,
|
|
1185
|
+
definitions: [...node.definitions, ...fragmentsToAdd]
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
return node;
|
|
1190
|
+
}, validationToRule = ({
|
|
1191
|
+
ruleId,
|
|
1192
|
+
rule: rule35,
|
|
1193
|
+
getDocumentNode,
|
|
1194
|
+
schema: schema15 = [],
|
|
1195
|
+
hasDidYouMeanSuggestions
|
|
1196
|
+
}, docs) => ({
|
|
1197
|
+
[ruleId]: {
|
|
1198
|
+
meta: {
|
|
1199
|
+
docs: {
|
|
1200
|
+
recommended: !0,
|
|
1201
|
+
...docs,
|
|
1202
|
+
graphQLJSRuleName: rule35.name,
|
|
1203
|
+
url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
|
|
1204
|
+
description: `${docs.description}
|
|
1205
|
+
> This rule is a wrapper around a \`graphql-js\` validation function.`
|
|
1206
|
+
},
|
|
1207
|
+
schema: schema15,
|
|
1208
|
+
hasSuggestions: hasDidYouMeanSuggestions
|
|
1209
|
+
},
|
|
1210
|
+
create(context) {
|
|
1211
|
+
return {
|
|
1212
|
+
Document(node) {
|
|
1213
|
+
let schema16 = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null, documentNode = getDocumentNode ? getDocumentNode({ ruleId, context, node: node.rawNode() }) : node.rawNode();
|
|
1214
|
+
validateDocument({
|
|
1215
|
+
context,
|
|
1216
|
+
schema: schema16,
|
|
1217
|
+
documentNode,
|
|
1218
|
+
rule: rule35,
|
|
1219
|
+
hasDidYouMeanSuggestions
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}), GRAPHQL_JS_VALIDATIONS = Object.assign(
|
|
1226
|
+
{},
|
|
1227
|
+
validationToRule(
|
|
1228
|
+
{
|
|
1229
|
+
ruleId: "executable-definitions",
|
|
1230
|
+
rule: ExecutableDefinitionsRule
|
|
1231
|
+
},
|
|
1232
|
+
{
|
|
1233
|
+
category: "Operations",
|
|
1234
|
+
description: "A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.",
|
|
1235
|
+
requiresSchema: !0
|
|
1236
|
+
}
|
|
1237
|
+
),
|
|
1238
|
+
validationToRule(
|
|
1239
|
+
{
|
|
1240
|
+
ruleId: "fields-on-correct-type",
|
|
1241
|
+
rule: FieldsOnCorrectTypeRule,
|
|
1242
|
+
hasDidYouMeanSuggestions: !0
|
|
1243
|
+
},
|
|
1244
|
+
{
|
|
1245
|
+
category: "Operations",
|
|
1246
|
+
description: "A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.",
|
|
1247
|
+
requiresSchema: !0
|
|
1248
|
+
}
|
|
1249
|
+
),
|
|
1250
|
+
validationToRule(
|
|
1251
|
+
{
|
|
1252
|
+
ruleId: "fragments-on-composite-type",
|
|
1253
|
+
rule: FragmentsOnCompositeTypesRule
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
category: "Operations",
|
|
821
1257
|
description: "Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.",
|
|
822
1258
|
requiresSchema: !0
|
|
823
1259
|
}
|
|
@@ -1028,13 +1464,13 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
|
1028
1464
|
delete FilePathToDocumentsMap[currentFilePath];
|
|
1029
1465
|
for (let [filePath, documents] of Object.entries(FilePathToDocumentsMap))
|
|
1030
1466
|
if (getMissingFragments({
|
|
1031
|
-
kind:
|
|
1467
|
+
kind: Kind5.DOCUMENT,
|
|
1032
1468
|
definitions: documents
|
|
1033
1469
|
}).some(
|
|
1034
1470
|
(fragment) => fragmentDefs.has(fragment)
|
|
1035
1471
|
))
|
|
1036
1472
|
return getParentNode(filePath, {
|
|
1037
|
-
kind:
|
|
1473
|
+
kind: Kind5.DOCUMENT,
|
|
1038
1474
|
definitions: [...node2.definitions, ...documents]
|
|
1039
1475
|
});
|
|
1040
1476
|
return node2;
|
|
@@ -1051,580 +1487,206 @@ var getFragmentDefsAndFragmentSpreads = (node) => {
|
|
|
1051
1487
|
),
|
|
1052
1488
|
validationToRule(
|
|
1053
1489
|
{
|
|
1054
|
-
ruleId: "no-unused-variables",
|
|
1055
|
-
rule: NoUnusedVariablesRule,
|
|
1056
|
-
getDocumentNode: handleMissingFragments
|
|
1057
|
-
},
|
|
1058
|
-
{
|
|
1059
|
-
category: "Operations",
|
|
1060
|
-
description: "A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.",
|
|
1061
|
-
requiresSchema: !0,
|
|
1062
|
-
requiresSiblings: !0
|
|
1063
|
-
}
|
|
1064
|
-
),
|
|
1065
|
-
validationToRule(
|
|
1066
|
-
{
|
|
1067
|
-
ruleId: "overlapping-fields-can-be-merged",
|
|
1068
|
-
rule: OverlappingFieldsCanBeMergedRule
|
|
1069
|
-
},
|
|
1070
|
-
{
|
|
1071
|
-
category: "Operations",
|
|
1072
|
-
description: "A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.",
|
|
1073
|
-
requiresSchema: !0
|
|
1074
|
-
}
|
|
1075
|
-
),
|
|
1076
|
-
validationToRule(
|
|
1077
|
-
{
|
|
1078
|
-
ruleId: "possible-fragment-spread",
|
|
1079
|
-
rule: PossibleFragmentSpreadsRule
|
|
1080
|
-
},
|
|
1081
|
-
{
|
|
1082
|
-
category: "Operations",
|
|
1083
|
-
description: "A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.",
|
|
1084
|
-
requiresSchema: !0
|
|
1085
|
-
}
|
|
1086
|
-
),
|
|
1087
|
-
validationToRule(
|
|
1088
|
-
{
|
|
1089
|
-
ruleId: "possible-type-extension",
|
|
1090
|
-
rule: PossibleTypeExtensionsRule,
|
|
1091
|
-
hasDidYouMeanSuggestions: !0
|
|
1092
|
-
},
|
|
1093
|
-
{
|
|
1094
|
-
category: "Schema",
|
|
1095
|
-
description: "A type extension is only valid if the type is defined and has the same kind.",
|
|
1096
|
-
recommended: !0,
|
|
1097
|
-
requiresSchema: !0
|
|
1098
|
-
}
|
|
1099
|
-
),
|
|
1100
|
-
validationToRule(
|
|
1101
|
-
{
|
|
1102
|
-
ruleId: "provided-required-arguments",
|
|
1103
|
-
rule: ProvidedRequiredArgumentsRule
|
|
1104
|
-
},
|
|
1105
|
-
{
|
|
1106
|
-
category: ["Schema", "Operations"],
|
|
1107
|
-
description: "A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.",
|
|
1108
|
-
requiresSchema: !0
|
|
1109
|
-
}
|
|
1110
|
-
),
|
|
1111
|
-
validationToRule(
|
|
1112
|
-
{
|
|
1113
|
-
ruleId: "scalar-leafs",
|
|
1114
|
-
rule: ScalarLeafsRule,
|
|
1115
|
-
hasDidYouMeanSuggestions: !0
|
|
1116
|
-
},
|
|
1117
|
-
{
|
|
1118
|
-
category: "Operations",
|
|
1119
|
-
description: "A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.",
|
|
1120
|
-
requiresSchema: !0
|
|
1121
|
-
}
|
|
1122
|
-
),
|
|
1123
|
-
validationToRule(
|
|
1124
|
-
{
|
|
1125
|
-
ruleId: "one-field-subscriptions",
|
|
1126
|
-
rule: SingleFieldSubscriptionsRule
|
|
1127
|
-
},
|
|
1128
|
-
{
|
|
1129
|
-
category: "Operations",
|
|
1130
|
-
description: "A GraphQL subscription is valid only if it contains a single root field.",
|
|
1131
|
-
requiresSchema: !0
|
|
1132
|
-
}
|
|
1133
|
-
),
|
|
1134
|
-
validationToRule(
|
|
1135
|
-
{
|
|
1136
|
-
ruleId: "unique-argument-names",
|
|
1137
|
-
rule: UniqueArgumentNamesRule
|
|
1138
|
-
},
|
|
1139
|
-
{
|
|
1140
|
-
category: "Operations",
|
|
1141
|
-
description: "A GraphQL field or directive is only valid if all supplied arguments are uniquely named.",
|
|
1142
|
-
requiresSchema: !0
|
|
1143
|
-
}
|
|
1144
|
-
),
|
|
1145
|
-
validationToRule(
|
|
1146
|
-
{
|
|
1147
|
-
ruleId: "unique-directive-names",
|
|
1148
|
-
rule: UniqueDirectiveNamesRule
|
|
1149
|
-
},
|
|
1150
|
-
{
|
|
1151
|
-
category: "Schema",
|
|
1152
|
-
description: "A GraphQL document is only valid if all defined directives have unique names."
|
|
1153
|
-
}
|
|
1154
|
-
),
|
|
1155
|
-
validationToRule(
|
|
1156
|
-
{
|
|
1157
|
-
ruleId: "unique-directive-names-per-location",
|
|
1158
|
-
rule: UniqueDirectivesPerLocationRule
|
|
1490
|
+
ruleId: "no-unused-variables",
|
|
1491
|
+
rule: NoUnusedVariablesRule,
|
|
1492
|
+
getDocumentNode: handleMissingFragments
|
|
1159
1493
|
},
|
|
1160
1494
|
{
|
|
1161
|
-
category:
|
|
1162
|
-
description: "A GraphQL
|
|
1163
|
-
requiresSchema: !0
|
|
1495
|
+
category: "Operations",
|
|
1496
|
+
description: "A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.",
|
|
1497
|
+
requiresSchema: !0,
|
|
1498
|
+
requiresSiblings: !0
|
|
1164
1499
|
}
|
|
1165
1500
|
),
|
|
1166
1501
|
validationToRule(
|
|
1167
1502
|
{
|
|
1168
|
-
ruleId: "
|
|
1169
|
-
rule:
|
|
1503
|
+
ruleId: "overlapping-fields-can-be-merged",
|
|
1504
|
+
rule: OverlappingFieldsCanBeMergedRule
|
|
1170
1505
|
},
|
|
1171
1506
|
{
|
|
1172
|
-
category: "
|
|
1173
|
-
description: "A
|
|
1507
|
+
category: "Operations",
|
|
1508
|
+
description: "A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.",
|
|
1509
|
+
requiresSchema: !0
|
|
1174
1510
|
}
|
|
1175
1511
|
),
|
|
1176
1512
|
validationToRule(
|
|
1177
1513
|
{
|
|
1178
|
-
ruleId: "
|
|
1179
|
-
rule:
|
|
1514
|
+
ruleId: "possible-fragment-spread",
|
|
1515
|
+
rule: PossibleFragmentSpreadsRule
|
|
1180
1516
|
},
|
|
1181
1517
|
{
|
|
1182
1518
|
category: "Operations",
|
|
1183
|
-
description: "A
|
|
1519
|
+
description: "A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.",
|
|
1520
|
+
requiresSchema: !0
|
|
1184
1521
|
}
|
|
1185
1522
|
),
|
|
1186
1523
|
validationToRule(
|
|
1187
1524
|
{
|
|
1188
|
-
ruleId: "
|
|
1189
|
-
rule:
|
|
1525
|
+
ruleId: "possible-type-extension",
|
|
1526
|
+
rule: PossibleTypeExtensionsRule,
|
|
1527
|
+
hasDidYouMeanSuggestions: !0
|
|
1190
1528
|
},
|
|
1191
1529
|
{
|
|
1192
1530
|
category: "Schema",
|
|
1193
|
-
description: "A
|
|
1531
|
+
description: "A type extension is only valid if the type is defined and has the same kind.",
|
|
1532
|
+
recommended: !0,
|
|
1533
|
+
requiresSchema: !0
|
|
1194
1534
|
}
|
|
1195
1535
|
),
|
|
1196
1536
|
validationToRule(
|
|
1197
1537
|
{
|
|
1198
|
-
ruleId: "
|
|
1199
|
-
rule:
|
|
1538
|
+
ruleId: "provided-required-arguments",
|
|
1539
|
+
rule: ProvidedRequiredArgumentsRule
|
|
1200
1540
|
},
|
|
1201
1541
|
{
|
|
1202
|
-
category: "Schema",
|
|
1203
|
-
description: "A
|
|
1542
|
+
category: ["Schema", "Operations"],
|
|
1543
|
+
description: "A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.",
|
|
1544
|
+
requiresSchema: !0
|
|
1204
1545
|
}
|
|
1205
1546
|
),
|
|
1206
1547
|
validationToRule(
|
|
1207
1548
|
{
|
|
1208
|
-
ruleId: "
|
|
1209
|
-
rule:
|
|
1549
|
+
ruleId: "scalar-leafs",
|
|
1550
|
+
rule: ScalarLeafsRule,
|
|
1551
|
+
hasDidYouMeanSuggestions: !0
|
|
1210
1552
|
},
|
|
1211
1553
|
{
|
|
1212
1554
|
category: "Operations",
|
|
1213
|
-
description: "A GraphQL
|
|
1555
|
+
description: "A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.",
|
|
1214
1556
|
requiresSchema: !0
|
|
1215
1557
|
}
|
|
1216
1558
|
),
|
|
1217
1559
|
validationToRule(
|
|
1218
1560
|
{
|
|
1219
|
-
ruleId: "
|
|
1220
|
-
rule:
|
|
1221
|
-
hasDidYouMeanSuggestions: !0
|
|
1561
|
+
ruleId: "one-field-subscriptions",
|
|
1562
|
+
rule: SingleFieldSubscriptionsRule
|
|
1222
1563
|
},
|
|
1223
1564
|
{
|
|
1224
1565
|
category: "Operations",
|
|
1225
|
-
description: "A GraphQL
|
|
1566
|
+
description: "A GraphQL subscription is valid only if it contains a single root field.",
|
|
1226
1567
|
requiresSchema: !0
|
|
1227
1568
|
}
|
|
1228
1569
|
),
|
|
1229
1570
|
validationToRule(
|
|
1230
1571
|
{
|
|
1231
|
-
ruleId: "
|
|
1232
|
-
rule:
|
|
1572
|
+
ruleId: "unique-argument-names",
|
|
1573
|
+
rule: UniqueArgumentNamesRule
|
|
1233
1574
|
},
|
|
1234
1575
|
{
|
|
1235
1576
|
category: "Operations",
|
|
1236
|
-
description: "A GraphQL
|
|
1577
|
+
description: "A GraphQL field or directive is only valid if all supplied arguments are uniquely named.",
|
|
1237
1578
|
requiresSchema: !0
|
|
1238
1579
|
}
|
|
1239
1580
|
),
|
|
1240
1581
|
validationToRule(
|
|
1241
1582
|
{
|
|
1242
|
-
ruleId: "
|
|
1243
|
-
rule:
|
|
1583
|
+
ruleId: "unique-directive-names",
|
|
1584
|
+
rule: UniqueDirectiveNamesRule
|
|
1244
1585
|
},
|
|
1245
1586
|
{
|
|
1246
|
-
category: "
|
|
1247
|
-
description: "
|
|
1248
|
-
requiresSchema: !0
|
|
1249
|
-
}
|
|
1250
|
-
)
|
|
1251
|
-
);
|
|
1252
|
-
|
|
1253
|
-
// src/rules/alphabetize.ts
|
|
1254
|
-
import {
|
|
1255
|
-
Kind as Kind5
|
|
1256
|
-
} from "graphql";
|
|
1257
|
-
import lowerCase2 from "lodash.lowercase";
|
|
1258
|
-
var RULE_ID = "alphabetize", fieldsEnum = [
|
|
1259
|
-
Kind5.OBJECT_TYPE_DEFINITION,
|
|
1260
|
-
Kind5.INTERFACE_TYPE_DEFINITION,
|
|
1261
|
-
Kind5.INPUT_OBJECT_TYPE_DEFINITION
|
|
1262
|
-
], selectionsEnum = [
|
|
1263
|
-
Kind5.OPERATION_DEFINITION,
|
|
1264
|
-
Kind5.FRAGMENT_DEFINITION
|
|
1265
|
-
], argumentsEnum = [
|
|
1266
|
-
Kind5.FIELD_DEFINITION,
|
|
1267
|
-
Kind5.FIELD,
|
|
1268
|
-
Kind5.DIRECTIVE_DEFINITION,
|
|
1269
|
-
Kind5.DIRECTIVE
|
|
1270
|
-
], schema = {
|
|
1271
|
-
type: "array",
|
|
1272
|
-
minItems: 1,
|
|
1273
|
-
maxItems: 1,
|
|
1274
|
-
items: {
|
|
1275
|
-
type: "object",
|
|
1276
|
-
additionalProperties: !1,
|
|
1277
|
-
minProperties: 1,
|
|
1278
|
-
properties: {
|
|
1279
|
-
fields: {
|
|
1280
|
-
...ARRAY_DEFAULT_OPTIONS,
|
|
1281
|
-
items: {
|
|
1282
|
-
enum: fieldsEnum
|
|
1283
|
-
},
|
|
1284
|
-
description: "Fields of `type`, `interface`, and `input`."
|
|
1285
|
-
},
|
|
1286
|
-
values: {
|
|
1287
|
-
type: "boolean",
|
|
1288
|
-
description: "Values of `enum`."
|
|
1289
|
-
},
|
|
1290
|
-
selections: {
|
|
1291
|
-
...ARRAY_DEFAULT_OPTIONS,
|
|
1292
|
-
items: {
|
|
1293
|
-
enum: selectionsEnum
|
|
1294
|
-
},
|
|
1295
|
-
description: "Selections of `fragment` and operations `query`, `mutation` and `subscription`."
|
|
1296
|
-
},
|
|
1297
|
-
variables: {
|
|
1298
|
-
type: "boolean",
|
|
1299
|
-
description: "Variables of operations `query`, `mutation` and `subscription`."
|
|
1300
|
-
},
|
|
1301
|
-
arguments: {
|
|
1302
|
-
...ARRAY_DEFAULT_OPTIONS,
|
|
1303
|
-
items: {
|
|
1304
|
-
enum: argumentsEnum
|
|
1305
|
-
},
|
|
1306
|
-
description: "Arguments of fields and directives."
|
|
1307
|
-
},
|
|
1308
|
-
definitions: {
|
|
1309
|
-
type: "boolean",
|
|
1310
|
-
description: "Definitions \u2013 `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`."
|
|
1311
|
-
},
|
|
1312
|
-
groups: {
|
|
1313
|
-
...ARRAY_DEFAULT_OPTIONS,
|
|
1314
|
-
minItems: 2,
|
|
1315
|
-
description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
|
|
1316
|
-
}
|
|
1587
|
+
category: "Schema",
|
|
1588
|
+
description: "A GraphQL document is only valid if all defined directives have unique names."
|
|
1317
1589
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1590
|
+
),
|
|
1591
|
+
validationToRule(
|
|
1592
|
+
{
|
|
1593
|
+
ruleId: "unique-directive-names-per-location",
|
|
1594
|
+
rule: UniqueDirectivesPerLocationRule
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1324
1597
|
category: ["Schema", "Operations"],
|
|
1325
|
-
description: "
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
`
|
|
1334
|
-
type User {
|
|
1335
|
-
password: String
|
|
1336
|
-
firstName: String! # should be before "password"
|
|
1337
|
-
age: Int # should be before "firstName"
|
|
1338
|
-
lastName: String!
|
|
1339
|
-
}
|
|
1340
|
-
`
|
|
1341
|
-
)
|
|
1342
|
-
},
|
|
1343
|
-
{
|
|
1344
|
-
title: "Correct",
|
|
1345
|
-
usage: [{ fields: [Kind5.OBJECT_TYPE_DEFINITION] }],
|
|
1346
|
-
code: (
|
|
1347
|
-
/* GraphQL */
|
|
1348
|
-
`
|
|
1349
|
-
type User {
|
|
1350
|
-
age: Int
|
|
1351
|
-
firstName: String!
|
|
1352
|
-
lastName: String!
|
|
1353
|
-
password: String
|
|
1354
|
-
}
|
|
1355
|
-
`
|
|
1356
|
-
)
|
|
1357
|
-
},
|
|
1358
|
-
{
|
|
1359
|
-
title: "Incorrect",
|
|
1360
|
-
usage: [{ values: !0 }],
|
|
1361
|
-
code: (
|
|
1362
|
-
/* GraphQL */
|
|
1363
|
-
`
|
|
1364
|
-
enum Role {
|
|
1365
|
-
SUPER_ADMIN
|
|
1366
|
-
ADMIN # should be before "SUPER_ADMIN"
|
|
1367
|
-
USER
|
|
1368
|
-
GOD # should be before "USER"
|
|
1369
|
-
}
|
|
1370
|
-
`
|
|
1371
|
-
)
|
|
1372
|
-
},
|
|
1373
|
-
{
|
|
1374
|
-
title: "Correct",
|
|
1375
|
-
usage: [{ values: !0 }],
|
|
1376
|
-
code: (
|
|
1377
|
-
/* GraphQL */
|
|
1378
|
-
`
|
|
1379
|
-
enum Role {
|
|
1380
|
-
ADMIN
|
|
1381
|
-
GOD
|
|
1382
|
-
SUPER_ADMIN
|
|
1383
|
-
USER
|
|
1384
|
-
}
|
|
1385
|
-
`
|
|
1386
|
-
)
|
|
1387
|
-
},
|
|
1388
|
-
{
|
|
1389
|
-
title: "Incorrect",
|
|
1390
|
-
usage: [{ selections: [Kind5.OPERATION_DEFINITION] }],
|
|
1391
|
-
code: (
|
|
1392
|
-
/* GraphQL */
|
|
1393
|
-
`
|
|
1394
|
-
query {
|
|
1395
|
-
me {
|
|
1396
|
-
firstName
|
|
1397
|
-
lastName
|
|
1398
|
-
email # should be before "lastName"
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
`
|
|
1402
|
-
)
|
|
1403
|
-
},
|
|
1404
|
-
{
|
|
1405
|
-
title: "Correct",
|
|
1406
|
-
usage: [{ selections: [Kind5.OPERATION_DEFINITION] }],
|
|
1407
|
-
code: (
|
|
1408
|
-
/* GraphQL */
|
|
1409
|
-
`
|
|
1410
|
-
query {
|
|
1411
|
-
me {
|
|
1412
|
-
email
|
|
1413
|
-
firstName
|
|
1414
|
-
lastName
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
`
|
|
1418
|
-
)
|
|
1419
|
-
}
|
|
1420
|
-
],
|
|
1421
|
-
configOptions: {
|
|
1422
|
-
schema: [
|
|
1423
|
-
{
|
|
1424
|
-
definitions: !0,
|
|
1425
|
-
fields: fieldsEnum,
|
|
1426
|
-
values: !0,
|
|
1427
|
-
arguments: argumentsEnum,
|
|
1428
|
-
groups: ["id", "*", "createdAt", "updatedAt"]
|
|
1429
|
-
}
|
|
1430
|
-
],
|
|
1431
|
-
operations: [
|
|
1432
|
-
{
|
|
1433
|
-
definitions: !0,
|
|
1434
|
-
selections: selectionsEnum,
|
|
1435
|
-
variables: !0,
|
|
1436
|
-
arguments: [Kind5.FIELD, Kind5.DIRECTIVE],
|
|
1437
|
-
groups: ["id", "*", "createdAt", "updatedAt"]
|
|
1438
|
-
}
|
|
1439
|
-
]
|
|
1440
|
-
}
|
|
1598
|
+
description: "A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.",
|
|
1599
|
+
requiresSchema: !0
|
|
1600
|
+
}
|
|
1601
|
+
),
|
|
1602
|
+
validationToRule(
|
|
1603
|
+
{
|
|
1604
|
+
ruleId: "unique-field-definition-names",
|
|
1605
|
+
rule: UniqueFieldDefinitionNamesRule
|
|
1441
1606
|
},
|
|
1442
|
-
|
|
1443
|
-
|
|
1607
|
+
{
|
|
1608
|
+
category: "Schema",
|
|
1609
|
+
description: "A GraphQL complex type is only valid if all its fields are uniquely named."
|
|
1610
|
+
}
|
|
1611
|
+
),
|
|
1612
|
+
validationToRule(
|
|
1613
|
+
{
|
|
1614
|
+
ruleId: "unique-input-field-names",
|
|
1615
|
+
rule: UniqueInputFieldNamesRule
|
|
1444
1616
|
},
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
let sourceCode = context.getSourceCode();
|
|
1449
|
-
function isNodeAndCommentOnSameLine(node, comment) {
|
|
1450
|
-
return node.loc.end.line === comment.loc.start.line;
|
|
1617
|
+
{
|
|
1618
|
+
category: "Operations",
|
|
1619
|
+
description: "A GraphQL input object value is only valid if all supplied fields are uniquely named."
|
|
1451
1620
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
let comment = commentsBefore[i];
|
|
1462
|
-
if (nodeLine - comment.loc.start.line - filteredComments.length > 1)
|
|
1463
|
-
break;
|
|
1464
|
-
filteredComments.unshift(comment);
|
|
1465
|
-
}
|
|
1466
|
-
return filteredComments;
|
|
1621
|
+
),
|
|
1622
|
+
validationToRule(
|
|
1623
|
+
{
|
|
1624
|
+
ruleId: "unique-operation-types",
|
|
1625
|
+
rule: UniqueOperationTypesRule
|
|
1626
|
+
},
|
|
1627
|
+
{
|
|
1628
|
+
category: "Schema",
|
|
1629
|
+
description: "A GraphQL document is only valid if it has only one type per operation."
|
|
1467
1630
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1631
|
+
),
|
|
1632
|
+
validationToRule(
|
|
1633
|
+
{
|
|
1634
|
+
ruleId: "unique-type-names",
|
|
1635
|
+
rule: UniqueTypeNamesRule
|
|
1636
|
+
},
|
|
1637
|
+
{
|
|
1638
|
+
category: "Schema",
|
|
1639
|
+
description: "A GraphQL document is only valid if all defined types have unique names."
|
|
1472
1640
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
throw new Error("`groups` option should contain `*` string.");
|
|
1484
|
-
let indexForPrev = groups.indexOf(prevName);
|
|
1485
|
-
indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
|
|
1486
|
-
let indexForCurr = groups.indexOf(currName);
|
|
1487
|
-
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
|
1488
|
-
continue;
|
|
1489
|
-
}
|
|
1490
|
-
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
|
1491
|
-
continue;
|
|
1492
|
-
}
|
|
1493
|
-
context.report({
|
|
1494
|
-
// @ts-expect-error can't be undefined
|
|
1495
|
-
node: "alias" in currNode && currNode.alias || currNode.name,
|
|
1496
|
-
messageId: RULE_ID,
|
|
1497
|
-
data: {
|
|
1498
|
-
currNode: displayNodeName(currNode),
|
|
1499
|
-
prevNode: prevName ? displayNodeName(prevNode) : lowerCase2(prevNode.kind)
|
|
1500
|
-
},
|
|
1501
|
-
*fix(fixer) {
|
|
1502
|
-
let prevRange = getRangeWithComments(prevNode), currRange = getRangeWithComments(currNode);
|
|
1503
|
-
yield fixer.replaceTextRange(
|
|
1504
|
-
prevRange,
|
|
1505
|
-
sourceCode.getText({ range: currRange })
|
|
1506
|
-
), yield fixer.replaceTextRange(
|
|
1507
|
-
currRange,
|
|
1508
|
-
sourceCode.getText({ range: prevRange })
|
|
1509
|
-
);
|
|
1510
|
-
}
|
|
1511
|
-
});
|
|
1512
|
-
}
|
|
1641
|
+
),
|
|
1642
|
+
validationToRule(
|
|
1643
|
+
{
|
|
1644
|
+
ruleId: "unique-variable-names",
|
|
1645
|
+
rule: UniqueVariableNamesRule
|
|
1646
|
+
},
|
|
1647
|
+
{
|
|
1648
|
+
category: "Operations",
|
|
1649
|
+
description: "A GraphQL operation is only valid if all its variables are uniquely named.",
|
|
1650
|
+
requiresSchema: !0
|
|
1513
1651
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
Kind5.INPUT_OBJECT_TYPE_EXTENSION
|
|
1526
|
-
]
|
|
1527
|
-
].filter(truthy).flat().join(","), selectionsSelector = opts.selections?.join(","), argumentsSelector = opts.arguments?.join(",");
|
|
1528
|
-
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
|
1529
|
-
checkNodes(node.fields);
|
|
1530
|
-
}), opts.values) {
|
|
1531
|
-
let enumValuesSelector = [Kind5.ENUM_TYPE_DEFINITION, Kind5.ENUM_TYPE_EXTENSION].join(",");
|
|
1532
|
-
listeners[enumValuesSelector] = (node) => {
|
|
1533
|
-
checkNodes(node.values);
|
|
1534
|
-
};
|
|
1652
|
+
),
|
|
1653
|
+
validationToRule(
|
|
1654
|
+
{
|
|
1655
|
+
ruleId: "value-literals-of-correct-type",
|
|
1656
|
+
rule: ValuesOfCorrectTypeRule,
|
|
1657
|
+
hasDidYouMeanSuggestions: !0
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
category: "Operations",
|
|
1661
|
+
description: "A GraphQL document is only valid if all value literals are of the type expected at their position.",
|
|
1662
|
+
requiresSchema: !0
|
|
1535
1663
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
};
|
|
1547
|
-
|
|
1548
|
-
// src/rules/description-style.ts
|
|
1549
|
-
var schema2 = {
|
|
1550
|
-
type: "array",
|
|
1551
|
-
maxItems: 1,
|
|
1552
|
-
items: {
|
|
1553
|
-
type: "object",
|
|
1554
|
-
additionalProperties: !1,
|
|
1555
|
-
minProperties: 1,
|
|
1556
|
-
properties: {
|
|
1557
|
-
style: {
|
|
1558
|
-
enum: ["block", "inline"],
|
|
1559
|
-
default: "block"
|
|
1560
|
-
}
|
|
1664
|
+
),
|
|
1665
|
+
validationToRule(
|
|
1666
|
+
{
|
|
1667
|
+
ruleId: "variables-are-input-types",
|
|
1668
|
+
rule: VariablesAreInputTypesRule
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
category: "Operations",
|
|
1672
|
+
description: "A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).",
|
|
1673
|
+
requiresSchema: !0
|
|
1561
1674
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
docs: {
|
|
1568
|
-
examples: [
|
|
1569
|
-
{
|
|
1570
|
-
title: "Incorrect",
|
|
1571
|
-
usage: [{ style: "inline" }],
|
|
1572
|
-
code: (
|
|
1573
|
-
/* GraphQL */
|
|
1574
|
-
`
|
|
1575
|
-
""" Description """
|
|
1576
|
-
type someTypeName {
|
|
1577
|
-
# ...
|
|
1578
|
-
}
|
|
1579
|
-
`
|
|
1580
|
-
)
|
|
1581
|
-
},
|
|
1582
|
-
{
|
|
1583
|
-
title: "Correct",
|
|
1584
|
-
usage: [{ style: "inline" }],
|
|
1585
|
-
code: (
|
|
1586
|
-
/* GraphQL */
|
|
1587
|
-
`
|
|
1588
|
-
" Description "
|
|
1589
|
-
type someTypeName {
|
|
1590
|
-
# ...
|
|
1591
|
-
}
|
|
1592
|
-
`
|
|
1593
|
-
)
|
|
1594
|
-
}
|
|
1595
|
-
],
|
|
1596
|
-
description: "Require all comments to follow the same style (either block or inline).",
|
|
1597
|
-
category: "Schema",
|
|
1598
|
-
url: "https://the-guild.dev/graphql/eslint/rules/description-style",
|
|
1599
|
-
recommended: !0
|
|
1675
|
+
),
|
|
1676
|
+
validationToRule(
|
|
1677
|
+
{
|
|
1678
|
+
ruleId: "variables-in-allowed-position",
|
|
1679
|
+
rule: VariablesInAllowedPositionRule
|
|
1600
1680
|
},
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
loc: isBlock ? node.loc : node.loc.start,
|
|
1609
|
-
message: `Unexpected ${isBlock ? "inline" : "block"} description for ${getNodeName(
|
|
1610
|
-
node.parent
|
|
1611
|
-
)}`,
|
|
1612
|
-
suggest: [
|
|
1613
|
-
{
|
|
1614
|
-
desc: `Change to ${isBlock ? "block" : "inline"} style description`,
|
|
1615
|
-
fix(fixer) {
|
|
1616
|
-
let originalText = context.getSourceCode().getText(node), newText = isBlock ? originalText.replace(/(^")|("$)/g, '"""') : originalText.replace(/(^""")|("""$)/g, '"').replace(/\s+/g, " ");
|
|
1617
|
-
return fixer.replaceText(node, newText);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
]
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
};
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1681
|
+
{
|
|
1682
|
+
category: "Operations",
|
|
1683
|
+
description: "Variables passed to field arguments conform to type.",
|
|
1684
|
+
requiresSchema: !0
|
|
1685
|
+
}
|
|
1686
|
+
)
|
|
1687
|
+
);
|
|
1626
1688
|
|
|
1627
|
-
// src/rules/input-name.ts
|
|
1689
|
+
// src/rules/input-name/index.ts
|
|
1628
1690
|
import {
|
|
1629
1691
|
Kind as Kind6
|
|
1630
1692
|
} from "graphql";
|
|
@@ -1758,7 +1820,7 @@ Using the same name for all input parameters will make your schemas easier to co
|
|
|
1758
1820
|
}
|
|
1759
1821
|
};
|
|
1760
1822
|
|
|
1761
|
-
// src/rules/lone-executable-definition.ts
|
|
1823
|
+
// src/rules/lone-executable-definition/index.ts
|
|
1762
1824
|
import { OperationTypeNode as OperationTypeNode2 } from "graphql";
|
|
1763
1825
|
var RULE_ID2 = "lone-executable-definition", definitionTypes = ["fragment", ...Object.values(OperationTypeNode2)], schema4 = {
|
|
1764
1826
|
type: "array",
|
|
@@ -1840,8 +1902,8 @@ var RULE_ID2 = "lone-executable-definition", definitionTypes = ["fragment", ...O
|
|
|
1840
1902
|
}
|
|
1841
1903
|
};
|
|
1842
1904
|
|
|
1843
|
-
// src/rules/match-document-filename.ts
|
|
1844
|
-
import { basename, extname } from "path";
|
|
1905
|
+
// src/rules/match-document-filename/index.ts
|
|
1906
|
+
import { basename, extname } from "node:path";
|
|
1845
1907
|
import { Kind as Kind7 } from "graphql";
|
|
1846
1908
|
var MATCH_EXTENSION = "MATCH_EXTENSION", MATCH_STYLE = "MATCH_STYLE", CASE_STYLES = [
|
|
1847
1909
|
"camelCase",
|
|
@@ -2068,7 +2130,7 @@ var MATCH_EXTENSION = "MATCH_EXTENSION", MATCH_STYLE = "MATCH_STYLE", CASE_STYLE
|
|
|
2068
2130
|
}
|
|
2069
2131
|
};
|
|
2070
2132
|
|
|
2071
|
-
// src/rules/naming-convention.ts
|
|
2133
|
+
// src/rules/naming-convention/index.ts
|
|
2072
2134
|
import { Kind as Kind8 } from "graphql";
|
|
2073
2135
|
var KindToDisplayName = {
|
|
2074
2136
|
// types
|
|
@@ -2462,7 +2524,7 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
|
|
|
2462
2524
|
}
|
|
2463
2525
|
};
|
|
2464
2526
|
|
|
2465
|
-
// src/rules/no-anonymous-operations.ts
|
|
2527
|
+
// src/rules/no-anonymous-operations/index.ts
|
|
2466
2528
|
import { Kind as Kind9 } from "graphql";
|
|
2467
2529
|
var RULE_ID3 = "no-anonymous-operations", rule7 = {
|
|
2468
2530
|
meta: {
|
|
@@ -2531,7 +2593,7 @@ var RULE_ID3 = "no-anonymous-operations", rule7 = {
|
|
|
2531
2593
|
}
|
|
2532
2594
|
};
|
|
2533
2595
|
|
|
2534
|
-
// src/rules/no-deprecated.ts
|
|
2596
|
+
// src/rules/no-deprecated/index.ts
|
|
2535
2597
|
import { Kind as Kind10 } from "graphql";
|
|
2536
2598
|
var RULE_ID4 = "no-deprecated", rule8 = {
|
|
2537
2599
|
meta: {
|
|
@@ -2652,7 +2714,7 @@ var RULE_ID4 = "no-deprecated", rule8 = {
|
|
|
2652
2714
|
}
|
|
2653
2715
|
};
|
|
2654
2716
|
|
|
2655
|
-
// src/rules/no-duplicate-fields.ts
|
|
2717
|
+
// src/rules/no-duplicate-fields/index.ts
|
|
2656
2718
|
import { Kind as Kind11 } from "graphql";
|
|
2657
2719
|
var RULE_ID5 = "no-duplicate-fields", rule9 = {
|
|
2658
2720
|
meta: {
|
|
@@ -2766,7 +2828,7 @@ var RULE_ID5 = "no-duplicate-fields", rule9 = {
|
|
|
2766
2828
|
}
|
|
2767
2829
|
};
|
|
2768
2830
|
|
|
2769
|
-
// src/rules/no-hashtag-description.ts
|
|
2831
|
+
// src/rules/no-hashtag-description/index.ts
|
|
2770
2832
|
import { TokenKind as TokenKind2 } from "graphql";
|
|
2771
2833
|
var RULE_ID6 = "HASHTAG_COMMENT", rule10 = {
|
|
2772
2834
|
meta: {
|
|
@@ -2869,8 +2931,8 @@ var RULE_ID6 = "HASHTAG_COMMENT", rule10 = {
|
|
|
2869
2931
|
}
|
|
2870
2932
|
};
|
|
2871
2933
|
|
|
2872
|
-
// src/rules/no-one-place-fragments.ts
|
|
2873
|
-
import { relative } from "path";
|
|
2934
|
+
// src/rules/no-one-place-fragments/index.ts
|
|
2935
|
+
import { relative } from "node:path";
|
|
2874
2936
|
import { visit as visit4 } from "graphql";
|
|
2875
2937
|
var RULE_ID7 = "no-one-place-fragments", rule11 = {
|
|
2876
2938
|
meta: {
|
|
@@ -2949,7 +3011,7 @@ var RULE_ID7 = "no-one-place-fragments", rule11 = {
|
|
|
2949
3011
|
}
|
|
2950
3012
|
};
|
|
2951
3013
|
|
|
2952
|
-
// src/rules/no-root-type.ts
|
|
3014
|
+
// src/rules/no-root-type/index.ts
|
|
2953
3015
|
var schema7 = {
|
|
2954
3016
|
type: "array",
|
|
2955
3017
|
minItems: 1,
|
|
@@ -3029,7 +3091,7 @@ var schema7 = {
|
|
|
3029
3091
|
}
|
|
3030
3092
|
};
|
|
3031
3093
|
|
|
3032
|
-
// src/rules/no-scalar-result-type-on-mutation.ts
|
|
3094
|
+
// src/rules/no-scalar-result-type-on-mutation/index.ts
|
|
3033
3095
|
import { isScalarType, Kind as Kind12 } from "graphql";
|
|
3034
3096
|
var RULE_ID8 = "no-scalar-result-type-on-mutation", rule13 = {
|
|
3035
3097
|
meta: {
|
|
@@ -3095,7 +3157,7 @@ var RULE_ID8 = "no-scalar-result-type-on-mutation", rule13 = {
|
|
|
3095
3157
|
}
|
|
3096
3158
|
};
|
|
3097
3159
|
|
|
3098
|
-
// src/rules/no-typename-prefix.ts
|
|
3160
|
+
// src/rules/no-typename-prefix/index.ts
|
|
3099
3161
|
var NO_TYPENAME_PREFIX = "NO_TYPENAME_PREFIX", rule14 = {
|
|
3100
3162
|
meta: {
|
|
3101
3163
|
type: "suggestion",
|
|
@@ -3164,7 +3226,7 @@ var NO_TYPENAME_PREFIX = "NO_TYPENAME_PREFIX", rule14 = {
|
|
|
3164
3226
|
}
|
|
3165
3227
|
};
|
|
3166
3228
|
|
|
3167
|
-
// src/rules/no-unreachable-types.ts
|
|
3229
|
+
// src/rules/no-unreachable-types/index.ts
|
|
3168
3230
|
import {
|
|
3169
3231
|
DirectiveLocation,
|
|
3170
3232
|
isInterfaceType,
|
|
@@ -3186,7 +3248,7 @@ var RULE_ID9 = "no-unreachable-types", KINDS = [
|
|
|
3186
3248
|
Kind13.UNION_TYPE_EXTENSION,
|
|
3187
3249
|
Kind13.ENUM_TYPE_DEFINITION,
|
|
3188
3250
|
Kind13.ENUM_TYPE_EXTENSION
|
|
3189
|
-
], reachableTypesCache, RequestDirectiveLocations = /* @__PURE__ */ new Set([
|
|
3251
|
+
], reachableTypesCache = new ModuleCache(), RequestDirectiveLocations = /* @__PURE__ */ new Set([
|
|
3190
3252
|
DirectiveLocation.QUERY,
|
|
3191
3253
|
DirectiveLocation.MUTATION,
|
|
3192
3254
|
DirectiveLocation.SUBSCRIPTION,
|
|
@@ -3197,8 +3259,9 @@ var RULE_ID9 = "no-unreachable-types", KINDS = [
|
|
|
3197
3259
|
DirectiveLocation.VARIABLE_DEFINITION
|
|
3198
3260
|
]);
|
|
3199
3261
|
function getReachableTypes(schema15) {
|
|
3200
|
-
|
|
3201
|
-
|
|
3262
|
+
let cachedValue = reachableTypesCache.get(schema15);
|
|
3263
|
+
if (cachedValue)
|
|
3264
|
+
return cachedValue;
|
|
3202
3265
|
let reachableTypes = /* @__PURE__ */ new Set(), collect = (node) => {
|
|
3203
3266
|
let typeName = getTypeName(node);
|
|
3204
3267
|
if (reachableTypes.has(typeName))
|
|
@@ -3209,8 +3272,7 @@ function getReachableTypes(schema15) {
|
|
|
3209
3272
|
let { objects, interfaces } = schema15.getImplementations(type);
|
|
3210
3273
|
for (let { astNode } of [...objects, ...interfaces])
|
|
3211
3274
|
visit5(astNode, visitor);
|
|
3212
|
-
} else
|
|
3213
|
-
type?.astNode && visit5(type.astNode, visitor);
|
|
3275
|
+
} else type?.astNode && visit5(type.astNode, visitor);
|
|
3214
3276
|
}, visitor = {
|
|
3215
3277
|
InterfaceTypeDefinition: collect,
|
|
3216
3278
|
ObjectTypeDefinition: collect,
|
|
@@ -3236,7 +3298,7 @@ function getReachableTypes(schema15) {
|
|
|
3236
3298
|
argTypeName && reachableTypes.add(argTypeName);
|
|
3237
3299
|
}
|
|
3238
3300
|
}
|
|
3239
|
-
return reachableTypesCache
|
|
3301
|
+
return reachableTypesCache.set(schema15, reachableTypes), reachableTypes;
|
|
3240
3302
|
}
|
|
3241
3303
|
var rule15 = {
|
|
3242
3304
|
meta: {
|
|
@@ -3315,12 +3377,13 @@ var rule15 = {
|
|
|
3315
3377
|
}
|
|
3316
3378
|
};
|
|
3317
3379
|
|
|
3318
|
-
// src/rules/no-unused-fields.ts
|
|
3380
|
+
// src/rules/no-unused-fields/index.ts
|
|
3319
3381
|
import { TypeInfo as TypeInfo2, visit as visit6, visitWithTypeInfo as visitWithTypeInfo2 } from "graphql";
|
|
3320
|
-
var RULE_ID10 = "no-unused-fields", usedFieldsCache;
|
|
3382
|
+
var RULE_ID10 = "no-unused-fields", usedFieldsCache = new ModuleCache();
|
|
3321
3383
|
function getUsedFields(schema15, operations) {
|
|
3322
|
-
|
|
3323
|
-
|
|
3384
|
+
let cachedValue = usedFieldsCache.get(schema15);
|
|
3385
|
+
if (cachedValue)
|
|
3386
|
+
return cachedValue;
|
|
3324
3387
|
let usedFields = /* @__PURE__ */ Object.create(null), typeInfo = new TypeInfo2(schema15), visitor = visitWithTypeInfo2(typeInfo, {
|
|
3325
3388
|
Field(node) {
|
|
3326
3389
|
if (!typeInfo.getFieldDef())
|
|
@@ -3331,7 +3394,7 @@ function getUsedFields(schema15, operations) {
|
|
|
3331
3394
|
}), allDocuments = [...operations.getOperations(), ...operations.getFragments()];
|
|
3332
3395
|
for (let { document } of allDocuments)
|
|
3333
3396
|
visit6(document, visitor);
|
|
3334
|
-
return usedFieldsCache
|
|
3397
|
+
return usedFieldsCache.set(schema15, usedFields), usedFields;
|
|
3335
3398
|
}
|
|
3336
3399
|
var rule16 = {
|
|
3337
3400
|
meta: {
|
|
@@ -3424,7 +3487,7 @@ var rule16 = {
|
|
|
3424
3487
|
}
|
|
3425
3488
|
};
|
|
3426
3489
|
|
|
3427
|
-
// src/rules/relay-arguments.ts
|
|
3490
|
+
// src/rules/relay-arguments/index.ts
|
|
3428
3491
|
import { isScalarType as isScalarType2, Kind as Kind14 } from "graphql";
|
|
3429
3492
|
var RULE_ID11 = "relay-arguments", MISSING_ARGUMENTS = "MISSING_ARGUMENTS", schema8 = {
|
|
3430
3493
|
type: "array",
|
|
@@ -3527,7 +3590,7 @@ var RULE_ID11 = "relay-arguments", MISSING_ARGUMENTS = "MISSING_ARGUMENTS", sche
|
|
|
3527
3590
|
}
|
|
3528
3591
|
};
|
|
3529
3592
|
|
|
3530
|
-
// src/rules/relay-connection-types.ts
|
|
3593
|
+
// src/rules/relay-connection-types/index.ts
|
|
3531
3594
|
import { Kind as Kind15 } from "graphql";
|
|
3532
3595
|
var 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 = [
|
|
3533
3596
|
Kind15.SCALAR_TYPE_DEFINITION,
|
|
@@ -3614,14 +3677,14 @@ var MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE", MUST_CONTAIN_FIELD_EDGES = "MUS
|
|
|
3614
3677
|
}
|
|
3615
3678
|
};
|
|
3616
3679
|
|
|
3617
|
-
// src/rules/relay-edge-types.ts
|
|
3618
|
-
import { getDocumentNodeFromSchema } from "@graphql-tools/utils";
|
|
3680
|
+
// src/rules/relay-edge-types/index.ts
|
|
3619
3681
|
import {
|
|
3620
3682
|
isObjectType as isObjectType2,
|
|
3621
3683
|
isScalarType as isScalarType3,
|
|
3622
3684
|
Kind as Kind16,
|
|
3623
3685
|
visit as visit7
|
|
3624
3686
|
} from "graphql";
|
|
3687
|
+
import { getDocumentNodeFromSchema } from "@graphql-tools/utils";
|
|
3625
3688
|
var RULE_ID12 = "relay-edge-types", MESSAGE_MUST_BE_OBJECT_TYPE = "MESSAGE_MUST_BE_OBJECT_TYPE", MESSAGE_MISSING_EDGE_SUFFIX = "MESSAGE_MISSING_EDGE_SUFFIX", MESSAGE_LIST_TYPE_ONLY_EDGE_TYPE = "MESSAGE_LIST_TYPE_ONLY_EDGE_TYPE", MESSAGE_SHOULD_IMPLEMENTS_NODE = "MESSAGE_SHOULD_IMPLEMENTS_NODE", edgeTypesCache;
|
|
3626
3689
|
function getEdgeTypes(schema15) {
|
|
3627
3690
|
if (edgeTypesCache)
|
|
@@ -3758,7 +3821,7 @@ var schema9 = {
|
|
|
3758
3821
|
}
|
|
3759
3822
|
};
|
|
3760
3823
|
|
|
3761
|
-
// src/rules/relay-page-info.ts
|
|
3824
|
+
// src/rules/relay-page-info/index.ts
|
|
3762
3825
|
import { isScalarType as isScalarType4, Kind as Kind17 } from "graphql";
|
|
3763
3826
|
var RULE_ID13 = "relay-page-info", MESSAGE_MUST_EXIST = "MESSAGE_MUST_EXIST", MESSAGE_MUST_BE_OBJECT_TYPE2 = "MESSAGE_MUST_BE_OBJECT_TYPE", notPageInfoTypesSelector = `:matches(${NON_OBJECT_TYPES})[name.value=PageInfo] > .name`, hasPageInfoChecked = !1, rule20 = {
|
|
3764
3827
|
meta: {
|
|
@@ -3831,7 +3894,7 @@ var RULE_ID13 = "relay-page-info", MESSAGE_MUST_EXIST = "MESSAGE_MUST_EXIST", ME
|
|
|
3831
3894
|
}
|
|
3832
3895
|
};
|
|
3833
3896
|
|
|
3834
|
-
// src/rules/require-deprecation-date.ts
|
|
3897
|
+
// src/rules/require-deprecation-date/index.ts
|
|
3835
3898
|
var DATE_REGEX = /^\d{2}\/\d{2}\/\d{4}$/, MESSAGE_REQUIRE_DATE = "MESSAGE_REQUIRE_DATE", MESSAGE_INVALID_FORMAT = "MESSAGE_INVALID_FORMAT", MESSAGE_INVALID_DATE = "MESSAGE_INVALID_DATE", MESSAGE_CAN_BE_REMOVED = "MESSAGE_CAN_BE_REMOVED", schema10 = {
|
|
3836
3899
|
type: "array",
|
|
3837
3900
|
maxItems: 1,
|
|
@@ -3956,7 +4019,7 @@ var DATE_REGEX = /^\d{2}\/\d{2}\/\d{4}$/, MESSAGE_REQUIRE_DATE = "MESSAGE_REQUIR
|
|
|
3956
4019
|
}
|
|
3957
4020
|
};
|
|
3958
4021
|
|
|
3959
|
-
// src/rules/require-deprecation-reason.ts
|
|
4022
|
+
// src/rules/require-deprecation-reason/index.ts
|
|
3960
4023
|
var rule22 = {
|
|
3961
4024
|
meta: {
|
|
3962
4025
|
docs: {
|
|
@@ -4018,9 +4081,9 @@ var rule22 = {
|
|
|
4018
4081
|
}
|
|
4019
4082
|
};
|
|
4020
4083
|
|
|
4021
|
-
// src/rules/require-description.ts
|
|
4022
|
-
import { getRootTypeNames } from "@graphql-tools/utils";
|
|
4084
|
+
// src/rules/require-description/index.ts
|
|
4023
4085
|
import { Kind as Kind18, TokenKind as TokenKind3 } from "graphql";
|
|
4086
|
+
import { getRootTypeNames } from "@graphql-tools/utils";
|
|
4024
4087
|
var RULE_ID14 = "require-description", ALLOWED_KINDS2 = [
|
|
4025
4088
|
...TYPES_KINDS,
|
|
4026
4089
|
Kind18.DIRECTIVE_DEFINITION,
|
|
@@ -4173,7 +4236,7 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
|
|
|
4173
4236
|
}
|
|
4174
4237
|
};
|
|
4175
4238
|
|
|
4176
|
-
// src/rules/require-field-of-type-query-in-mutation-result.ts
|
|
4239
|
+
// src/rules/require-field-of-type-query-in-mutation-result/index.ts
|
|
4177
4240
|
import { isObjectType as isObjectType3 } from "graphql";
|
|
4178
4241
|
var RULE_ID15 = "require-field-of-type-query-in-mutation-result", rule24 = {
|
|
4179
4242
|
meta: {
|
|
@@ -4238,8 +4301,8 @@ var RULE_ID15 = "require-field-of-type-query-in-mutation-result", rule24 = {
|
|
|
4238
4301
|
}
|
|
4239
4302
|
};
|
|
4240
4303
|
|
|
4241
|
-
// src/rules/require-import-fragment.ts
|
|
4242
|
-
import path from "path";
|
|
4304
|
+
// src/rules/require-import-fragment/index.ts
|
|
4305
|
+
import path from "node:path";
|
|
4243
4306
|
var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expression", rule25 = {
|
|
4244
4307
|
meta: {
|
|
4245
4308
|
type: "suggestion",
|
|
@@ -4321,22 +4384,23 @@ var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
|
|
|
4321
4384
|
for (let comment of comments) {
|
|
4322
4385
|
if (comment.type !== "Line" || !new RegExp(
|
|
4323
4386
|
`^\\s*import\\s+(${fragmentName}\\s+from\\s+)?['"]`
|
|
4324
|
-
).test(comment.value))
|
|
4325
|
-
continue;
|
|
4387
|
+
).test(comment.value)) continue;
|
|
4326
4388
|
let extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
|
|
4327
|
-
if (!extractedImportPath)
|
|
4328
|
-
|
|
4329
|
-
let importPath = path.join(path.dirname(filePath), extractedImportPath);
|
|
4389
|
+
if (!extractedImportPath) continue;
|
|
4390
|
+
let importPath = path.join(filePath, "..", extractedImportPath);
|
|
4330
4391
|
if (fragmentsFromSiblings.some(
|
|
4331
4392
|
(source) => source.filePath === importPath
|
|
4332
|
-
))
|
|
4333
|
-
return;
|
|
4393
|
+
)) return;
|
|
4334
4394
|
}
|
|
4335
4395
|
if (fragmentsFromSiblings.some(
|
|
4336
4396
|
(source) => source.filePath === filePath
|
|
4337
|
-
))
|
|
4338
|
-
|
|
4339
|
-
|
|
4397
|
+
)) return;
|
|
4398
|
+
let suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map(
|
|
4399
|
+
(o) => (
|
|
4400
|
+
// Use always forward slash for suggested import path
|
|
4401
|
+
slash(path.relative(path.dirname(filePath), o.filePath))
|
|
4402
|
+
)
|
|
4403
|
+
) : ["CHANGE_ME.graphql"];
|
|
4340
4404
|
context.report({
|
|
4341
4405
|
node,
|
|
4342
4406
|
messageId: RULE_ID16,
|
|
@@ -4356,7 +4420,7 @@ var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
|
|
|
4356
4420
|
}
|
|
4357
4421
|
};
|
|
4358
4422
|
|
|
4359
|
-
// src/rules/require-nullable-fields-with-oneof.ts
|
|
4423
|
+
// src/rules/require-nullable-fields-with-oneof/index.ts
|
|
4360
4424
|
import { Kind as Kind19 } from "graphql";
|
|
4361
4425
|
var RULE_ID17 = "require-nullable-fields-with-oneof", rule26 = {
|
|
4362
4426
|
meta: {
|
|
@@ -4415,7 +4479,7 @@ var RULE_ID17 = "require-nullable-fields-with-oneof", rule26 = {
|
|
|
4415
4479
|
}
|
|
4416
4480
|
};
|
|
4417
4481
|
|
|
4418
|
-
// src/rules/require-nullable-result-in-root.ts
|
|
4482
|
+
// src/rules/require-nullable-result-in-root/index.ts
|
|
4419
4483
|
import { Kind as Kind20 } from "graphql";
|
|
4420
4484
|
var RULE_ID18 = "require-nullable-result-in-root", rule27 = {
|
|
4421
4485
|
meta: {
|
|
@@ -4492,8 +4556,7 @@ var RULE_ID18 = "require-nullable-result-in-root", rule27 = {
|
|
|
4492
4556
|
}
|
|
4493
4557
|
};
|
|
4494
4558
|
|
|
4495
|
-
// src/rules/require-selections.ts
|
|
4496
|
-
import { asArray } from "@graphql-tools/utils";
|
|
4559
|
+
// src/rules/require-selections/index.ts
|
|
4497
4560
|
import {
|
|
4498
4561
|
GraphQLInterfaceType,
|
|
4499
4562
|
GraphQLObjectType,
|
|
@@ -4503,6 +4566,7 @@ import {
|
|
|
4503
4566
|
visit as visit8,
|
|
4504
4567
|
visitWithTypeInfo as visitWithTypeInfo3
|
|
4505
4568
|
} from "graphql";
|
|
4569
|
+
import { asArray } from "@graphql-tools/utils";
|
|
4506
4570
|
var RULE_ID19 = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema12 = {
|
|
4507
4571
|
definitions: {
|
|
4508
4572
|
asString: {
|
|
@@ -4618,13 +4682,19 @@ Include it in your selection set{{ addition }}.`
|
|
|
4618
4682
|
let rawType = getBaseType(type);
|
|
4619
4683
|
if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType)
|
|
4620
4684
|
checkFields(rawType);
|
|
4621
|
-
else if (rawType instanceof GraphQLUnionType)
|
|
4622
|
-
for (let selection of node.selections)
|
|
4685
|
+
else if (rawType instanceof GraphQLUnionType)
|
|
4686
|
+
for (let selection of node.selections) {
|
|
4687
|
+
let types = rawType.getTypes();
|
|
4623
4688
|
if (selection.kind === Kind21.INLINE_FRAGMENT) {
|
|
4624
|
-
let t =
|
|
4689
|
+
let t = types.find((t2) => t2.name === selection.typeCondition.name.value);
|
|
4625
4690
|
t && checkFields(t);
|
|
4691
|
+
} else if (selection.kind === Kind21.FRAGMENT_SPREAD) {
|
|
4692
|
+
let [foundSpread] = siblings.getFragment(selection.name.value);
|
|
4693
|
+
if (!foundSpread) return;
|
|
4694
|
+
let fragmentSpread = foundSpread.document, t = fragmentSpread.typeCondition.name.value === rawType.name ? rawType : types.find((t2) => t2.name === fragmentSpread.typeCondition.name.value);
|
|
4695
|
+
checkedFragmentSpreads.add(fragmentSpread.name.value), checkSelections(fragmentSpread.selectionSet, t, loc, parent, checkedFragmentSpreads);
|
|
4626
4696
|
}
|
|
4627
|
-
|
|
4697
|
+
}
|
|
4628
4698
|
function checkFields(rawType2) {
|
|
4629
4699
|
let fields = rawType2.getFields();
|
|
4630
4700
|
if (!idNames.some((name) => fields[name]))
|
|
@@ -4677,7 +4747,7 @@ Include it in your selection set{{ addition }}.`
|
|
|
4677
4747
|
}
|
|
4678
4748
|
};
|
|
4679
4749
|
|
|
4680
|
-
// src/rules/require-type-pattern-with-oneof.ts
|
|
4750
|
+
// src/rules/require-type-pattern-with-oneof/index.ts
|
|
4681
4751
|
var RULE_ID20 = "require-type-pattern-with-oneof", rule29 = {
|
|
4682
4752
|
meta: {
|
|
4683
4753
|
type: "suggestion",
|
|
@@ -4737,7 +4807,7 @@ var RULE_ID20 = "require-type-pattern-with-oneof", rule29 = {
|
|
|
4737
4807
|
}
|
|
4738
4808
|
};
|
|
4739
4809
|
|
|
4740
|
-
// src/rules/selection-set-depth.ts
|
|
4810
|
+
// src/rules/selection-set-depth/index.ts
|
|
4741
4811
|
import { Kind as Kind22 } from "graphql";
|
|
4742
4812
|
import depthLimit from "graphql-depth-limit";
|
|
4743
4813
|
var RULE_ID21 = "selection-set-depth", schema13 = {
|
|
@@ -4830,7 +4900,7 @@ var RULE_ID21 = "selection-set-depth", schema13 = {
|
|
|
4830
4900
|
checkFn({
|
|
4831
4901
|
getDocument: () => document,
|
|
4832
4902
|
reportError(error) {
|
|
4833
|
-
let { line, column } = error.locations[0], token = context.getAncestors()[0].tokens.find(
|
|
4903
|
+
let { line, column } = error.locations[0], token = context.sourceCode.getAncestors(node)[0].tokens.find(
|
|
4834
4904
|
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
|
4835
4905
|
);
|
|
4836
4906
|
context.report({
|
|
@@ -4867,7 +4937,7 @@ var RULE_ID21 = "selection-set-depth", schema13 = {
|
|
|
4867
4937
|
}
|
|
4868
4938
|
};
|
|
4869
4939
|
|
|
4870
|
-
// src/rules/strict-id-in-types.ts
|
|
4940
|
+
// src/rules/strict-id-in-types/index.ts
|
|
4871
4941
|
import { Kind as Kind23 } from "graphql";
|
|
4872
4942
|
var RULE_ID22 = "strict-id-in-types", schema14 = {
|
|
4873
4943
|
type: "array",
|
|
@@ -5012,7 +5082,7 @@ Accepted type${pluralTypesSuffix}: ${englishJoinWords(options.acceptedIdTypes)}.
|
|
|
5012
5082
|
}
|
|
5013
5083
|
};
|
|
5014
5084
|
|
|
5015
|
-
// src/rules/unique-enum-value-names.ts
|
|
5085
|
+
// src/rules/unique-enum-value-names/index.ts
|
|
5016
5086
|
import { Kind as Kind24 } from "graphql";
|
|
5017
5087
|
var rule32 = {
|
|
5018
5088
|
meta: {
|
|
@@ -5081,12 +5151,12 @@ var rule32 = {
|
|
|
5081
5151
|
}
|
|
5082
5152
|
};
|
|
5083
5153
|
|
|
5084
|
-
// src/rules/unique-fragment-name.ts
|
|
5085
|
-
import { relative as relative2 } from "path";
|
|
5154
|
+
// src/rules/unique-fragment-name/index.ts
|
|
5155
|
+
import { relative as relative2 } from "node:path";
|
|
5086
5156
|
import { Kind as Kind25 } from "graphql";
|
|
5087
5157
|
var RULE_ID23 = "unique-fragment-name", checkNode = (context, node, ruleId) => {
|
|
5088
5158
|
let documentName = node.name.value, siblings = requireSiblingsOperations(ruleId, context), siblingDocuments = node.kind === Kind25.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName), filepath = context.filename, conflictingDocuments = siblingDocuments.filter((f) => {
|
|
5089
|
-
let isSameName = f.document.name?.value === documentName, isSamePath =
|
|
5159
|
+
let isSameName = f.document.name?.value === documentName, isSamePath = slash(f.filePath) === slash(filepath);
|
|
5090
5160
|
return isSameName && !isSamePath;
|
|
5091
5161
|
});
|
|
5092
5162
|
conflictingDocuments.length > 0 && context.report({
|
|
@@ -5164,7 +5234,7 @@ var RULE_ID23 = "unique-fragment-name", checkNode = (context, node, ruleId) => {
|
|
|
5164
5234
|
}
|
|
5165
5235
|
};
|
|
5166
5236
|
|
|
5167
|
-
// src/rules/unique-operation-name.ts
|
|
5237
|
+
// src/rules/unique-operation-name/index.ts
|
|
5168
5238
|
var RULE_ID24 = "unique-operation-name", rule34 = {
|
|
5169
5239
|
meta: {
|
|
5170
5240
|
type: "suggestion",
|
|
@@ -5274,50 +5344,36 @@ var rules = {
|
|
|
5274
5344
|
};
|
|
5275
5345
|
|
|
5276
5346
|
// src/configs/index.ts
|
|
5277
|
-
var import_operations_all = __toESM(require_operations_all()), import_operations_recommended = __toESM(require_operations_recommended()), import_schema_all = __toESM(require_schema_all()), import_schema_recommended = __toESM(require_schema_recommended()), import_schema_relay = __toESM(require_schema_relay()), configs = {
|
|
5347
|
+
var import_operations_all = __toESM(require_operations_all(), 1), import_operations_recommended = __toESM(require_operations_recommended(), 1), import_schema_all = __toESM(require_schema_all(), 1), import_schema_recommended = __toESM(require_schema_recommended(), 1), import_schema_relay = __toESM(require_schema_relay(), 1), configs = {
|
|
5278
5348
|
"schema-recommended": import_schema_recommended.default,
|
|
5279
5349
|
"schema-all": import_schema_all.default,
|
|
5280
5350
|
"schema-relay": import_schema_relay.default,
|
|
5281
5351
|
"operations-recommended": import_operations_recommended.default,
|
|
5282
|
-
"operations-all": import_operations_all.default
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
parser: { parseForESLint }
|
|
5288
|
-
}, flatConfigs = {
|
|
5289
|
-
"operations-all": {
|
|
5290
|
-
languageOptions,
|
|
5352
|
+
"operations-all": import_operations_all.default,
|
|
5353
|
+
"flat/schema-recommended": {
|
|
5354
|
+
rules: import_schema_recommended.default.rules
|
|
5355
|
+
},
|
|
5356
|
+
"flat/schema-all": {
|
|
5291
5357
|
rules: {
|
|
5292
|
-
...
|
|
5293
|
-
...
|
|
5358
|
+
...import_schema_recommended.default.rules,
|
|
5359
|
+
...import_schema_all.default.rules
|
|
5294
5360
|
}
|
|
5295
5361
|
},
|
|
5296
|
-
"
|
|
5297
|
-
|
|
5298
|
-
rules: configs["operations-recommended"].rules
|
|
5362
|
+
"flat/schema-relay": {
|
|
5363
|
+
rules: import_schema_relay.default.rules
|
|
5299
5364
|
},
|
|
5300
|
-
"
|
|
5301
|
-
|
|
5302
|
-
rules: configs["schema-relay"].rules
|
|
5365
|
+
"flat/operations-recommended": {
|
|
5366
|
+
rules: import_operations_recommended.default.rules
|
|
5303
5367
|
},
|
|
5304
|
-
"
|
|
5305
|
-
languageOptions,
|
|
5368
|
+
"flat/operations-all": {
|
|
5306
5369
|
rules: {
|
|
5307
|
-
...
|
|
5308
|
-
...
|
|
5370
|
+
...import_operations_recommended.default.rules,
|
|
5371
|
+
...import_operations_all.default.rules
|
|
5309
5372
|
}
|
|
5310
|
-
},
|
|
5311
|
-
"schema-recommended": {
|
|
5312
|
-
languageOptions,
|
|
5313
|
-
rules: configs["schema-recommended"].rules
|
|
5314
5373
|
}
|
|
5315
5374
|
};
|
|
5316
5375
|
export {
|
|
5317
5376
|
configs,
|
|
5318
|
-
|
|
5319
|
-
parseForESLint,
|
|
5320
|
-
requireGraphQLSchemaFromContext,
|
|
5321
|
-
requireSiblingsOperations,
|
|
5377
|
+
parser,
|
|
5322
5378
|
rules
|
|
5323
5379
|
};
|