@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810155929-e89edf7
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/cjs/cache.js +10 -19
- package/cjs/configs/index.d.ts +42 -16
- package/cjs/configs/index.js +10 -19
- package/cjs/configs/operations-all.d.ts +4 -3
- package/cjs/configs/operations-all.js +5 -4
- package/cjs/configs/operations-recommended.d.ts +3 -1
- package/cjs/configs/operations-recommended.js +3 -1
- package/cjs/configs/schema-all.d.ts +6 -1
- package/cjs/configs/schema-all.js +5 -2
- package/cjs/configs/schema-recommended.d.ts +19 -1
- package/cjs/configs/schema-recommended.js +22 -2
- package/cjs/documents.js +17 -32
- package/cjs/estree-converter/converter.js +14 -27
- package/cjs/estree-converter/index.js +4 -7
- package/cjs/estree-converter/types.js +3 -5
- package/cjs/estree-converter/utils.d.ts +2 -3
- package/cjs/estree-converter/utils.js +15 -45
- package/cjs/flat-configs.d.ts +59 -12
- package/cjs/flat-configs.js +9 -14
- package/cjs/graphql-config.d.ts +4 -3
- package/cjs/graphql-config.js +23 -44
- package/cjs/index.d.ts +10 -4
- package/cjs/index.js +8 -16
- package/cjs/parser.d.ts +4 -3
- package/cjs/parser.js +38 -45
- package/cjs/processor.d.ts +5 -1
- package/cjs/processor.js +25 -57
- package/cjs/rules/alphabetize.d.ts +6 -16
- package/cjs/rules/alphabetize.js +60 -132
- package/cjs/rules/description-style.d.ts +4 -3
- package/cjs/rules/description-style.js +11 -18
- package/cjs/rules/graphql-js-validation.d.ts +4 -3
- package/cjs/rules/graphql-js-validation.js +151 -225
- package/cjs/rules/index.d.ts +15 -13
- package/cjs/rules/index.js +8 -45
- package/cjs/rules/input-name.d.ts +4 -3
- package/cjs/rules/input-name.js +43 -59
- package/cjs/rules/lone-executable-definition.d.ts +6 -5
- package/cjs/rules/lone-executable-definition.js +14 -28
- package/cjs/rules/match-document-filename.d.ts +4 -3
- package/cjs/rules/match-document-filename.js +39 -70
- package/cjs/rules/naming-convention.d.ts +4 -3
- package/cjs/rules/naming-convention.js +56 -74
- package/cjs/rules/no-anonymous-operations.d.ts +4 -3
- package/cjs/rules/no-anonymous-operations.js +11 -18
- package/cjs/rules/no-deprecated.d.ts +4 -3
- package/cjs/rules/no-deprecated.js +15 -29
- package/cjs/rules/no-duplicate-fields.d.ts +4 -3
- package/cjs/rules/no-duplicate-fields.js +13 -23
- package/cjs/rules/no-hashtag-description.d.ts +4 -3
- package/cjs/rules/no-hashtag-description.js +16 -29
- package/cjs/rules/no-one-place-fragments.d.ts +4 -3
- package/cjs/rules/no-one-place-fragments.js +17 -29
- package/cjs/rules/no-root-type.d.ts +4 -3
- package/cjs/rules/no-root-type.js +15 -25
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
- package/cjs/rules/no-typename-prefix.d.ts +4 -3
- package/cjs/rules/no-typename-prefix.js +26 -33
- package/cjs/rules/no-unreachable-types.d.ts +4 -3
- package/cjs/rules/no-unreachable-types.js +25 -47
- package/cjs/rules/no-unused-fields.d.ts +4 -3
- package/cjs/rules/no-unused-fields.js +24 -49
- package/cjs/rules/relay-arguments.d.ts +4 -3
- package/cjs/rules/relay-arguments.js +20 -43
- package/cjs/rules/relay-connection-types.d.ts +4 -3
- package/cjs/rules/relay-connection-types.js +14 -45
- package/cjs/rules/relay-edge-types.d.ts +4 -3
- package/cjs/rules/relay-edge-types.js +48 -99
- package/cjs/rules/relay-page-info.d.ts +4 -3
- package/cjs/rules/relay-page-info.js +21 -44
- package/cjs/rules/require-deprecation-date.d.ts +4 -3
- package/cjs/rules/require-deprecation-date.js +15 -31
- package/cjs/rules/require-deprecation-reason.d.ts +4 -3
- package/cjs/rules/require-deprecation-reason.js +12 -20
- package/cjs/rules/require-description.d.ts +4 -3
- package/cjs/rules/require-description.js +39 -65
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
- package/cjs/rules/require-import-fragment.d.ts +4 -3
- package/cjs/rules/require-import-fragment.js +22 -40
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
- package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
- package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
- package/cjs/rules/require-nullable-result-in-root.js +34 -44
- package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
- package/cjs/rules/require-selections.js +198 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
- package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
- package/cjs/rules/selection-set-depth.d.ts +4 -3
- package/cjs/rules/selection-set-depth.js +18 -34
- package/cjs/rules/strict-id-in-types.d.ts +4 -3
- package/cjs/rules/strict-id-in-types.js +25 -43
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
- package/cjs/rules/unique-fragment-name.d.ts +3 -2
- package/cjs/rules/unique-fragment-name.js +24 -36
- package/cjs/rules/unique-operation-name.d.ts +4 -3
- package/cjs/rules/unique-operation-name.js +10 -12
- package/cjs/schema.d.ts +4 -3
- package/cjs/schema.js +14 -27
- package/cjs/siblings.d.ts +24 -8
- package/cjs/siblings.js +42 -82
- package/cjs/types.d.ts +74 -7
- package/cjs/types.js +3 -5
- package/cjs/utils.d.ts +3 -2
- package/cjs/utils.js +27 -44
- package/esm/cache.js +4 -8
- package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
- package/esm/configs/index.d.mts +42 -16
- package/esm/configs/index.js +4 -4
- package/esm/configs/operations-all.d.mts +4 -3
- package/esm/configs/operations-all.js +6 -5
- package/esm/configs/operations-recommended.d.mts +3 -1
- package/esm/configs/operations-recommended.js +4 -2
- package/esm/configs/schema-all.d.mts +6 -1
- package/esm/configs/schema-all.js +6 -3
- package/esm/configs/schema-recommended.d.mts +19 -1
- package/esm/configs/schema-recommended.js +23 -3
- package/esm/configs/{relay.js → schema-relay.js} +4 -4
- package/esm/documents.js +10 -17
- package/esm/estree-converter/converter.js +9 -18
- package/esm/estree-converter/utils.d.mts +2 -3
- package/esm/estree-converter/utils.js +11 -38
- package/esm/flat-configs.d.mts +59 -12
- package/esm/flat-configs.js +4 -5
- package/esm/graphql-config.d.mts +4 -3
- package/esm/graphql-config.js +18 -34
- package/esm/index.d.mts +10 -4
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +4 -3
- package/esm/parser.js +33 -27
- package/esm/processor.d.mts +5 -1
- package/esm/processor.js +21 -46
- package/esm/rules/alphabetize.d.mts +6 -16
- package/esm/rules/alphabetize.js +53 -118
- package/esm/rules/description-style.d.mts +4 -3
- package/esm/rules/description-style.js +7 -11
- package/esm/rules/graphql-js-validation.d.mts +4 -3
- package/esm/rules/graphql-js-validation.js +178 -218
- package/esm/rules/index.d.mts +15 -13
- package/esm/rules/index.js +5 -5
- package/esm/rules/input-name.d.mts +4 -3
- package/esm/rules/input-name.js +39 -52
- package/esm/rules/lone-executable-definition.d.mts +6 -5
- package/esm/rules/lone-executable-definition.js +10 -20
- package/esm/rules/match-document-filename.d.mts +4 -3
- package/esm/rules/match-document-filename.js +35 -61
- package/esm/rules/naming-convention.d.mts +4 -3
- package/esm/rules/naming-convention.js +51 -65
- package/esm/rules/no-anonymous-operations.d.mts +4 -3
- package/esm/rules/no-anonymous-operations.js +6 -9
- package/esm/rules/no-deprecated.d.mts +4 -3
- package/esm/rules/no-deprecated.js +10 -20
- package/esm/rules/no-duplicate-fields.d.mts +4 -3
- package/esm/rules/no-duplicate-fields.js +9 -16
- package/esm/rules/no-hashtag-description.d.mts +4 -3
- package/esm/rules/no-hashtag-description.js +11 -20
- package/esm/rules/no-one-place-fragments.d.mts +4 -3
- package/esm/rules/no-one-place-fragments.js +12 -19
- package/esm/rules/no-root-type.d.mts +4 -3
- package/esm/rules/no-root-type.js +11 -18
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
- package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
- package/esm/rules/no-typename-prefix.d.mts +4 -3
- package/esm/rules/no-typename-prefix.js +22 -26
- package/esm/rules/no-unreachable-types.d.mts +4 -3
- package/esm/rules/no-unreachable-types.js +18 -33
- package/esm/rules/no-unused-fields.d.mts +4 -3
- package/esm/rules/no-unused-fields.js +19 -40
- package/esm/rules/relay-arguments.d.mts +4 -3
- package/esm/rules/relay-arguments.js +15 -34
- package/esm/rules/relay-connection-types.d.mts +4 -3
- package/esm/rules/relay-connection-types.js +10 -38
- package/esm/rules/relay-edge-types.d.mts +4 -3
- package/esm/rules/relay-edge-types.js +43 -89
- package/esm/rules/relay-page-info.d.mts +4 -3
- package/esm/rules/relay-page-info.js +16 -34
- package/esm/rules/require-deprecation-date.d.mts +4 -3
- package/esm/rules/require-deprecation-date.js +10 -22
- package/esm/rules/require-deprecation-reason.d.mts +4 -3
- package/esm/rules/require-deprecation-reason.js +7 -11
- package/esm/rules/require-description.d.mts +4 -3
- package/esm/rules/require-description.js +34 -55
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
- package/esm/rules/require-import-fragment.d.mts +4 -3
- package/esm/rules/require-import-fragment.js +14 -26
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
- package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
- package/esm/rules/require-nullable-result-in-root.js +29 -35
- package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
- package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
- package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
- package/esm/rules/require-type-pattern-with-oneof.js +11 -16
- package/esm/rules/selection-set-depth.d.mts +4 -3
- package/esm/rules/selection-set-depth.js +11 -20
- package/esm/rules/strict-id-in-types.d.mts +4 -3
- package/esm/rules/strict-id-in-types.js +20 -34
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
- package/esm/rules/unique-fragment-name.d.mts +3 -2
- package/esm/rules/unique-fragment-name.js +20 -27
- package/esm/rules/unique-operation-name.d.mts +4 -3
- package/esm/rules/unique-operation-name.js +6 -5
- package/esm/schema.d.mts +4 -3
- package/esm/schema.js +7 -12
- package/esm/siblings.d.mts +24 -8
- package/esm/siblings.js +37 -73
- package/esm/types.d.mts +74 -7
- package/esm/utils.d.mts +3 -2
- package/esm/utils.js +20 -31
- package/index.browser.mjs +5323 -0
- package/package.json +8 -13
- package/cjs/rules/require-id-when-available.js +0 -241
- package/cjs/types-8d5f4ae0.d.ts +0 -107
- package/esm/types-ace77d86.d.ts +0 -107
- /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
- /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
- /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
@@ -1,14 +1,14 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { checkNode } from "./unique-fragment-name.js";
|
3
|
-
const RULE_ID = "unique-operation-name"
|
4
|
-
const rule = {
|
3
|
+
const RULE_ID = "unique-operation-name", rule = {
|
5
4
|
meta: {
|
6
5
|
type: "suggestion",
|
7
6
|
docs: {
|
8
7
|
category: "Operations",
|
9
8
|
description: "Enforce unique operation names across your project.",
|
10
9
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
11
|
-
requiresSiblings:
|
10
|
+
requiresSiblings: !0,
|
11
|
+
recommended: !0,
|
12
12
|
examples: [
|
13
13
|
{
|
14
14
|
title: "Incorrect",
|
@@ -55,7 +55,8 @@ const rule = {
|
|
55
55
|
]
|
56
56
|
},
|
57
57
|
messages: {
|
58
|
-
[RULE_ID]:
|
58
|
+
[RULE_ID]: `Operation named "{{ documentName }}" already defined in:
|
59
|
+
{{ summary }}`
|
59
60
|
},
|
60
61
|
schema: []
|
61
62
|
},
|
package/esm/schema.d.mts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
import { GraphQLProjectConfig } from 'graphql-config';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { Schema } from './types.mjs';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
6
|
import 'json-schema-to-ts';
|
7
|
+
import './siblings.mjs';
|
8
|
+
import '@graphql-tools/utils';
|
8
9
|
import './estree-converter/types.mjs';
|
9
10
|
|
10
|
-
declare function getSchema(project: GraphQLProjectConfig
|
11
|
+
declare function getSchema(project: GraphQLProjectConfig): Schema;
|
11
12
|
|
12
13
|
export { getSchema };
|
package/esm/schema.js
CHANGED
@@ -1,31 +1,26 @@
|
|
1
|
-
import "./chunk-
|
1
|
+
import "./chunk-U3TKCM4X.js";
|
2
2
|
import debugFactory from "debug";
|
3
3
|
import fg from "fast-glob";
|
4
4
|
import { GraphQLSchema } from "graphql";
|
5
5
|
import { ModuleCache } from "./cache.js";
|
6
|
-
const schemaCache = new ModuleCache();
|
7
|
-
|
8
|
-
function getSchema(project, schemaOptions) {
|
6
|
+
const schemaCache = new ModuleCache(), debug = debugFactory("graphql-eslint:schema");
|
7
|
+
function getSchema(project) {
|
9
8
|
const schemaKey = project.schema;
|
10
|
-
if (!schemaKey)
|
9
|
+
if (!schemaKey)
|
11
10
|
return null;
|
12
|
-
}
|
13
11
|
const cache = schemaCache.get(schemaKey);
|
14
|
-
if (cache)
|
12
|
+
if (cache)
|
15
13
|
return cache;
|
16
|
-
}
|
17
14
|
debug("Loading schema from %o", project.schema);
|
18
15
|
const schema = project.loadSchemaSync(project.schema, "GraphQLSchema", {
|
19
|
-
...schemaOptions,
|
20
16
|
pluckConfig: project.extensions.pluckConfig
|
21
17
|
});
|
22
18
|
if (debug.enabled) {
|
23
19
|
debug("Schema loaded: %o", schema instanceof GraphQLSchema);
|
24
|
-
const schemaPaths = fg.sync(project.schema, { absolute:
|
20
|
+
const schemaPaths = fg.sync(project.schema, { absolute: !0 });
|
25
21
|
debug("Schema pointers %O", schemaPaths);
|
26
22
|
}
|
27
|
-
schemaCache.set(schemaKey, schema);
|
28
|
-
return schema;
|
23
|
+
return schemaCache.set(schemaKey, schema), schema;
|
29
24
|
}
|
30
25
|
export {
|
31
26
|
getSchema
|
package/esm/siblings.d.mts
CHANGED
@@ -1,8 +1,24 @@
|
|
1
|
-
import 'graphql';
|
2
|
-
import 'graphql
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
import { Source } from '@graphql-tools/utils';
|
2
|
+
import { FragmentDefinitionNode, OperationDefinitionNode, SelectionSetNode, OperationTypeNode } from 'graphql';
|
3
|
+
|
4
|
+
type FragmentSource = {
|
5
|
+
filePath: string;
|
6
|
+
document: FragmentDefinitionNode;
|
7
|
+
};
|
8
|
+
type OperationSource = {
|
9
|
+
filePath: string;
|
10
|
+
document: OperationDefinitionNode;
|
11
|
+
};
|
12
|
+
type SiblingOperations = {
|
13
|
+
available: boolean;
|
14
|
+
getFragment(fragmentName: string): FragmentSource[];
|
15
|
+
getFragments(): FragmentSource[];
|
16
|
+
getFragmentByType(typeName: string): FragmentSource[];
|
17
|
+
getFragmentsInUse(baseOperation: FragmentDefinitionNode | OperationDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
|
18
|
+
getOperation(operationName: string): OperationSource[];
|
19
|
+
getOperations(): OperationSource[];
|
20
|
+
getOperationByType(operationType: OperationTypeNode): OperationSource[];
|
21
|
+
};
|
22
|
+
declare function getSiblings(documents: Source[]): SiblingOperations;
|
23
|
+
|
24
|
+
export { FragmentSource, OperationSource, SiblingOperations, getSiblings };
|
package/esm/siblings.js
CHANGED
@@ -1,27 +1,18 @@
|
|
1
|
-
import "./chunk-
|
2
|
-
import { parseGraphQLSDL } from "@graphql-tools/utils";
|
1
|
+
import "./chunk-U3TKCM4X.js";
|
3
2
|
import {
|
4
3
|
Kind,
|
5
4
|
visit
|
6
5
|
} from "graphql";
|
7
|
-
import { getDocuments } from "./documents.js";
|
8
6
|
import { logger } from "./utils.js";
|
9
7
|
const siblingOperationsCache = /* @__PURE__ */ new Map();
|
10
|
-
function getSiblings(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
logger.warn(
|
17
|
-
'getSiblingOperations was called without any operations. Make sure to set "parserOptions.operations" to make this feature available!'
|
18
|
-
);
|
19
|
-
printed = true;
|
20
|
-
}
|
21
|
-
return [];
|
22
|
-
};
|
8
|
+
function getSiblings(documents) {
|
9
|
+
if (documents.length === 0) {
|
10
|
+
let printed = !1;
|
11
|
+
const noopWarn = () => (printed || (logger.warn(
|
12
|
+
"getSiblingOperations was called without any operations. Make sure to set graphql-config `documents` field to make this feature available! See https://the-guild.dev/graphql/config/docs/user/documents for more info"
|
13
|
+
), printed = !0), []);
|
23
14
|
return {
|
24
|
-
available:
|
15
|
+
available: !1,
|
25
16
|
getFragment: noopWarn,
|
26
17
|
getFragments: noopWarn,
|
27
18
|
getFragmentByType: noopWarn,
|
@@ -31,85 +22,58 @@ function getSiblings(project, documents) {
|
|
31
22
|
getOperationByType: noopWarn
|
32
23
|
};
|
33
24
|
}
|
34
|
-
const value = siblingOperationsCache.get(
|
35
|
-
if (value)
|
25
|
+
const value = siblingOperationsCache.get(documents);
|
26
|
+
if (value)
|
36
27
|
return value;
|
37
|
-
}
|
38
28
|
let fragmentsCache = null;
|
39
29
|
const getFragments = () => {
|
40
|
-
var _a;
|
41
30
|
if (fragmentsCache === null) {
|
42
31
|
const result = [];
|
43
|
-
for (const source of
|
44
|
-
for (const definition of
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
});
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
32
|
+
for (const source of documents)
|
33
|
+
for (const definition of source.document?.definitions || [])
|
34
|
+
definition.kind === Kind.FRAGMENT_DEFINITION && result.push({
|
35
|
+
filePath: source.location,
|
36
|
+
document: definition
|
37
|
+
});
|
53
38
|
fragmentsCache = result;
|
54
39
|
}
|
55
40
|
return fragmentsCache;
|
56
41
|
};
|
57
42
|
let cachedOperations = null;
|
58
43
|
const getOperations = () => {
|
59
|
-
var _a;
|
60
44
|
if (cachedOperations === null) {
|
61
45
|
const result = [];
|
62
|
-
for (const source of
|
63
|
-
for (const definition of
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
});
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
46
|
+
for (const source of documents)
|
47
|
+
for (const definition of source.document?.definitions || [])
|
48
|
+
definition.kind === Kind.OPERATION_DEFINITION && result.push({
|
49
|
+
filePath: source.location,
|
50
|
+
document: definition
|
51
|
+
});
|
72
52
|
cachedOperations = result;
|
73
53
|
}
|
74
54
|
return cachedOperations;
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
logger.warn(
|
84
|
-
`Unable to locate fragment named "${fragmentName}", please make sure it's loaded using "parserOptions.operations"`
|
85
|
-
);
|
86
|
-
return;
|
87
|
-
}
|
88
|
-
if (!collected.has(fragmentName)) {
|
89
|
-
collected.set(fragmentName, fragment.document);
|
90
|
-
if (recursive) {
|
91
|
-
collectFragments(fragment.document, recursive, collected);
|
92
|
-
}
|
93
|
-
}
|
55
|
+
}, getFragment = (name) => getFragments().filter((f) => f.document.name.value === name), collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => (visit(selectable, {
|
56
|
+
FragmentSpread(spread) {
|
57
|
+
const fragmentName = spread.name.value, [fragment] = getFragment(fragmentName);
|
58
|
+
if (!fragment) {
|
59
|
+
logger.warn(
|
60
|
+
`Unable to locate fragment named "${fragmentName}", please make sure it's loaded using "parserOptions.operations"`
|
61
|
+
);
|
62
|
+
return;
|
94
63
|
}
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
available: true,
|
64
|
+
collected.has(fragmentName) || (collected.set(fragmentName, fragment.document), recursive && collectFragments(fragment.document, recursive, collected));
|
65
|
+
}
|
66
|
+
}), collected), siblingOperations = {
|
67
|
+
available: !0,
|
100
68
|
getFragment,
|
101
69
|
getFragments,
|
102
70
|
getFragmentByType: (typeName) => getFragments().filter((f) => f.document.typeCondition.name.value === typeName),
|
103
|
-
getFragmentsInUse: (selectable, recursive =
|
104
|
-
getOperation: (name) => getOperations().filter((o) =>
|
105
|
-
var _a;
|
106
|
-
return ((_a = o.document.name) == null ? void 0 : _a.value) === name;
|
107
|
-
}),
|
71
|
+
getFragmentsInUse: (selectable, recursive = !0) => Array.from(collectFragments(selectable, recursive).values()),
|
72
|
+
getOperation: (name) => getOperations().filter((o) => o.document.name?.value === name),
|
108
73
|
getOperations,
|
109
74
|
getOperationByType: (type) => getOperations().filter((o) => o.document.operation === type)
|
110
75
|
};
|
111
|
-
siblingOperationsCache.set(
|
112
|
-
return siblingOperations;
|
76
|
+
return siblingOperationsCache.set(documents, siblingOperations), siblingOperations;
|
113
77
|
}
|
114
78
|
export {
|
115
79
|
getSiblings
|
package/esm/types.d.mts
CHANGED
@@ -1,8 +1,75 @@
|
|
1
|
+
import { Linter, Rule, AST } from 'eslint';
|
2
|
+
import * as ESTree from 'estree';
|
3
|
+
import { GraphQLSchema, ASTKindToNode } from 'graphql';
|
4
|
+
import { JSONSchema } from 'json-schema-to-ts';
|
5
|
+
import { SiblingOperations } from './siblings.mjs';
|
6
|
+
import { GraphQLESTreeNode } from './estree-converter/types.mjs';
|
7
|
+
import { IGraphQLConfig } from 'graphql-config';
|
1
8
|
import '@graphql-tools/utils';
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
|
10
|
+
type Schema = GraphQLSchema | null;
|
11
|
+
type Pointer = string | string[];
|
12
|
+
interface ParserOptions {
|
13
|
+
graphQLConfig?: IGraphQLConfig;
|
14
|
+
filePath: string;
|
15
|
+
}
|
16
|
+
type ParserServices = {
|
17
|
+
schema: Schema;
|
18
|
+
siblingOperations: SiblingOperations;
|
19
|
+
};
|
20
|
+
type GraphQLESLintParseResult = Linter.ESLintParseResult & {
|
21
|
+
services: ParserServices;
|
22
|
+
};
|
23
|
+
type Location = AST.SourceLocation | ESTree.Position;
|
24
|
+
type ReportDescriptorLocation = {
|
25
|
+
loc: Location;
|
26
|
+
} | {
|
27
|
+
node: {
|
28
|
+
loc: Location;
|
29
|
+
};
|
30
|
+
};
|
31
|
+
type ReportDescriptor = ReportDescriptorLocation & Rule.ReportDescriptorMessage & Rule.ReportDescriptorOptions;
|
32
|
+
type GraphQLESLintRuleContext<Options = any[]> = Omit<Rule.RuleContext, 'options' | 'parserServices' | 'report'> & {
|
33
|
+
options: Options;
|
34
|
+
parserServices: ParserServices;
|
35
|
+
report(descriptor: ReportDescriptor): void;
|
36
|
+
};
|
37
|
+
type CategoryType = 'Operations' | 'Schema';
|
38
|
+
type RuleMetaDataDocs = Required<Rule.RuleMetaData>['docs'];
|
39
|
+
type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & {
|
40
|
+
category: CategoryType | CategoryType[];
|
41
|
+
requiresSchema?: true;
|
42
|
+
requiresSiblings?: true;
|
43
|
+
examples?: {
|
44
|
+
title: string;
|
45
|
+
code: string;
|
46
|
+
usage?: T;
|
47
|
+
}[];
|
48
|
+
configOptions?: T | {
|
49
|
+
schema?: T;
|
50
|
+
operations?: T;
|
51
|
+
};
|
52
|
+
graphQLJSRuleName?: string;
|
53
|
+
isDisabledForAllConfig?: true;
|
54
|
+
};
|
55
|
+
type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
|
56
|
+
[K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
|
57
|
+
};
|
58
|
+
type GraphQLESLintRule<Options = [], WithTypeInfo extends boolean = false> = {
|
59
|
+
meta: Omit<Rule.RuleMetaData, 'docs' | 'schema'> & {
|
60
|
+
docs?: RuleDocsInfo<Options>;
|
61
|
+
schema: Readonly<JSONSchema> | [];
|
62
|
+
};
|
63
|
+
create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
|
64
|
+
};
|
65
|
+
type ValueOf<T> = T[keyof T];
|
66
|
+
type Id<T> = {
|
67
|
+
[P in keyof T]: T[P];
|
68
|
+
} & {};
|
69
|
+
type OmitDistributive<T, K extends PropertyKey> = T extends object ? Id<OmitRecursively<T, K>> : T;
|
70
|
+
type OmitRecursively<T extends object, K extends PropertyKey> = Omit<{
|
71
|
+
[P in keyof T]: OmitDistributive<T[P], K>;
|
72
|
+
}, K>;
|
73
|
+
type ConfigName = 'operations-all' | 'operations-recommended' | 'schema-all' | 'schema-recommended' | 'schema-relay';
|
74
|
+
|
75
|
+
export { CategoryType, ConfigName, GraphQLESLintParseResult, GraphQLESLintRule, GraphQLESLintRuleContext, GraphQLESLintRuleListener, OmitRecursively, ParserOptions, ParserServices, Pointer, ReportDescriptor, RuleDocsInfo, Schema, ValueOf };
|
package/esm/utils.d.mts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import { AST } from 'eslint';
|
2
2
|
import { Position } from 'estree';
|
3
3
|
import { GraphQLSchema, ASTNode, Kind } from 'graphql';
|
4
|
-
import {
|
4
|
+
import { SiblingOperations } from './siblings.mjs';
|
5
|
+
import { GraphQLESLintRuleContext } from './types.mjs';
|
5
6
|
import { GraphQLESTreeNode } from './estree-converter/types.mjs';
|
6
7
|
import '@graphql-tools/utils';
|
7
|
-
import 'graphql-config';
|
8
8
|
import 'json-schema-to-ts';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare function requireSiblingsOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
|
11
12
|
declare function requireGraphQLSchemaFromContext(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
|
package/esm/utils.js
CHANGED
@@ -1,53 +1,45 @@
|
|
1
|
-
import "./chunk-
|
2
|
-
import chalk from "chalk";
|
1
|
+
import "./chunk-U3TKCM4X.js";
|
3
2
|
import { Kind } from "graphql";
|
4
3
|
import lowerCase from "lodash.lowercase";
|
5
4
|
function requireSiblingsOperations(ruleId, context) {
|
6
|
-
const { siblingOperations } = context.parserServices;
|
7
|
-
if (!siblingOperations.available)
|
5
|
+
const { siblingOperations } = context.sourceCode.parserServices;
|
6
|
+
if (!siblingOperations.available)
|
8
7
|
throw new Error(
|
9
|
-
`Rule \`${ruleId}\` requires \`
|
8
|
+
`Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/config/docs/user/documents for more info`
|
10
9
|
);
|
11
|
-
}
|
12
10
|
return siblingOperations;
|
13
11
|
}
|
14
12
|
function requireGraphQLSchemaFromContext(ruleId, context) {
|
15
|
-
const { schema } = context.parserServices;
|
16
|
-
if (!schema)
|
13
|
+
const { schema } = context.sourceCode.parserServices;
|
14
|
+
if (!schema)
|
17
15
|
throw new Error(
|
18
|
-
`Rule \`${ruleId}\` requires \`
|
16
|
+
`Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/config/docs/user/schema for more info`
|
19
17
|
);
|
20
|
-
}
|
21
18
|
return schema;
|
22
19
|
}
|
23
|
-
const
|
20
|
+
const chalk = {
|
21
|
+
red: (str) => `\x1B[31m${str}\x1B[39m`,
|
22
|
+
yellow: (str) => `\x1B[33m${str}\x1B[39m`
|
23
|
+
}, logger = {
|
24
24
|
error: (...args) => (
|
25
25
|
// eslint-disable-next-line no-console
|
26
|
-
console.error(chalk.red("error"), "[graphql-eslint]",
|
26
|
+
console.error(chalk.red("error"), "[graphql-eslint]", ...args)
|
27
27
|
),
|
28
28
|
warn: (...args) => (
|
29
29
|
// eslint-disable-next-line no-console
|
30
|
-
console.warn(chalk.yellow("warning"), "[graphql-eslint]",
|
30
|
+
console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
|
31
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 = [
|
32
|
+
}, normalizePath = (path) => (path || "").replace(/\\/g, "/"), 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 = [
|
38
33
|
Kind.OBJECT_TYPE_DEFINITION,
|
39
34
|
Kind.INTERFACE_TYPE_DEFINITION,
|
40
35
|
Kind.ENUM_TYPE_DEFINITION,
|
41
36
|
Kind.SCALAR_TYPE_DEFINITION,
|
42
37
|
Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
43
38
|
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) => {
|
39
|
+
], pascalCase = (str) => lowerCase(str).split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(""), camelCase = (str) => {
|
47
40
|
const result = pascalCase(str);
|
48
41
|
return result.charAt(0).toLowerCase() + result.slice(1);
|
49
|
-
}
|
50
|
-
const convertCase = (style, str) => {
|
42
|
+
}, convertCase = (style, str) => {
|
51
43
|
switch (style) {
|
52
44
|
case "camelCase":
|
53
45
|
return camelCase(str);
|
@@ -74,16 +66,14 @@ function getLocation(start, fieldName = "") {
|
|
74
66
|
}
|
75
67
|
};
|
76
68
|
}
|
77
|
-
const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 }
|
78
|
-
const ARRAY_DEFAULT_OPTIONS = {
|
69
|
+
const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 }, ARRAY_DEFAULT_OPTIONS = {
|
79
70
|
type: "array",
|
80
|
-
uniqueItems:
|
71
|
+
uniqueItems: !0,
|
81
72
|
minItems: 1,
|
82
73
|
items: {
|
83
74
|
type: "string"
|
84
75
|
}
|
85
|
-
};
|
86
|
-
const englishJoinWords = (words) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(words);
|
76
|
+
}, englishJoinWords = (words) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(words);
|
87
77
|
function truthy(value) {
|
88
78
|
return !!value;
|
89
79
|
}
|
@@ -110,8 +100,7 @@ const DisplayNodeNameMap = {
|
|
110
100
|
[Kind.FIELD]: "field"
|
111
101
|
};
|
112
102
|
function displayNodeName(node) {
|
113
|
-
|
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)}"`;
|
103
|
+
return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value}"`;
|
115
104
|
}
|
116
105
|
function getNodeName(node) {
|
117
106
|
switch (node.kind) {
|