@graphql-eslint/eslint-plugin 4.3.0-alpha-20241205065956-601947f40654914ef0effc1cdf4fe269245fc7bc → 4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561

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.
Files changed (110) hide show
  1. package/cjs/cache.js +6 -2
  2. package/cjs/configs/operations-all.js +2 -2
  3. package/cjs/configs/schema-all.js +2 -2
  4. package/cjs/configs/schema-recommended.js +1 -1
  5. package/cjs/documents.js +13 -7
  6. package/cjs/estree-converter/converter.js +17 -8
  7. package/cjs/estree-converter/utils.js +22 -9
  8. package/cjs/graphql-config.js +13 -6
  9. package/cjs/index.d.cts +18 -4
  10. package/cjs/meta.js +1 -1
  11. package/cjs/parser.js +36 -9
  12. package/cjs/processor.js +48 -20
  13. package/cjs/rules/alphabetize/index.js +99 -47
  14. package/cjs/rules/description-style/index.js +10 -6
  15. package/cjs/rules/graphql-js-validation.js +142 -108
  16. package/cjs/rules/index.d.cts +18 -4
  17. package/cjs/rules/input-name/index.js +51 -38
  18. package/cjs/rules/lone-executable-definition/index.js +15 -6
  19. package/cjs/rules/match-document-filename/index.d.cts +4 -3
  20. package/cjs/rules/match-document-filename/index.js +63 -37
  21. package/cjs/rules/naming-convention/index.d.cts +6 -10
  22. package/cjs/rules/naming-convention/index.js +146 -57
  23. package/cjs/rules/no-anonymous-operations/index.js +8 -5
  24. package/cjs/rules/no-deprecated/index.js +27 -13
  25. package/cjs/rules/no-duplicate-fields/index.js +15 -8
  26. package/cjs/rules/no-hashtag-description/index.js +18 -10
  27. package/cjs/rules/no-one-place-fragments/index.js +17 -10
  28. package/cjs/rules/no-root-type/index.js +15 -8
  29. package/cjs/rules/no-scalar-result-type-on-mutation/index.js +20 -12
  30. package/cjs/rules/no-typename-prefix/index.js +25 -21
  31. package/cjs/rules/no-unreachable-types/index.js +34 -17
  32. package/cjs/rules/no-unused-fields/index.js +56 -30
  33. package/cjs/rules/relay-arguments/index.js +31 -13
  34. package/cjs/rules/relay-connection-types/index.js +31 -9
  35. package/cjs/rules/relay-edge-types/index.js +84 -41
  36. package/cjs/rules/relay-page-info/index.js +31 -14
  37. package/cjs/rules/require-deprecation-date/index.js +20 -9
  38. package/cjs/rules/require-deprecation-reason/index.js +8 -5
  39. package/cjs/rules/require-description/index.d.cts +79 -13
  40. package/cjs/rules/require-description/index.js +67 -49
  41. package/cjs/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
  42. package/cjs/rules/require-import-fragment/index.js +20 -11
  43. package/cjs/rules/require-nullable-fields-with-oneof/index.js +12 -5
  44. package/cjs/rules/require-nullable-result-in-root/index.js +32 -27
  45. package/cjs/rules/require-selections/index.js +88 -46
  46. package/cjs/rules/require-type-pattern-with-oneof/index.js +14 -10
  47. package/cjs/rules/selection-set-depth/index.js +19 -10
  48. package/cjs/rules/strict-id-in-types/index.js +32 -19
  49. package/cjs/rules/unique-enum-value-names/index.js +4 -3
  50. package/cjs/rules/unique-fragment-name/index.js +25 -18
  51. package/cjs/rules/unique-operation-name/index.js +5 -5
  52. package/cjs/schema.js +14 -8
  53. package/cjs/siblings.js +60 -32
  54. package/cjs/utils.js +23 -9
  55. package/esm/cache.js +6 -2
  56. package/esm/configs/operations-all.js +2 -2
  57. package/esm/configs/schema-all.js +2 -2
  58. package/esm/configs/schema-recommended.js +1 -1
  59. package/esm/documents.js +13 -7
  60. package/esm/estree-converter/converter.js +17 -8
  61. package/esm/estree-converter/utils.js +22 -9
  62. package/esm/graphql-config.js +13 -6
  63. package/esm/index.d.ts +19 -5
  64. package/esm/meta.js +1 -1
  65. package/esm/parser.js +36 -9
  66. package/esm/processor.js +48 -20
  67. package/esm/rules/alphabetize/index.js +99 -47
  68. package/esm/rules/description-style/index.js +10 -6
  69. package/esm/rules/graphql-js-validation.js +142 -108
  70. package/esm/rules/index.d.ts +19 -5
  71. package/esm/rules/input-name/index.js +51 -38
  72. package/esm/rules/lone-executable-definition/index.js +15 -6
  73. package/esm/rules/match-document-filename/index.d.ts +4 -3
  74. package/esm/rules/match-document-filename/index.js +63 -37
  75. package/esm/rules/naming-convention/index.d.ts +6 -10
  76. package/esm/rules/naming-convention/index.js +146 -57
  77. package/esm/rules/no-anonymous-operations/index.js +8 -5
  78. package/esm/rules/no-deprecated/index.js +27 -13
  79. package/esm/rules/no-duplicate-fields/index.js +15 -8
  80. package/esm/rules/no-hashtag-description/index.js +18 -10
  81. package/esm/rules/no-one-place-fragments/index.js +17 -10
  82. package/esm/rules/no-root-type/index.js +15 -8
  83. package/esm/rules/no-scalar-result-type-on-mutation/index.js +20 -12
  84. package/esm/rules/no-typename-prefix/index.js +25 -21
  85. package/esm/rules/no-unreachable-types/index.js +34 -17
  86. package/esm/rules/no-unused-fields/index.js +56 -30
  87. package/esm/rules/relay-arguments/index.js +31 -13
  88. package/esm/rules/relay-connection-types/index.js +31 -9
  89. package/esm/rules/relay-edge-types/index.js +84 -41
  90. package/esm/rules/relay-page-info/index.js +31 -14
  91. package/esm/rules/require-deprecation-date/index.js +20 -9
  92. package/esm/rules/require-deprecation-reason/index.js +8 -5
  93. package/esm/rules/require-description/index.d.ts +79 -13
  94. package/esm/rules/require-description/index.js +67 -49
  95. package/esm/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
  96. package/esm/rules/require-import-fragment/index.js +20 -11
  97. package/esm/rules/require-nullable-fields-with-oneof/index.js +12 -5
  98. package/esm/rules/require-nullable-result-in-root/index.js +32 -27
  99. package/esm/rules/require-selections/index.js +88 -46
  100. package/esm/rules/require-type-pattern-with-oneof/index.js +14 -10
  101. package/esm/rules/selection-set-depth/index.js +19 -10
  102. package/esm/rules/strict-id-in-types/index.js +32 -19
  103. package/esm/rules/unique-enum-value-names/index.js +4 -3
  104. package/esm/rules/unique-fragment-name/index.js +25 -18
  105. package/esm/rules/unique-operation-name/index.js +5 -5
  106. package/esm/schema.js +15 -8
  107. package/esm/siblings.js +60 -32
  108. package/esm/utils.js +23 -9
  109. package/index.browser.js +1838 -1135
  110. package/package.json +1 -1
package/esm/siblings.js CHANGED
@@ -6,12 +6,18 @@ import { logger } from "./utils.js";
6
6
  const siblingOperationsCache = /* @__PURE__ */ new Map();
7
7
  function getSiblings(documents) {
8
8
  if (documents.length === 0) {
9
- let printed = !1;
10
- const noopWarn = () => (printed || (logger.warn(
11
- "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"
12
- ), printed = !0), []);
9
+ let printed = false;
10
+ const noopWarn = () => {
11
+ if (!printed) {
12
+ logger.warn(
13
+ "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"
14
+ );
15
+ printed = true;
16
+ }
17
+ return [];
18
+ };
13
19
  return {
14
- available: !1,
20
+ available: false,
15
21
  getFragment: noopWarn,
16
22
  getFragments: noopWarn,
17
23
  getFragmentByType: noopWarn,
@@ -22,18 +28,23 @@ function getSiblings(documents) {
22
28
  };
23
29
  }
24
30
  const value = siblingOperationsCache.get(documents);
25
- if (value)
31
+ if (value) {
26
32
  return value;
33
+ }
27
34
  let fragmentsCache = null;
28
35
  const getFragments = () => {
29
36
  if (fragmentsCache === null) {
30
37
  const result = [];
31
- for (const source of documents)
32
- for (const definition of source.document?.definitions || [])
33
- definition.kind === Kind.FRAGMENT_DEFINITION && result.push({
34
- filePath: source.location,
35
- document: definition
36
- });
38
+ for (const source of documents) {
39
+ for (const definition of source.document?.definitions || []) {
40
+ if (definition.kind === Kind.FRAGMENT_DEFINITION) {
41
+ result.push({
42
+ filePath: source.location,
43
+ document: definition
44
+ });
45
+ }
46
+ }
47
+ }
37
48
  fragmentsCache = result;
38
49
  }
39
50
  return fragmentsCache;
@@ -42,37 +53,54 @@ function getSiblings(documents) {
42
53
  const getOperations = () => {
43
54
  if (cachedOperations === null) {
44
55
  const result = [];
45
- for (const source of documents)
46
- for (const definition of source.document?.definitions || [])
47
- definition.kind === Kind.OPERATION_DEFINITION && result.push({
48
- filePath: source.location,
49
- document: definition
50
- });
56
+ for (const source of documents) {
57
+ for (const definition of source.document?.definitions || []) {
58
+ if (definition.kind === Kind.OPERATION_DEFINITION) {
59
+ result.push({
60
+ filePath: source.location,
61
+ document: definition
62
+ });
63
+ }
64
+ }
65
+ }
51
66
  cachedOperations = result;
52
67
  }
53
68
  return cachedOperations;
54
- }, getFragment = (name) => getFragments().filter((f) => f.document.name.value === name), collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => (visit(selectable, {
55
- FragmentSpread(spread) {
56
- const fragmentName = spread.name.value, [fragment] = getFragment(fragmentName);
57
- if (!fragment) {
58
- logger.warn(
59
- `Unable to locate fragment named "${fragmentName}", please make sure it's loaded using "parserOptions.operations"`
60
- );
61
- return;
69
+ };
70
+ const getFragment = (name) => getFragments().filter((f) => f.document.name.value === name);
71
+ const collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => {
72
+ visit(selectable, {
73
+ FragmentSpread(spread) {
74
+ const fragmentName = spread.name.value;
75
+ const [fragment] = getFragment(fragmentName);
76
+ if (!fragment) {
77
+ logger.warn(
78
+ `Unable to locate fragment named "${fragmentName}", please make sure it's loaded using "parserOptions.operations"`
79
+ );
80
+ return;
81
+ }
82
+ if (!collected.has(fragmentName)) {
83
+ collected.set(fragmentName, fragment.document);
84
+ if (recursive) {
85
+ collectFragments(fragment.document, recursive, collected);
86
+ }
87
+ }
62
88
  }
63
- collected.has(fragmentName) || (collected.set(fragmentName, fragment.document), recursive && collectFragments(fragment.document, recursive, collected));
64
- }
65
- }), collected), siblingOperations = {
66
- available: !0,
89
+ });
90
+ return collected;
91
+ };
92
+ const siblingOperations = {
93
+ available: true,
67
94
  getFragment,
68
95
  getFragments,
69
96
  getFragmentByType: (typeName) => getFragments().filter((f) => f.document.typeCondition.name.value === typeName),
70
- getFragmentsInUse: (selectable, recursive = !0) => Array.from(collectFragments(selectable, recursive).values()),
97
+ getFragmentsInUse: (selectable, recursive = true) => Array.from(collectFragments(selectable, recursive).values()),
71
98
  getOperation: (name) => getOperations().filter((o) => o.document.name?.value === name),
72
99
  getOperations,
73
100
  getOperationByType: (type) => getOperations().filter((o) => o.document.operation === type)
74
101
  };
75
- return siblingOperationsCache.set(documents, siblingOperations), siblingOperations;
102
+ siblingOperationsCache.set(documents, siblingOperations);
103
+ return siblingOperations;
76
104
  }
77
105
  export {
78
106
  getSiblings
package/esm/utils.js CHANGED
@@ -2,24 +2,27 @@ import { Kind } from "graphql";
2
2
  import lowerCase from "lodash.lowercase";
3
3
  function requireGraphQLOperations(ruleId, context) {
4
4
  const { siblingOperations } = context.sourceCode.parserServices;
5
- if (!siblingOperations.available)
5
+ if (!siblingOperations.available) {
6
6
  throw new Error(
7
7
  `Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`
8
8
  );
9
+ }
9
10
  return siblingOperations;
10
11
  }
11
12
  function requireGraphQLSchema(ruleId, context) {
12
13
  const { schema } = context.sourceCode.parserServices;
13
- if (!schema)
14
+ if (!schema) {
14
15
  throw new Error(
15
16
  `Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-schema for more info`
16
17
  );
18
+ }
17
19
  return schema;
18
20
  }
19
21
  const chalk = {
20
22
  red: (str) => `\x1B[31m${str}\x1B[39m`,
21
23
  yellow: (str) => `\x1B[33m${str}\x1B[39m`
22
- }, logger = {
24
+ };
25
+ const logger = {
23
26
  error: (...args) => (
24
27
  // eslint-disable-next-line no-console
25
28
  console.error(chalk.red("error"), "[graphql-eslint]", ...args)
@@ -28,17 +31,25 @@ const chalk = {
28
31
  // eslint-disable-next-line no-console
29
32
  console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
30
33
  )
31
- }, slash = (path) => path.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 = [
34
+ };
35
+ const slash = (path) => path.replaceAll("\\", "/");
36
+ const VIRTUAL_DOCUMENT_REGEX = /[/\\]\d+_document.graphql$/;
37
+ const CWD = process.cwd();
38
+ const getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "";
39
+ const TYPES_KINDS = [
32
40
  Kind.OBJECT_TYPE_DEFINITION,
33
41
  Kind.INTERFACE_TYPE_DEFINITION,
34
42
  Kind.ENUM_TYPE_DEFINITION,
35
43
  Kind.SCALAR_TYPE_DEFINITION,
36
44
  Kind.INPUT_OBJECT_TYPE_DEFINITION,
37
45
  Kind.UNION_TYPE_DEFINITION
38
- ], pascalCase = (str) => lowerCase(str).split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(""), camelCase = (str) => {
46
+ ];
47
+ const pascalCase = (str) => lowerCase(str).split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
48
+ const camelCase = (str) => {
39
49
  const result = pascalCase(str);
40
50
  return result.charAt(0).toLowerCase() + result.slice(1);
41
- }, convertCase = (style, str) => {
51
+ };
52
+ const convertCase = (style, str) => {
42
53
  switch (style) {
43
54
  case "camelCase":
44
55
  return camelCase(str);
@@ -65,14 +76,17 @@ function getLocation(start, fieldName = "") {
65
76
  }
66
77
  };
67
78
  }
68
- const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 }, ARRAY_DEFAULT_OPTIONS = {
79
+ const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 };
80
+ const ARRAY_DEFAULT_OPTIONS = {
69
81
  type: "array",
70
- uniqueItems: !0,
82
+ uniqueItems: true,
71
83
  minItems: 1,
72
84
  items: {
73
85
  type: "string"
74
86
  }
75
- }, englishJoinWords = (words) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(words), DisplayNodeNameMap = {
87
+ };
88
+ const englishJoinWords = (words) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(words);
89
+ const DisplayNodeNameMap = {
76
90
  [Kind.ARGUMENT]: "argument",
77
91
  [Kind.BOOLEAN]: "boolean",
78
92
  [Kind.DIRECTIVE_DEFINITION]: "directive",