@graphql-eslint/eslint-plugin 4.0.0-alpha-20220821140530-e968cfc → 4.0.0-alpha-20230801163310-8bc4340
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/LICENSE +21 -0
- package/README.md +13 -253
- package/cjs/cache.d.ts +12 -0
- package/cjs/cache.js +62 -0
- package/cjs/configs/index.d.ts +148 -0
- package/cjs/configs/index.js +49 -0
- package/cjs/configs/operations-all.d.ts +22 -0
- package/cjs/configs/operations-all.js +27 -0
- package/cjs/configs/operations-recommended.d.ts +52 -0
- package/{configs/operations-recommended.json → cjs/configs/operations-recommended.js} +16 -14
- package/cjs/configs/relay.d.ts +12 -0
- package/{configs/relay.json → cjs/configs/relay.js} +6 -4
- package/cjs/configs/schema-all.d.ts +19 -0
- package/cjs/configs/schema-all.js +21 -0
- package/cjs/configs/schema-recommended.d.ts +49 -0
- package/{configs/schema-recommended.json → cjs/configs/schema-recommended.js} +19 -20
- package/cjs/documents.d.ts +6 -0
- package/cjs/documents.js +81 -0
- package/cjs/estree-converter/converter.d.ts +8 -0
- package/cjs/estree-converter/converter.js +83 -0
- package/cjs/estree-converter/index.d.ts +8 -0
- package/cjs/estree-converter/index.js +26 -0
- package/cjs/estree-converter/types.d.ts +42 -0
- package/cjs/estree-converter/types.js +16 -0
- package/cjs/estree-converter/utils.d.ts +18 -0
- package/cjs/estree-converter/utils.js +135 -0
- package/cjs/flat-configs.d.ts +260 -0
- package/cjs/flat-configs.js +60 -0
- package/cjs/graphql-config.d.ts +13 -0
- package/cjs/graphql-config.js +86 -0
- package/cjs/index.d.ts +22 -0
- package/cjs/index.js +49 -0
- package/cjs/parser.d.ts +12 -0
- package/cjs/parser.js +103 -0
- package/cjs/processor.d.ts +9 -0
- package/cjs/processor.js +127 -0
- package/cjs/rules/alphabetize.d.ts +84 -0
- package/cjs/rules/alphabetize.js +395 -0
- package/cjs/rules/description-style.d.ts +28 -0
- package/cjs/rules/description-style.js +109 -0
- package/cjs/rules/graphql-js-validation.d.ts +12 -0
- package/cjs/rules/graphql-js-validation.js +669 -0
- package/cjs/rules/index.d.ts +125 -0
- package/cjs/rules/index.js +99 -0
- package/cjs/rules/input-name.d.ts +43 -0
- package/cjs/rules/input-name.js +170 -0
- package/cjs/rules/lone-executable-definition.d.ts +34 -0
- package/cjs/rules/lone-executable-definition.js +119 -0
- package/cjs/rules/match-document-filename.d.ts +80 -0
- package/cjs/rules/match-document-filename.js +282 -0
- package/cjs/rules/naming-convention.d.ts +107 -0
- package/cjs/rules/naming-convention.js +434 -0
- package/cjs/rules/no-anonymous-operations.d.ts +12 -0
- package/cjs/rules/no-anonymous-operations.js +98 -0
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.d.ts +12 -0
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +96 -0
- package/cjs/rules/no-deprecated.d.ts +12 -0
- package/cjs/rules/no-deprecated.js +157 -0
- package/cjs/rules/no-duplicate-fields.d.ts +12 -0
- package/cjs/rules/no-duplicate-fields.js +146 -0
- package/cjs/rules/no-hashtag-description.d.ts +13 -0
- package/cjs/rules/no-hashtag-description.js +140 -0
- package/cjs/rules/no-one-place-fragments.d.ts +12 -0
- package/cjs/rules/no-one-place-fragments.js +113 -0
- package/cjs/rules/no-root-type.d.ts +33 -0
- package/cjs/rules/no-root-type.js +113 -0
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +12 -0
- package/cjs/rules/no-scalar-result-type-on-mutation.js +100 -0
- package/cjs/rules/no-typename-prefix.d.ts +12 -0
- package/cjs/rules/no-typename-prefix.js +98 -0
- package/cjs/rules/no-unreachable-types.d.ts +12 -0
- package/cjs/rules/no-unreachable-types.js +199 -0
- package/cjs/rules/no-unused-fields.d.ts +12 -0
- package/cjs/rules/no-unused-fields.js +157 -0
- package/cjs/rules/relay-arguments.d.ts +29 -0
- package/cjs/rules/relay-arguments.js +149 -0
- package/cjs/rules/relay-connection-types.d.ts +13 -0
- package/cjs/rules/relay-connection-types.js +142 -0
- package/cjs/rules/relay-edge-types.d.ts +39 -0
- package/cjs/rules/relay-edge-types.js +212 -0
- package/cjs/rules/relay-page-info.d.ts +12 -0
- package/cjs/rules/relay-page-info.js +121 -0
- package/cjs/rules/require-deprecation-date.d.ts +26 -0
- package/cjs/rules/require-deprecation-date.js +164 -0
- package/cjs/rules/require-deprecation-reason.d.ts +12 -0
- package/cjs/rules/require-deprecation-reason.js +93 -0
- package/cjs/rules/require-description.d.ts +23 -0
- package/cjs/rules/require-description.js +205 -0
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +12 -0
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +102 -0
- package/cjs/rules/require-id-when-available.d.ts +44 -0
- package/cjs/rules/require-id-when-available.js +241 -0
- package/cjs/rules/require-import-fragment.d.ts +12 -0
- package/cjs/rules/require-import-fragment.js +166 -0
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +12 -0
- package/cjs/rules/require-nullable-fields-with-oneof.js +92 -0
- package/cjs/rules/require-nullable-result-in-root.d.ts +12 -0
- package/cjs/rules/require-nullable-result-in-root.js +109 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +12 -0
- package/cjs/rules/require-type-pattern-with-oneof.js +91 -0
- package/cjs/rules/selection-set-depth.d.ts +36 -0
- package/cjs/rules/selection-set-depth.js +175 -0
- package/cjs/rules/strict-id-in-types.d.ts +65 -0
- package/cjs/rules/strict-id-in-types.js +186 -0
- package/cjs/rules/unique-fragment-name.d.ts +13 -0
- package/cjs/rules/unique-fragment-name.js +118 -0
- package/cjs/rules/unique-operation-name.d.ts +12 -0
- package/cjs/rules/unique-operation-name.js +95 -0
- package/cjs/schema.d.ts +12 -0
- package/cjs/schema.js +65 -0
- package/cjs/siblings.d.ts +8 -0
- package/cjs/siblings.js +136 -0
- package/cjs/types-8d5f4ae0.d.ts +107 -0
- package/cjs/types.d.ts +8 -0
- package/cjs/types.js +16 -0
- package/cjs/utils.d.ts +44 -0
- package/cjs/utils.js +205 -0
- package/esm/cache.d.mts +12 -0
- package/esm/cache.js +29 -0
- package/esm/chunk-BMTV3EA2.js +8 -0
- package/esm/configs/index.d.mts +148 -0
- package/esm/configs/index.js +16 -0
- package/esm/configs/operations-all.d.mts +22 -0
- package/esm/configs/operations-all.js +34 -0
- package/esm/configs/operations-recommended.d.mts +52 -0
- package/esm/configs/operations-recommended.js +59 -0
- package/esm/configs/relay.d.mts +12 -0
- package/esm/configs/relay.js +18 -0
- package/esm/configs/schema-all.d.mts +19 -0
- package/esm/configs/schema-all.js +28 -0
- package/esm/configs/schema-recommended.d.mts +49 -0
- package/esm/configs/schema-recommended.js +55 -0
- package/esm/documents.d.mts +6 -0
- package/esm/documents.js +48 -0
- package/esm/estree-converter/converter.d.mts +8 -0
- package/esm/estree-converter/converter.js +65 -0
- package/esm/estree-converter/index.d.mts +8 -0
- package/esm/estree-converter/index.js +3 -0
- package/esm/estree-converter/types.d.mts +42 -0
- package/esm/estree-converter/types.js +0 -0
- package/esm/estree-converter/utils.d.mts +18 -0
- package/esm/estree-converter/utils.js +114 -0
- package/esm/flat-configs.d.mts +260 -0
- package/esm/flat-configs.js +37 -0
- package/esm/graphql-config.d.mts +13 -0
- package/esm/graphql-config.js +55 -0
- package/esm/index.d.mts +22 -0
- package/esm/index.js +18 -0
- package/esm/package.json +1 -0
- package/esm/parser.d.mts +12 -0
- package/esm/parser.js +70 -0
- package/esm/processor.d.mts +9 -0
- package/esm/processor.js +106 -0
- package/esm/rules/alphabetize.d.mts +84 -0
- package/esm/rules/alphabetize.js +364 -0
- package/esm/rules/description-style.d.mts +28 -0
- package/esm/rules/description-style.js +86 -0
- package/esm/rules/graphql-js-validation.d.mts +12 -0
- package/esm/rules/graphql-js-validation.js +658 -0
- package/esm/rules/index.d.mts +125 -0
- package/esm/rules/index.js +76 -0
- package/esm/rules/input-name.d.mts +43 -0
- package/esm/rules/input-name.js +149 -0
- package/esm/rules/lone-executable-definition.d.mts +34 -0
- package/esm/rules/lone-executable-definition.js +96 -0
- package/esm/rules/match-document-filename.d.mts +80 -0
- package/esm/rules/match-document-filename.js +263 -0
- package/esm/rules/naming-convention.d.mts +107 -0
- package/esm/rules/naming-convention.js +417 -0
- package/esm/rules/no-anonymous-operations.d.mts +12 -0
- package/esm/rules/no-anonymous-operations.js +75 -0
- package/esm/rules/no-case-insensitive-enum-values-duplicates.d.mts +12 -0
- package/esm/rules/no-case-insensitive-enum-values-duplicates.js +73 -0
- package/esm/rules/no-deprecated.d.mts +12 -0
- package/esm/rules/no-deprecated.js +134 -0
- package/esm/rules/no-duplicate-fields.d.mts +12 -0
- package/esm/rules/no-duplicate-fields.js +123 -0
- package/esm/rules/no-hashtag-description.d.mts +13 -0
- package/esm/rules/no-hashtag-description.js +116 -0
- package/esm/rules/no-one-place-fragments.d.mts +12 -0
- package/esm/rules/no-one-place-fragments.js +90 -0
- package/esm/rules/no-root-type.d.mts +33 -0
- package/esm/rules/no-root-type.js +90 -0
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +12 -0
- package/esm/rules/no-scalar-result-type-on-mutation.js +77 -0
- package/esm/rules/no-typename-prefix.d.mts +12 -0
- package/esm/rules/no-typename-prefix.js +75 -0
- package/esm/rules/no-unreachable-types.d.mts +12 -0
- package/esm/rules/no-unreachable-types.js +171 -0
- package/esm/rules/no-unused-fields.d.mts +12 -0
- package/esm/rules/no-unused-fields.js +134 -0
- package/esm/rules/relay-arguments.d.mts +29 -0
- package/esm/rules/relay-arguments.js +126 -0
- package/esm/rules/relay-connection-types.d.mts +13 -0
- package/esm/rules/relay-connection-types.js +118 -0
- package/esm/rules/relay-edge-types.d.mts +39 -0
- package/esm/rules/relay-edge-types.js +194 -0
- package/esm/rules/relay-page-info.d.mts +12 -0
- package/esm/rules/relay-page-info.js +98 -0
- package/esm/rules/require-deprecation-date.d.mts +26 -0
- package/esm/rules/require-deprecation-date.js +141 -0
- package/esm/rules/require-deprecation-reason.d.mts +12 -0
- package/esm/rules/require-deprecation-reason.js +70 -0
- package/esm/rules/require-description.d.mts +23 -0
- package/esm/rules/require-description.js +186 -0
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +12 -0
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +79 -0
- package/esm/rules/require-id-when-available.d.mts +44 -0
- package/esm/rules/require-id-when-available.js +231 -0
- package/esm/rules/require-import-fragment.d.mts +12 -0
- package/esm/rules/require-import-fragment.js +133 -0
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +12 -0
- package/esm/rules/require-nullable-fields-with-oneof.js +69 -0
- package/esm/rules/require-nullable-result-in-root.d.mts +12 -0
- package/esm/rules/require-nullable-result-in-root.js +86 -0
- package/esm/rules/require-type-pattern-with-oneof.d.mts +12 -0
- package/esm/rules/require-type-pattern-with-oneof.js +68 -0
- package/esm/rules/selection-set-depth.d.mts +36 -0
- package/esm/rules/selection-set-depth.js +142 -0
- package/esm/rules/strict-id-in-types.d.mts +65 -0
- package/esm/rules/strict-id-in-types.js +169 -0
- package/esm/rules/unique-fragment-name.d.mts +13 -0
- package/esm/rules/unique-fragment-name.js +94 -0
- package/esm/rules/unique-operation-name.d.mts +12 -0
- package/esm/rules/unique-operation-name.js +72 -0
- package/esm/schema.d.mts +12 -0
- package/esm/schema.js +32 -0
- package/esm/siblings.d.mts +8 -0
- package/esm/siblings.js +116 -0
- package/esm/types-ace77d86.d.ts +107 -0
- package/esm/types.d.mts +8 -0
- package/esm/types.js +0 -0
- package/esm/utils.d.mts +44 -0
- package/esm/utils.js +155 -0
- package/package.json +47 -34
- package/configs/base.json +0 -4
- package/configs/operations-all.json +0 -24
- package/configs/schema-all.json +0 -26
- package/docs/README.md +0 -75
- package/docs/custom-rules.md +0 -148
- package/docs/deprecated-rules.md +0 -21
- package/docs/parser-options.md +0 -85
- package/docs/parser.md +0 -49
- package/docs/rules/alphabetize.md +0 -178
- package/docs/rules/description-style.md +0 -54
- package/docs/rules/executable-definitions.md +0 -17
- package/docs/rules/fields-on-correct-type.md +0 -17
- package/docs/rules/fragments-on-composite-type.md +0 -17
- package/docs/rules/input-name.md +0 -76
- package/docs/rules/known-argument-names.md +0 -17
- package/docs/rules/known-directives.md +0 -44
- package/docs/rules/known-fragment-names.md +0 -69
- package/docs/rules/known-type-names.md +0 -17
- package/docs/rules/lone-anonymous-operation.md +0 -17
- package/docs/rules/lone-schema-definition.md +0 -17
- package/docs/rules/match-document-filename.md +0 -156
- package/docs/rules/naming-convention.md +0 -300
- package/docs/rules/no-anonymous-operations.md +0 -39
- package/docs/rules/no-case-insensitive-enum-values-duplicates.md +0 -43
- package/docs/rules/no-deprecated.md +0 -85
- package/docs/rules/no-duplicate-fields.md +0 -65
- package/docs/rules/no-fragment-cycles.md +0 -17
- package/docs/rules/no-hashtag-description.md +0 -59
- package/docs/rules/no-root-type.md +0 -53
- package/docs/rules/no-scalar-result-type-on-mutation.md +0 -37
- package/docs/rules/no-typename-prefix.md +0 -39
- package/docs/rules/no-undefined-variables.md +0 -17
- package/docs/rules/no-unreachable-types.md +0 -49
- package/docs/rules/no-unused-fields.md +0 -62
- package/docs/rules/no-unused-fragments.md +0 -17
- package/docs/rules/no-unused-variables.md +0 -17
- package/docs/rules/one-field-subscriptions.md +0 -17
- package/docs/rules/overlapping-fields-can-be-merged.md +0 -17
- package/docs/rules/possible-fragment-spread.md +0 -17
- package/docs/rules/possible-type-extension.md +0 -15
- package/docs/rules/provided-required-arguments.md +0 -17
- package/docs/rules/relay-arguments.md +0 -57
- package/docs/rules/relay-connection-types.md +0 -42
- package/docs/rules/relay-edge-types.md +0 -56
- package/docs/rules/relay-page-info.md +0 -32
- package/docs/rules/require-deprecation-date.md +0 -56
- package/docs/rules/require-deprecation-reason.md +0 -47
- package/docs/rules/require-description.md +0 -115
- package/docs/rules/require-field-of-type-query-in-mutation-result.md +0 -47
- package/docs/rules/require-id-when-available.md +0 -88
- package/docs/rules/scalar-leafs.md +0 -17
- package/docs/rules/selection-set-depth.md +0 -76
- package/docs/rules/strict-id-in-types.md +0 -130
- package/docs/rules/unique-argument-names.md +0 -17
- package/docs/rules/unique-directive-names-per-location.md +0 -17
- package/docs/rules/unique-directive-names.md +0 -17
- package/docs/rules/unique-enum-value-names.md +0 -15
- package/docs/rules/unique-field-definition-names.md +0 -17
- package/docs/rules/unique-fragment-name.md +0 -51
- package/docs/rules/unique-input-field-names.md +0 -17
- package/docs/rules/unique-operation-name.md +0 -55
- package/docs/rules/unique-operation-types.md +0 -17
- package/docs/rules/unique-type-names.md +0 -17
- package/docs/rules/unique-variable-names.md +0 -17
- package/docs/rules/value-literals-of-correct-type.md +0 -17
- package/docs/rules/variables-are-input-types.md +0 -17
- package/docs/rules/variables-in-allowed-position.md +0 -17
- package/estree-converter/converter.d.ts +0 -3
- package/estree-converter/index.d.ts +0 -3
- package/estree-converter/types.d.ts +0 -40
- package/estree-converter/utils.d.ts +0 -13
- package/graphql-config.d.ts +0 -3
- package/index.d.ts +0 -16
- package/index.js +0 -4653
- package/index.mjs +0 -4641
- package/parser.d.ts +0 -2
- package/processor.d.ts +0 -7
- package/rules/alphabetize.d.ts +0 -16
- package/rules/description-style.d.ts +0 -6
- package/rules/graphql-js-validation.d.ts +0 -2
- package/rules/index.d.ts +0 -41
- package/rules/input-name.d.ts +0 -9
- package/rules/match-document-filename.d.ts +0 -18
- package/rules/naming-convention.d.ts +0 -37
- package/rules/no-anonymous-operations.d.ts +0 -3
- package/rules/no-case-insensitive-enum-values-duplicates.d.ts +0 -3
- package/rules/no-deprecated.d.ts +0 -3
- package/rules/no-duplicate-fields.d.ts +0 -3
- package/rules/no-hashtag-description.d.ts +0 -3
- package/rules/no-root-type.d.ts +0 -7
- package/rules/no-scalar-result-type-on-mutation.d.ts +0 -3
- package/rules/no-typename-prefix.d.ts +0 -3
- package/rules/no-unreachable-types.d.ts +0 -3
- package/rules/no-unused-fields.d.ts +0 -3
- package/rules/relay-arguments.d.ts +0 -6
- package/rules/relay-connection-types.d.ts +0 -5
- package/rules/relay-edge-types.d.ts +0 -8
- package/rules/relay-page-info.d.ts +0 -3
- package/rules/require-deprecation-date.d.ts +0 -5
- package/rules/require-deprecation-reason.d.ts +0 -3
- package/rules/require-description.d.ts +0 -11
- package/rules/require-field-of-type-query-in-mutation-result.d.ts +0 -3
- package/rules/require-id-when-available.d.ts +0 -6
- package/rules/selection-set-depth.d.ts +0 -7
- package/rules/strict-id-in-types.d.ts +0 -11
- package/rules/unique-fragment-name.d.ts +0 -6
- package/rules/unique-operation-name.d.ts +0 -3
- package/schema.d.ts +0 -3
- package/sibling-operations.d.ts +0 -21
- package/testkit.d.ts +0 -27
- package/types.d.ts +0 -79
- package/utils.d.ts +0 -39
package/esm/utils.d.mts
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
import { AST } from 'eslint';
|
2
|
+
import { Position } from 'estree';
|
3
|
+
import { GraphQLSchema, ASTNode, Kind } from 'graphql';
|
4
|
+
import { c as GraphQLESLintRuleContext, g as SiblingOperations } from './types-ace77d86.js';
|
5
|
+
import { GraphQLESTreeNode } from './estree-converter/types.mjs';
|
6
|
+
import '@graphql-tools/utils';
|
7
|
+
import 'graphql-config';
|
8
|
+
import 'json-schema-to-ts';
|
9
|
+
|
10
|
+
declare function requireSiblingsOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
|
11
|
+
declare function requireGraphQLSchemaFromContext(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
|
12
|
+
declare const logger: {
|
13
|
+
error: (...args: unknown[]) => void;
|
14
|
+
warn: (...args: unknown[]) => void;
|
15
|
+
};
|
16
|
+
declare const normalizePath: (path: string) => string;
|
17
|
+
declare const VIRTUAL_DOCUMENT_REGEX: RegExp;
|
18
|
+
declare const CWD: string;
|
19
|
+
declare const getTypeName: (node: ASTNode) => string;
|
20
|
+
declare const TYPES_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION];
|
21
|
+
type CaseStyle = 'camelCase' | 'kebab-case' | 'PascalCase' | 'snake_case' | 'UPPER_CASE';
|
22
|
+
declare const pascalCase: (str: string) => string;
|
23
|
+
declare const camelCase: (str: string) => string;
|
24
|
+
declare const convertCase: (style: CaseStyle, str: string) => string;
|
25
|
+
declare function getLocation(start: Position, fieldName?: string): AST.SourceLocation;
|
26
|
+
declare const REPORT_ON_FIRST_CHARACTER: {
|
27
|
+
column: number;
|
28
|
+
line: number;
|
29
|
+
};
|
30
|
+
declare const ARRAY_DEFAULT_OPTIONS: {
|
31
|
+
readonly type: "array";
|
32
|
+
readonly uniqueItems: true;
|
33
|
+
readonly minItems: 1;
|
34
|
+
readonly items: {
|
35
|
+
readonly type: "string";
|
36
|
+
};
|
37
|
+
};
|
38
|
+
declare const englishJoinWords: (words: string[]) => string;
|
39
|
+
type Truthy<T> = T extends '' | 0 | false | null | undefined ? never : T;
|
40
|
+
declare function truthy<T>(value: T): value is Truthy<T>;
|
41
|
+
declare function displayNodeName(node: GraphQLESTreeNode<ASTNode>): string;
|
42
|
+
declare function getNodeName(node: GraphQLESTreeNode<ASTNode>): string;
|
43
|
+
|
44
|
+
export { ARRAY_DEFAULT_OPTIONS, CWD, CaseStyle, REPORT_ON_FIRST_CHARACTER, TYPES_KINDS, VIRTUAL_DOCUMENT_REGEX, camelCase, convertCase, displayNodeName, englishJoinWords, getLocation, getNodeName, getTypeName, logger, normalizePath, pascalCase, requireGraphQLSchemaFromContext, requireSiblingsOperations, truthy };
|
package/esm/utils.js
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
import "./chunk-BMTV3EA2.js";
|
2
|
+
import chalk from "chalk";
|
3
|
+
import { Kind } from "graphql";
|
4
|
+
import lowerCase from "lodash.lowercase";
|
5
|
+
function requireSiblingsOperations(ruleId, context) {
|
6
|
+
const { siblingOperations } = context.parserServices;
|
7
|
+
if (!siblingOperations.available) {
|
8
|
+
throw new Error(
|
9
|
+
`Rule \`${ruleId}\` requires \`parserOptions.operations\` to be set and loaded. See https://bit.ly/graphql-eslint-operations for more info`
|
10
|
+
);
|
11
|
+
}
|
12
|
+
return siblingOperations;
|
13
|
+
}
|
14
|
+
function requireGraphQLSchemaFromContext(ruleId, context) {
|
15
|
+
const { schema } = context.parserServices;
|
16
|
+
if (!schema) {
|
17
|
+
throw new Error(
|
18
|
+
`Rule \`${ruleId}\` requires \`parserOptions.schema\` to be set and loaded. See https://bit.ly/graphql-eslint-schema for more info`
|
19
|
+
);
|
20
|
+
}
|
21
|
+
return schema;
|
22
|
+
}
|
23
|
+
const logger = {
|
24
|
+
error: (...args) => (
|
25
|
+
// eslint-disable-next-line no-console
|
26
|
+
console.error(chalk.red("error"), "[graphql-eslint]", chalk(...args))
|
27
|
+
),
|
28
|
+
warn: (...args) => (
|
29
|
+
// eslint-disable-next-line no-console
|
30
|
+
console.warn(chalk.yellow("warning"), "[graphql-eslint]", chalk(...args))
|
31
|
+
)
|
32
|
+
};
|
33
|
+
const normalizePath = (path) => (path || "").replace(/\\/g, "/");
|
34
|
+
const VIRTUAL_DOCUMENT_REGEX = /\/\d+_document.graphql$/;
|
35
|
+
const CWD = process.cwd();
|
36
|
+
const getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "";
|
37
|
+
const TYPES_KINDS = [
|
38
|
+
Kind.OBJECT_TYPE_DEFINITION,
|
39
|
+
Kind.INTERFACE_TYPE_DEFINITION,
|
40
|
+
Kind.ENUM_TYPE_DEFINITION,
|
41
|
+
Kind.SCALAR_TYPE_DEFINITION,
|
42
|
+
Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
43
|
+
Kind.UNION_TYPE_DEFINITION
|
44
|
+
];
|
45
|
+
const pascalCase = (str) => lowerCase(str).split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
46
|
+
const camelCase = (str) => {
|
47
|
+
const result = pascalCase(str);
|
48
|
+
return result.charAt(0).toLowerCase() + result.slice(1);
|
49
|
+
};
|
50
|
+
const convertCase = (style, str) => {
|
51
|
+
switch (style) {
|
52
|
+
case "camelCase":
|
53
|
+
return camelCase(str);
|
54
|
+
case "PascalCase":
|
55
|
+
return pascalCase(str);
|
56
|
+
case "snake_case":
|
57
|
+
return lowerCase(str).replace(/ /g, "_");
|
58
|
+
case "UPPER_CASE":
|
59
|
+
return lowerCase(str).replace(/ /g, "_").toUpperCase();
|
60
|
+
case "kebab-case":
|
61
|
+
return lowerCase(str).replace(/ /g, "-");
|
62
|
+
}
|
63
|
+
};
|
64
|
+
function getLocation(start, fieldName = "") {
|
65
|
+
const { line, column } = start;
|
66
|
+
return {
|
67
|
+
start: {
|
68
|
+
line,
|
69
|
+
column
|
70
|
+
},
|
71
|
+
end: {
|
72
|
+
line,
|
73
|
+
column: column + fieldName.length
|
74
|
+
}
|
75
|
+
};
|
76
|
+
}
|
77
|
+
const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 };
|
78
|
+
const ARRAY_DEFAULT_OPTIONS = {
|
79
|
+
type: "array",
|
80
|
+
uniqueItems: true,
|
81
|
+
minItems: 1,
|
82
|
+
items: {
|
83
|
+
type: "string"
|
84
|
+
}
|
85
|
+
};
|
86
|
+
const englishJoinWords = (words) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(words);
|
87
|
+
function truthy(value) {
|
88
|
+
return !!value;
|
89
|
+
}
|
90
|
+
const DisplayNodeNameMap = {
|
91
|
+
[Kind.OBJECT_TYPE_DEFINITION]: "type",
|
92
|
+
[Kind.OBJECT_TYPE_EXTENSION]: "type",
|
93
|
+
[Kind.INTERFACE_TYPE_DEFINITION]: "interface",
|
94
|
+
[Kind.INTERFACE_TYPE_EXTENSION]: "interface",
|
95
|
+
[Kind.ENUM_TYPE_DEFINITION]: "enum",
|
96
|
+
[Kind.ENUM_TYPE_EXTENSION]: "enum",
|
97
|
+
[Kind.SCALAR_TYPE_DEFINITION]: "scalar",
|
98
|
+
[Kind.INPUT_OBJECT_TYPE_DEFINITION]: "input",
|
99
|
+
[Kind.INPUT_OBJECT_TYPE_EXTENSION]: "input",
|
100
|
+
[Kind.UNION_TYPE_DEFINITION]: "union",
|
101
|
+
[Kind.UNION_TYPE_EXTENSION]: "union",
|
102
|
+
[Kind.DIRECTIVE_DEFINITION]: "directive",
|
103
|
+
[Kind.FIELD_DEFINITION]: "field",
|
104
|
+
[Kind.ENUM_VALUE_DEFINITION]: "enum value",
|
105
|
+
[Kind.INPUT_VALUE_DEFINITION]: "input value",
|
106
|
+
[Kind.ARGUMENT]: "argument",
|
107
|
+
[Kind.VARIABLE]: "variable",
|
108
|
+
[Kind.FRAGMENT_DEFINITION]: "fragment",
|
109
|
+
[Kind.OPERATION_DEFINITION]: "operation",
|
110
|
+
[Kind.FIELD]: "field"
|
111
|
+
};
|
112
|
+
function displayNodeName(node) {
|
113
|
+
var _a, _b;
|
114
|
+
return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && ((_a = node.alias) == null ? void 0 : _a.value) || "name" in node && ((_b = node.name) == null ? void 0 : _b.value)}"`;
|
115
|
+
}
|
116
|
+
function getNodeName(node) {
|
117
|
+
switch (node.kind) {
|
118
|
+
case Kind.OBJECT_TYPE_DEFINITION:
|
119
|
+
case Kind.OBJECT_TYPE_EXTENSION:
|
120
|
+
case Kind.INTERFACE_TYPE_DEFINITION:
|
121
|
+
case Kind.ENUM_TYPE_DEFINITION:
|
122
|
+
case Kind.SCALAR_TYPE_DEFINITION:
|
123
|
+
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
124
|
+
case Kind.UNION_TYPE_DEFINITION:
|
125
|
+
case Kind.DIRECTIVE_DEFINITION:
|
126
|
+
return displayNodeName(node);
|
127
|
+
case Kind.FIELD_DEFINITION:
|
128
|
+
case Kind.INPUT_VALUE_DEFINITION:
|
129
|
+
case Kind.ENUM_VALUE_DEFINITION:
|
130
|
+
return `${displayNodeName(node)} in ${displayNodeName(node.parent)}`;
|
131
|
+
case Kind.OPERATION_DEFINITION:
|
132
|
+
return node.name ? displayNodeName(node) : node.operation;
|
133
|
+
}
|
134
|
+
return "";
|
135
|
+
}
|
136
|
+
export {
|
137
|
+
ARRAY_DEFAULT_OPTIONS,
|
138
|
+
CWD,
|
139
|
+
REPORT_ON_FIRST_CHARACTER,
|
140
|
+
TYPES_KINDS,
|
141
|
+
VIRTUAL_DOCUMENT_REGEX,
|
142
|
+
camelCase,
|
143
|
+
convertCase,
|
144
|
+
displayNodeName,
|
145
|
+
englishJoinWords,
|
146
|
+
getLocation,
|
147
|
+
getNodeName,
|
148
|
+
getTypeName,
|
149
|
+
logger,
|
150
|
+
normalizePath,
|
151
|
+
pascalCase,
|
152
|
+
requireGraphQLSchemaFromContext,
|
153
|
+
requireSiblingsOperations,
|
154
|
+
truthy
|
155
|
+
};
|
package/package.json
CHANGED
@@ -1,47 +1,60 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "4.0.0-alpha-
|
3
|
+
"version": "4.0.0-alpha-20230801163310-8bc4340",
|
4
4
|
"description": "GraphQL plugin for ESLint",
|
5
|
-
"
|
6
|
-
"
|
7
|
-
|
5
|
+
"repository": "https://github.com/B2o5T/graphql-eslint",
|
6
|
+
"author": "Dotan Simha <dotansimha@gmail.com>",
|
7
|
+
"license": "MIT",
|
8
|
+
"engines": {
|
9
|
+
"node": ">=12"
|
8
10
|
},
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
"
|
13
|
-
"
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
"main": "cjs/index.js",
|
12
|
+
"module": "esm/index.js",
|
13
|
+
"exports": {
|
14
|
+
"./package.json": "./package.json",
|
15
|
+
".": {
|
16
|
+
"require": {
|
17
|
+
"types": "./cjs/index.d.ts",
|
18
|
+
"default": "./cjs/index.js"
|
19
|
+
},
|
20
|
+
"import": {
|
21
|
+
"types": "./esm/index.d.mts",
|
22
|
+
"default": "./esm/index.js"
|
23
|
+
},
|
24
|
+
"default": {
|
25
|
+
"types": "./esm/index.d.mts",
|
26
|
+
"default": "./esm/index.js"
|
27
|
+
}
|
28
|
+
}
|
20
29
|
},
|
21
|
-
"
|
30
|
+
"typings": "esm/index.d.mts",
|
22
31
|
"keywords": [
|
23
32
|
"eslint",
|
24
33
|
"eslintplugin",
|
25
34
|
"eslint-plugin",
|
26
35
|
"graphql"
|
27
36
|
],
|
28
|
-
"
|
29
|
-
|
30
|
-
"main": "index.js",
|
31
|
-
"module": "index.mjs",
|
32
|
-
"typings": "index.d.ts",
|
33
|
-
"typescript": {
|
34
|
-
"definition": "index.d.ts"
|
37
|
+
"peerDependencies": {
|
38
|
+
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
35
39
|
},
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
"
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
"dependencies": {
|
41
|
+
"@graphql-tools/code-file-loader": "^7.3.6",
|
42
|
+
"@graphql-tools/graphql-tag-pluck": "^7.3.6",
|
43
|
+
"@graphql-tools/utils": "^9.0.0",
|
44
|
+
"chalk": "^4.1.2",
|
45
|
+
"debug": "^4.3.4",
|
46
|
+
"fast-glob": "^3.2.12",
|
47
|
+
"graphql-config": "^4.4.0",
|
48
|
+
"graphql-depth-limit": "^1.1.0",
|
49
|
+
"lodash.lowercase": "^4.3.0",
|
50
|
+
"tslib": "^2.4.1"
|
51
|
+
},
|
52
|
+
"publishConfig": {
|
53
|
+
"directory": "dist",
|
54
|
+
"access": "public"
|
55
|
+
},
|
56
|
+
"sideEffects": false,
|
57
|
+
"typescript": {
|
58
|
+
"definition": "cjs/index.d.ts"
|
46
59
|
}
|
47
|
-
}
|
60
|
+
}
|
package/configs/base.json
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": ["./base.json", "./operations-recommended.json"],
|
3
|
-
"rules": {
|
4
|
-
"@graphql-eslint/alphabetize": [
|
5
|
-
"error",
|
6
|
-
{
|
7
|
-
"selections": ["OperationDefinition", "FragmentDefinition"],
|
8
|
-
"variables": ["OperationDefinition"],
|
9
|
-
"arguments": ["Field", "Directive"]
|
10
|
-
}
|
11
|
-
],
|
12
|
-
"@graphql-eslint/match-document-filename": [
|
13
|
-
"error",
|
14
|
-
{
|
15
|
-
"query": "kebab-case",
|
16
|
-
"mutation": "kebab-case",
|
17
|
-
"subscription": "kebab-case",
|
18
|
-
"fragment": "kebab-case"
|
19
|
-
}
|
20
|
-
],
|
21
|
-
"@graphql-eslint/unique-fragment-name": "error",
|
22
|
-
"@graphql-eslint/unique-operation-name": "error"
|
23
|
-
}
|
24
|
-
}
|
package/configs/schema-all.json
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": ["./base.json", "./schema-recommended.json"],
|
3
|
-
"rules": {
|
4
|
-
"@graphql-eslint/alphabetize": [
|
5
|
-
"error",
|
6
|
-
{
|
7
|
-
"fields": [
|
8
|
-
"ObjectTypeDefinition",
|
9
|
-
"InterfaceTypeDefinition",
|
10
|
-
"InputObjectTypeDefinition"
|
11
|
-
],
|
12
|
-
"values": ["EnumTypeDefinition"],
|
13
|
-
"arguments": [
|
14
|
-
"FieldDefinition",
|
15
|
-
"Field",
|
16
|
-
"DirectiveDefinition",
|
17
|
-
"Directive"
|
18
|
-
]
|
19
|
-
}
|
20
|
-
],
|
21
|
-
"@graphql-eslint/input-name": "error",
|
22
|
-
"@graphql-eslint/no-scalar-result-type-on-mutation": "error",
|
23
|
-
"@graphql-eslint/require-deprecation-date": "error",
|
24
|
-
"@graphql-eslint/require-field-of-type-query-in-mutation-result": "error"
|
25
|
-
}
|
26
|
-
}
|
package/docs/README.md
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
## Available Rules
|
2
|
-
|
3
|
-
Each rule has emojis denoting:
|
4
|
-
|
5
|
-
- 🚀 `graphql-eslint` rule
|
6
|
-
- 🔮 `graphql-js` rule
|
7
|
-
- 🔧 if some problems reported by the rule are automatically fixable by the `--fix` [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) option
|
8
|
-
- 💡 if some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)
|
9
|
-
|
10
|
-
<!-- 🚨 IMPORTANT! Do not manually modify this table. Run: `yarn generate:docs` -->
|
11
|
-
<!-- prettier-ignore-start -->
|
12
|
-
Name |Description| Config |🚀 / 🔮|🔧 / 💡
|
13
|
-
-|-|:-:|:-:|:-:
|
14
|
-
[alphabetize](rules/alphabetize.md)|Enforce arrange in alphabetical order for type fields, enum values, input object fields, operation selections and more.|![all][]|🚀|🔧
|
15
|
-
[description-style](rules/description-style.md)|Require all comments to follow the same style (either block or inline).|![recommended][]|🚀|💡
|
16
|
-
[executable-definitions](rules/executable-definitions.md)|A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.|![recommended][]|🔮|
|
17
|
-
[fields-on-correct-type](rules/fields-on-correct-type.md)|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`.|![recommended][]|🔮|
|
18
|
-
[fragments-on-composite-type](rules/fragments-on-composite-type.md)|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.|![recommended][]|🔮|
|
19
|
-
[input-name](rules/input-name.md)|Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".|![all][]|🚀|💡
|
20
|
-
[known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮|
|
21
|
-
[known-directives](rules/known-directives.md)|A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.|![recommended][]|🔮|
|
22
|
-
[known-fragment-names](rules/known-fragment-names.md)|A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.|![recommended][]|🔮|
|
23
|
-
[known-type-names](rules/known-type-names.md)|A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.|![recommended][]|🔮|
|
24
|
-
[lone-anonymous-operation](rules/lone-anonymous-operation.md)|A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.|![recommended][]|🔮|
|
25
|
-
[lone-schema-definition](rules/lone-schema-definition.md)|A GraphQL document is only valid if it contains only one schema definition.|![recommended][]|🔮|
|
26
|
-
[match-document-filename](rules/match-document-filename.md)|This rule allows you to enforce that the file name should match the operation name.|![all][]|🚀|
|
27
|
-
[naming-convention](rules/naming-convention.md)|Require names to follow specified conventions.|![recommended][]|🚀|💡
|
28
|
-
[no-anonymous-operations](rules/no-anonymous-operations.md)|Require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes.|![recommended][]|🚀|💡
|
29
|
-
[no-case-insensitive-enum-values-duplicates](rules/no-case-insensitive-enum-values-duplicates.md)|Disallow case-insensitive enum values duplicates.|![recommended][]|🚀|💡
|
30
|
-
[no-deprecated](rules/no-deprecated.md)|Enforce that deprecated fields or enum values are not in use by operations.|![recommended][]|🚀|💡
|
31
|
-
[no-duplicate-fields](rules/no-duplicate-fields.md)|Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.|![recommended][]|🚀|💡
|
32
|
-
[no-fragment-cycles](rules/no-fragment-cycles.md)|A GraphQL fragment is only valid when it does not have cycles in fragments usage.|![recommended][]|🔮|
|
33
|
-
[no-hashtag-description](rules/no-hashtag-description.md)|Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.|![recommended][]|🚀|💡
|
34
|
-
[no-root-type](rules/no-root-type.md)|Disallow using root types `mutation` and/or `subscription`.||🚀|💡
|
35
|
-
[no-scalar-result-type-on-mutation](rules/no-scalar-result-type-on-mutation.md)|Avoid scalar result type on mutation type to make sure to return a valid state.|![all][]|🚀|💡
|
36
|
-
[no-typename-prefix](rules/no-typename-prefix.md)|Enforces users to avoid using the type name in a field name while defining your schema.|![recommended][]|🚀|💡
|
37
|
-
[no-undefined-variables](rules/no-undefined-variables.md)|A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.|![recommended][]|🔮|
|
38
|
-
[no-unreachable-types](rules/no-unreachable-types.md)|Requires all types to be reachable at some level by root level fields.|![recommended][]|🚀|💡
|
39
|
-
[no-unused-fields](rules/no-unused-fields.md)|Requires all fields to be used at some level by siblings operations.||🚀|💡
|
40
|
-
[no-unused-fragments](rules/no-unused-fragments.md)|A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.|![recommended][]|🔮|
|
41
|
-
[no-unused-variables](rules/no-unused-variables.md)|A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.|![recommended][]|🔮|
|
42
|
-
[one-field-subscriptions](rules/one-field-subscriptions.md)|A GraphQL subscription is valid only if it contains a single root field.|![recommended][]|🔮|
|
43
|
-
[overlapping-fields-can-be-merged](rules/overlapping-fields-can-be-merged.md)|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.|![recommended][]|🔮|
|
44
|
-
[possible-fragment-spread](rules/possible-fragment-spread.md)|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.|![recommended][]|🔮|
|
45
|
-
[possible-type-extension](rules/possible-type-extension.md)|A type extension is only valid if the type is defined and has the same kind.||🔮|
|
46
|
-
[provided-required-arguments](rules/provided-required-arguments.md)|A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.|![recommended][]|🔮|
|
47
|
-
[relay-arguments](rules/relay-arguments.md)|Set of rules to follow Relay specification for Arguments.||🚀|
|
48
|
-
[relay-connection-types](rules/relay-connection-types.md)|Set of rules to follow Relay specification for Connection types.||🚀|
|
49
|
-
[relay-edge-types](rules/relay-edge-types.md)|Set of rules to follow Relay specification for Edge types.||🚀|
|
50
|
-
[relay-page-info](rules/relay-page-info.md)|Set of rules to follow Relay specification for `PageInfo` object.||🚀|
|
51
|
-
[require-deprecation-date](rules/require-deprecation-date.md)|Require deletion date on `@deprecated` directive. Suggest removing deprecated things after deprecated date.|![all][]|🚀|💡
|
52
|
-
[require-deprecation-reason](rules/require-deprecation-reason.md)|Require all deprecation directives to specify a reason.|![recommended][]|🚀|
|
53
|
-
[require-description](rules/require-description.md)|Enforce descriptions in type definitions and operations.|![recommended][]|🚀|
|
54
|
-
[require-field-of-type-query-in-mutation-result](rules/require-field-of-type-query-in-mutation-result.md)|Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.|![all][]|🚀|
|
55
|
-
[require-id-when-available](rules/require-id-when-available.md)|Enforce selecting specific fields when they are available on the GraphQL type.|![recommended][]|🚀|💡
|
56
|
-
[scalar-leafs](rules/scalar-leafs.md)|A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.|![recommended][]|🔮|
|
57
|
-
[selection-set-depth](rules/selection-set-depth.md)|Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).|![recommended][]|🚀|💡
|
58
|
-
[strict-id-in-types](rules/strict-id-in-types.md)|Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.|![recommended][]|🚀|
|
59
|
-
[unique-argument-names](rules/unique-argument-names.md)|A GraphQL field or directive is only valid if all supplied arguments are uniquely named.|![recommended][]|🔮|
|
60
|
-
[unique-directive-names](rules/unique-directive-names.md)|A GraphQL document is only valid if all defined directives have unique names.|![recommended][]|🔮|
|
61
|
-
[unique-directive-names-per-location](rules/unique-directive-names-per-location.md)|A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.|![recommended][]|🔮|
|
62
|
-
[unique-enum-value-names](rules/unique-enum-value-names.md)|A GraphQL enum type is only valid if all its values are uniquely named.||🔮|
|
63
|
-
[unique-field-definition-names](rules/unique-field-definition-names.md)|A GraphQL complex type is only valid if all its fields are uniquely named.|![recommended][]|🔮|
|
64
|
-
[unique-fragment-name](rules/unique-fragment-name.md)|Enforce unique fragment names across your project.|![all][]|🚀|
|
65
|
-
[unique-input-field-names](rules/unique-input-field-names.md)|A GraphQL input object value is only valid if all supplied fields are uniquely named.|![recommended][]|🔮|
|
66
|
-
[unique-operation-name](rules/unique-operation-name.md)|Enforce unique operation names across your project.|![all][]|🚀|
|
67
|
-
[unique-operation-types](rules/unique-operation-types.md)|A GraphQL document is only valid if it has only one type per operation.|![recommended][]|🔮|
|
68
|
-
[unique-type-names](rules/unique-type-names.md)|A GraphQL document is only valid if all defined types have unique names.|![recommended][]|🔮|
|
69
|
-
[unique-variable-names](rules/unique-variable-names.md)|A GraphQL operation is only valid if all its variables are uniquely named.|![recommended][]|🔮|
|
70
|
-
[value-literals-of-correct-type](rules/value-literals-of-correct-type.md)|A GraphQL document is only valid if all value literals are of the type expected at their position.|![recommended][]|🔮|
|
71
|
-
[variables-are-input-types](rules/variables-are-input-types.md)|A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).|![recommended][]|🔮|
|
72
|
-
[variables-in-allowed-position](rules/variables-in-allowed-position.md)|Variables passed to field arguments conform to type.|![recommended][]|🔮|
|
73
|
-
<!-- prettier-ignore-end -->
|
74
|
-
[recommended]: https://img.shields.io/badge/-recommended-green.svg
|
75
|
-
[all]: https://img.shields.io/badge/-all-blue.svg
|
package/docs/custom-rules.md
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# Writing Custom Rules
|
2
|
-
|
3
|
-
To get started with your own rules, start by understanding how [ESLint custom rules works](https://eslint.org/docs/developer-guide/working-with-rules).
|
4
|
-
|
5
|
-
`graphql-eslint` converts the [GraphQL AST](https://graphql.org/graphql-js/language) into [ESTree structure](https://github.com/estree/estree), so it allows you to easily travel the GraphQL AST tree easily.
|
6
|
-
|
7
|
-
You can visit any GraphQL AST node in your custom rules, and report this as error. You don't need to have special handlers for code-files, since `graphql-eslint` extracts usages of `gql` and magic `/* GraphQL */` comments automatically, and runs it through the parser, and eventually it knows to adjust errors location to fit in your code files original location.
|
8
|
-
|
9
|
-
## Getting Started
|
10
|
-
|
11
|
-
Start by creating a [simple ESLint rule file](https://eslint.org/docs/developer-guide/working-with-rules), and choose the AST nodes you wish to visit. It can either be a [simple AST node `Kind`](https://github.com/graphql/graphql-js/blob/master/src/language/kinds.d.ts) or a complex [ESLint selector](https://eslint.org/docs/developer-guide/selectors) that allows you to travel and filter AST nodes.
|
12
|
-
|
13
|
-
We recommend you to read the [graphql-eslint parser documentation](parser.md) before getting started, to understand the differences between the AST structures.
|
14
|
-
|
15
|
-
The `graphql-eslint` comes with a TypeScript wrapper for ESLint rules, and provides a testkit to simplify testing process with GraphQL schemas, so you can use that by importing `GraphQLESLintRule` type. But if you wish to use JavaScript - that's fine :)
|
16
|
-
|
17
|
-
Here's an example for a simple rule that reports on anonymous GraphQL operations:
|
18
|
-
|
19
|
-
```ts
|
20
|
-
import { GraphQLESLintRule } from '@graphql-eslint/eslint-plugin'
|
21
|
-
|
22
|
-
const rule: GraphQLESLintRule = {
|
23
|
-
create(context) {
|
24
|
-
return {
|
25
|
-
OperationDefinition(node) {
|
26
|
-
if (!node.name || !node.name.value) {
|
27
|
-
context.report({
|
28
|
-
node,
|
29
|
-
message: 'Oops, name is required!'
|
30
|
-
})
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
```
|
37
|
-
|
38
|
-
So what happens here?
|
39
|
-
|
40
|
-
1. `@graphql-eslint/eslint-plugin` handles the parsing process for your GraphQL content. It will load the GraphQL files (either from code files or from `.graphql` files with SDL), parse it using GraphQL parser, converts it to ESTree structure and let ESLint do the rest.
|
41
|
-
1. Your rule is being loaded by ESLint, and executes just like any other ESLint rule.
|
42
|
-
1. Our custom rule asks ESLint to run our function for every `OperationDefinition` found.
|
43
|
-
1. If the `OperationDefinition` node doesn't have a valid `name` - we report an error to ESLint.
|
44
|
-
|
45
|
-
#### More Examples
|
46
|
-
|
47
|
-
You can scan the `packages/plugin/src/rules` directory in this repo for references for implementing rules. It coverts most of the use-cases and concepts of rules.
|
48
|
-
|
49
|
-
## Accessing original GraphQL AST nodes
|
50
|
-
|
51
|
-
Since our parser converts GraphQL AST to ESTree structure, there are some minor differences in the structure of the objects.
|
52
|
-
If you are using TypeScript, and you typed your rule with `GraphQLESLintRule` - you'll see that each `node` is a bit different from the AST nodes of GraphQL (you can read more about that in [graphql-eslint parser documentation](parser.md)).
|
53
|
-
|
54
|
-
If you need access to the original GraphQL AST `node`, you can use `.rawNode()` method on each node you get from the AST structure of ESLint.
|
55
|
-
|
56
|
-
This is useful if you wish to use other GraphQL tools that works with the original GraphQL AST objects.
|
57
|
-
|
58
|
-
Here's an example for using original `graphql-js` validate method to validate `OperationDefinition`:
|
59
|
-
|
60
|
-
```ts
|
61
|
-
import { validate } from 'graphql'
|
62
|
-
import { requireGraphQLSchemaFromContext } from '@graphql-eslint/eslint-plugin'
|
63
|
-
|
64
|
-
export const rule = {
|
65
|
-
create(context) {
|
66
|
-
return {
|
67
|
-
OperationDefinition(node) {
|
68
|
-
const schema = requireGraphQLSchemaFromContext(context)
|
69
|
-
|
70
|
-
validate(context, schema, {
|
71
|
-
kind: Kind.DOCUMENT,
|
72
|
-
definitions: [node.rawNode()]
|
73
|
-
})
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
```
|
79
|
-
|
80
|
-
## `TypeInfo` / `GraphQLSchema`
|
81
|
-
|
82
|
-
If you provide GraphQL schema in your ESLint configuration, it will get loaded automatically, and become available in your rules in two ways:
|
83
|
-
|
84
|
-
1. You'll be able to access the loaded `GraphQLSchema` object.
|
85
|
-
2. In every visited node, you'll be able to use `.typeInfo()` method to get an object with complete type information on your visited node (see [TypeInfo documentation](https://graphql.org/graphql-js/utilities/#typeinfo)).
|
86
|
-
|
87
|
-
#### Getting `GraphQLSchema`
|
88
|
-
|
89
|
-
To mark your ESLint rules as a rule that needs access to GraphQL schema, start by running `requireGraphQLSchemaFromContext` from the plugin package, it will make sure to return a schema, or throw an error for the user about the missing schema.
|
90
|
-
|
91
|
-
```ts
|
92
|
-
const schema = requireGraphQLSchemaFromContext(context)
|
93
|
-
```
|
94
|
-
|
95
|
-
#### Accessing TypeInfo
|
96
|
-
|
97
|
-
If schema is provided and loaded successfully, the `typeInfo` will be available to use. Otherwise - it will be `undefined`.
|
98
|
-
If your plugin requires `typeInfo` in order to operate and run, make sure to call `requireGraphQLSchemaFromContext` - it will validate that the schema is loaded.
|
99
|
-
|
100
|
-
`typeInfo` is provided on every node, based on the type of that node, for example, to access the `GraphQLOutputType` while you are visiting a `SelectionSet` node, you can do:
|
101
|
-
|
102
|
-
```ts
|
103
|
-
import { requireGraphQLSchemaFromContext } from '@graphql-eslint/eslint-plugin'
|
104
|
-
|
105
|
-
export const rule = {
|
106
|
-
create(context) {
|
107
|
-
requireGraphQLSchemaFromContext('your-rule-name', context)
|
108
|
-
|
109
|
-
return {
|
110
|
-
SelectionSet(node) {
|
111
|
-
const typeInfo = node.typeInfo()
|
112
|
-
if (typeInfo.gqlType) {
|
113
|
-
console.log(`The GraphQLOutputType is: ${typeInfo.gqlType}`)
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
```
|
120
|
-
|
121
|
-
The structure of the return value of `.typeInfo()` is [defined here](https://github.com/B2o5T/graphql-eslint/blob/master/packages/plugin/src/estree-converter/converter.ts#L32-L40). So based on the `node` you are using, you'll get a different values on `.typeInfo()` result.
|
122
|
-
|
123
|
-
## Testing your rules
|
124
|
-
|
125
|
-
To test your rules, you can either use the wrapped `GraphQLRuleTester` from this library, or use the built-it [`RuleTester`](https://eslint.org/docs/developer-guide/working-with-rules#rule-unit-tests) of ESLint.
|
126
|
-
|
127
|
-
The wrapped `GraphQLRuleTester` provides built-in configured parser, and a schema loader, if you need to test your rule with a loaded schema.
|
128
|
-
|
129
|
-
```ts
|
130
|
-
import { GraphQLRuleTester } from '@graphql-eslint/eslint-plugin'
|
131
|
-
import { rule } from './my-rule'
|
132
|
-
|
133
|
-
const ruleTester = new GraphQLRuleTester()
|
134
|
-
|
135
|
-
ruleTester.runGraphQLTests('my-rule', rule, {
|
136
|
-
valid: [
|
137
|
-
{
|
138
|
-
code: 'query something { foo }'
|
139
|
-
}
|
140
|
-
],
|
141
|
-
invalid: [
|
142
|
-
{
|
143
|
-
code: 'query invalid { foo }',
|
144
|
-
errors: [{ message: 'Your error message.' }],
|
145
|
-
}
|
146
|
-
]
|
147
|
-
})
|
148
|
-
```
|
package/docs/deprecated-rules.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# Deprecated Rules
|
2
|
-
|
3
|
-
## avoid-duplicate-fields
|
4
|
-
|
5
|
-
This rule was renamed to [`no-duplicate-fields`](rules/no-duplicate-fields.md).
|
6
|
-
|
7
|
-
## avoid-scalar-result-type-on-mutation
|
8
|
-
|
9
|
-
This rule was renamed to [`no-scalar-result-type-on-mutation`](rules/no-scalar-result-type-on-mutation.md).
|
10
|
-
|
11
|
-
## avoid-typename-prefix
|
12
|
-
|
13
|
-
This rule was renamed to [`no-typename-prefix`](rules/no-typename-prefix.md).
|
14
|
-
|
15
|
-
## avoid-operation-name-prefix
|
16
|
-
|
17
|
-
This rule was removed because the same things can be validated using [`naming-convention`](rules/naming-convention.md).
|
18
|
-
|
19
|
-
## no-operation-name-suffix
|
20
|
-
|
21
|
-
This rule was removed because the same things can be validated using [`naming-convention`](rules/naming-convention.md).
|