@graphql-eslint/eslint-plugin 3.14.0-alpha-20221222211539-5e993f5 → 3.14.0-alpha-20221223011223-bd3e820

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 (185) hide show
  1. package/cjs/configs/index.js +10 -10
  2. package/cjs/documents.js +5 -5
  3. package/cjs/estree-converter/converter.js +2 -2
  4. package/cjs/estree-converter/index.js +3 -3
  5. package/cjs/estree-converter/utils.js +2 -2
  6. package/cjs/flat-configs.js +36 -0
  7. package/cjs/index.js +16 -14
  8. package/cjs/parser.js +13 -13
  9. package/cjs/processor.js +2 -2
  10. package/cjs/rules/alphabetize.js +7 -7
  11. package/cjs/rules/graphql-js-validation.js +9 -9
  12. package/cjs/rules/index.js +66 -66
  13. package/cjs/rules/lone-executable-definition.js +4 -4
  14. package/cjs/rules/match-document-filename.js +4 -4
  15. package/cjs/rules/naming-convention.js +6 -6
  16. package/cjs/rules/no-anonymous-operations.js +2 -2
  17. package/cjs/rules/no-deprecated.js +2 -2
  18. package/cjs/rules/no-one-place-fragments.js +3 -4
  19. package/cjs/rules/no-root-type.js +3 -3
  20. package/cjs/rules/no-scalar-result-type-on-mutation.js +2 -2
  21. package/cjs/rules/no-unreachable-types.js +3 -3
  22. package/cjs/rules/no-unused-fields.js +3 -3
  23. package/cjs/rules/relay-arguments.js +2 -2
  24. package/cjs/rules/relay-edge-types.js +6 -6
  25. package/cjs/rules/relay-page-info.js +5 -5
  26. package/cjs/rules/require-deprecation-date.js +2 -2
  27. package/cjs/rules/require-deprecation-reason.js +2 -2
  28. package/cjs/rules/require-description.js +8 -8
  29. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +3 -3
  30. package/cjs/rules/require-id-when-available.js +8 -8
  31. package/cjs/rules/selection-set-depth.js +5 -5
  32. package/cjs/rules/strict-id-in-types.js +7 -7
  33. package/cjs/rules/unique-fragment-name.js +4 -4
  34. package/cjs/rules/unique-operation-name.js +2 -2
  35. package/cjs/schema.js +2 -2
  36. package/esm/cache.js +25 -0
  37. package/esm/configs/base.js +4 -0
  38. package/esm/configs/index.js +12 -0
  39. package/esm/configs/operations-all.js +29 -0
  40. package/esm/configs/operations-recommended.js +53 -0
  41. package/esm/configs/relay.js +9 -0
  42. package/esm/configs/schema-all.js +22 -0
  43. package/esm/configs/schema-recommended.js +49 -0
  44. package/esm/documents.js +144 -0
  45. package/esm/estree-converter/converter.js +58 -0
  46. package/esm/estree-converter/index.js +3 -0
  47. package/esm/estree-converter/types.js +1 -0
  48. package/esm/estree-converter/utils.js +102 -0
  49. package/esm/flat-configs.js +33 -0
  50. package/esm/graphql-config.js +49 -0
  51. package/esm/index.js +9 -0
  52. package/esm/package.json +1 -0
  53. package/esm/parser.js +56 -0
  54. package/esm/processor.js +75 -0
  55. package/esm/rules/alphabetize.js +344 -0
  56. package/esm/rules/description-style.js +75 -0
  57. package/esm/rules/graphql-js-validation.js +498 -0
  58. package/esm/rules/index.js +71 -0
  59. package/esm/rules/input-name.js +133 -0
  60. package/esm/rules/lone-executable-definition.js +85 -0
  61. package/esm/rules/match-document-filename.js +232 -0
  62. package/esm/rules/naming-convention.js +307 -0
  63. package/esm/rules/no-anonymous-operations.js +64 -0
  64. package/esm/rules/no-case-insensitive-enum-values-duplicates.js +58 -0
  65. package/esm/rules/no-deprecated.js +121 -0
  66. package/esm/rules/no-duplicate-fields.js +109 -0
  67. package/esm/rules/no-hashtag-description.js +86 -0
  68. package/esm/rules/no-one-place-fragments.js +80 -0
  69. package/esm/rules/no-root-type.js +83 -0
  70. package/esm/rules/no-scalar-result-type-on-mutation.js +63 -0
  71. package/esm/rules/no-typename-prefix.js +62 -0
  72. package/esm/rules/no-unreachable-types.js +154 -0
  73. package/esm/rules/no-unused-fields.js +127 -0
  74. package/esm/rules/relay-arguments.js +118 -0
  75. package/esm/rules/relay-connection-types.js +104 -0
  76. package/esm/rules/relay-edge-types.js +186 -0
  77. package/esm/rules/relay-page-info.js +97 -0
  78. package/esm/rules/require-deprecation-date.js +120 -0
  79. package/esm/rules/require-deprecation-reason.js +53 -0
  80. package/esm/rules/require-description.js +190 -0
  81. package/esm/rules/require-field-of-type-query-in-mutation-result.js +69 -0
  82. package/esm/rules/require-id-when-available.js +196 -0
  83. package/esm/rules/require-nullable-fields-with-oneof.js +58 -0
  84. package/esm/rules/require-type-pattern-with-oneof.js +57 -0
  85. package/esm/rules/selection-set-depth.js +131 -0
  86. package/esm/rules/strict-id-in-types.js +159 -0
  87. package/esm/rules/unique-fragment-name.js +86 -0
  88. package/esm/rules/unique-operation-name.js +62 -0
  89. package/esm/schema.js +37 -0
  90. package/esm/testkit.js +181 -0
  91. package/esm/types.js +1 -0
  92. package/esm/utils.js +83 -0
  93. package/package.json +10 -1
  94. package/typings/estree-converter/converter.d.cts +1 -1
  95. package/typings/estree-converter/converter.d.ts +1 -1
  96. package/typings/estree-converter/index.d.cts +3 -3
  97. package/typings/estree-converter/index.d.ts +3 -3
  98. package/typings/estree-converter/types.d.cts +3 -3
  99. package/typings/estree-converter/types.d.ts +3 -3
  100. package/typings/estree-converter/utils.d.cts +2 -2
  101. package/typings/estree-converter/utils.d.ts +2 -2
  102. package/typings/flat-configs.d.cts +248 -0
  103. package/typings/flat-configs.d.ts +248 -0
  104. package/typings/graphql-config.d.cts +1 -1
  105. package/typings/graphql-config.d.ts +1 -1
  106. package/typings/index.d.cts +8 -7
  107. package/typings/index.d.ts +8 -7
  108. package/typings/parser.d.cts +1 -1
  109. package/typings/parser.d.ts +1 -1
  110. package/typings/rules/alphabetize.d.cts +1 -1
  111. package/typings/rules/alphabetize.d.ts +1 -1
  112. package/typings/rules/description-style.d.cts +1 -1
  113. package/typings/rules/description-style.d.ts +1 -1
  114. package/typings/rules/graphql-js-validation.d.cts +1 -1
  115. package/typings/rules/graphql-js-validation.d.ts +1 -1
  116. package/typings/rules/index.d.cts +45 -45
  117. package/typings/rules/index.d.ts +45 -45
  118. package/typings/rules/input-name.d.cts +1 -1
  119. package/typings/rules/input-name.d.ts +1 -1
  120. package/typings/rules/lone-executable-definition.d.cts +1 -1
  121. package/typings/rules/lone-executable-definition.d.ts +1 -1
  122. package/typings/rules/match-document-filename.d.cts +2 -2
  123. package/typings/rules/match-document-filename.d.ts +2 -2
  124. package/typings/rules/naming-convention.d.cts +1 -1
  125. package/typings/rules/naming-convention.d.ts +1 -1
  126. package/typings/rules/no-anonymous-operations.d.cts +1 -1
  127. package/typings/rules/no-anonymous-operations.d.ts +1 -1
  128. package/typings/rules/no-case-insensitive-enum-values-duplicates.d.cts +1 -1
  129. package/typings/rules/no-case-insensitive-enum-values-duplicates.d.ts +1 -1
  130. package/typings/rules/no-deprecated.d.cts +1 -1
  131. package/typings/rules/no-deprecated.d.ts +1 -1
  132. package/typings/rules/no-duplicate-fields.d.cts +1 -1
  133. package/typings/rules/no-duplicate-fields.d.ts +1 -1
  134. package/typings/rules/no-hashtag-description.d.cts +1 -1
  135. package/typings/rules/no-hashtag-description.d.ts +1 -1
  136. package/typings/rules/no-one-place-fragments.d.cts +1 -1
  137. package/typings/rules/no-one-place-fragments.d.ts +1 -1
  138. package/typings/rules/no-root-type.d.cts +1 -1
  139. package/typings/rules/no-root-type.d.ts +1 -1
  140. package/typings/rules/no-scalar-result-type-on-mutation.d.cts +1 -1
  141. package/typings/rules/no-scalar-result-type-on-mutation.d.ts +1 -1
  142. package/typings/rules/no-typename-prefix.d.cts +1 -1
  143. package/typings/rules/no-typename-prefix.d.ts +1 -1
  144. package/typings/rules/no-unreachable-types.d.cts +1 -1
  145. package/typings/rules/no-unreachable-types.d.ts +1 -1
  146. package/typings/rules/no-unused-fields.d.cts +1 -1
  147. package/typings/rules/no-unused-fields.d.ts +1 -1
  148. package/typings/rules/relay-arguments.d.cts +1 -1
  149. package/typings/rules/relay-arguments.d.ts +1 -1
  150. package/typings/rules/relay-connection-types.d.cts +1 -1
  151. package/typings/rules/relay-connection-types.d.ts +1 -1
  152. package/typings/rules/relay-edge-types.d.cts +1 -1
  153. package/typings/rules/relay-edge-types.d.ts +1 -1
  154. package/typings/rules/relay-page-info.d.cts +1 -1
  155. package/typings/rules/relay-page-info.d.ts +1 -1
  156. package/typings/rules/require-deprecation-date.d.cts +1 -1
  157. package/typings/rules/require-deprecation-date.d.ts +1 -1
  158. package/typings/rules/require-deprecation-reason.d.cts +1 -1
  159. package/typings/rules/require-deprecation-reason.d.ts +1 -1
  160. package/typings/rules/require-description.d.cts +1 -1
  161. package/typings/rules/require-description.d.ts +1 -1
  162. package/typings/rules/require-field-of-type-query-in-mutation-result.d.cts +1 -1
  163. package/typings/rules/require-field-of-type-query-in-mutation-result.d.ts +1 -1
  164. package/typings/rules/require-id-when-available.d.cts +1 -1
  165. package/typings/rules/require-id-when-available.d.ts +1 -1
  166. package/typings/rules/require-nullable-fields-with-oneof.d.cts +1 -1
  167. package/typings/rules/require-nullable-fields-with-oneof.d.ts +1 -1
  168. package/typings/rules/require-type-pattern-with-oneof.d.cts +1 -1
  169. package/typings/rules/require-type-pattern-with-oneof.d.ts +1 -1
  170. package/typings/rules/selection-set-depth.d.cts +1 -1
  171. package/typings/rules/selection-set-depth.d.ts +1 -1
  172. package/typings/rules/strict-id-in-types.d.cts +1 -1
  173. package/typings/rules/strict-id-in-types.d.ts +1 -1
  174. package/typings/rules/unique-fragment-name.d.cts +2 -2
  175. package/typings/rules/unique-fragment-name.d.ts +2 -2
  176. package/typings/rules/unique-operation-name.d.cts +1 -1
  177. package/typings/rules/unique-operation-name.d.ts +1 -1
  178. package/typings/schema.d.cts +1 -1
  179. package/typings/schema.d.ts +1 -1
  180. package/typings/testkit.d.cts +3 -3
  181. package/typings/testkit.d.ts +3 -3
  182. package/typings/types.d.cts +2 -2
  183. package/typings/types.d.ts +2 -2
  184. package/typings/utils.d.cts +2 -2
  185. package/typings/utils.d.ts +2 -2
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'no-anonymous-operations';
7
7
  exports.rule = {
8
8
  meta: {
@@ -45,7 +45,7 @@ exports.rule = {
45
45
  ? (firstSelection.alias || firstSelection.name).value
46
46
  : node.operation;
47
47
  context.report({
48
- loc: (0, utils_1.getLocation)(node.loc.start, node.operation),
48
+ loc: (0, utils_js_1.getLocation)(node.loc.start, node.operation),
49
49
  messageId: RULE_ID,
50
50
  data: {
51
51
  operation: node.operation,
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'no-deprecated';
7
7
  exports.rule = {
8
8
  meta: {
@@ -83,7 +83,7 @@ exports.rule = {
83
83
  schema: [],
84
84
  },
85
85
  create(context) {
86
- (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
86
+ (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
87
87
  function report(node, reason) {
88
88
  const nodeName = node.kind === graphql_1.Kind.ENUM ? node.value : node.name.value;
89
89
  const nodeType = node.kind === graphql_1.Kind.ENUM ? 'enum value' : 'field';
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
- const eslint_plugin_1 = require("@graphql-eslint/eslint-plugin");
5
- const utils_1 = require("../utils");
4
+ const utils_js_1 = require("../utils.js");
6
5
  const path_1 = require("path");
7
6
  const graphql_1 = require("graphql");
8
7
  const RULE_ID = 'no-one-place-fragments';
@@ -54,11 +53,11 @@ exports.rule = {
54
53
  schema: [],
55
54
  },
56
55
  create(context) {
57
- const operations = (0, eslint_plugin_1.requireSiblingsOperations)(RULE_ID, context);
56
+ const operations = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
58
57
  const allDocuments = [...operations.getOperations(), ...operations.getFragments()];
59
58
  const usedFragmentsMap = Object.create(null);
60
59
  for (const { document, filePath } of allDocuments) {
61
- const relativeFilePath = (0, path_1.relative)(utils_1.CWD, filePath);
60
+ const relativeFilePath = (0, path_1.relative)(utils_js_1.CWD, filePath);
62
61
  (0, graphql_1.visit)(document, {
63
62
  FragmentSpread({ name }) {
64
63
  const spreadName = name.value;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
- const utils_1 = require("../utils");
4
+ const utils_js_1 = require("../utils.js");
5
5
  const schema = {
6
6
  type: 'array',
7
7
  minItems: 1,
@@ -12,7 +12,7 @@ const schema = {
12
12
  required: ['disallow'],
13
13
  properties: {
14
14
  disallow: {
15
- ...utils_1.ARRAY_DEFAULT_OPTIONS,
15
+ ...utils_js_1.ARRAY_DEFAULT_OPTIONS,
16
16
  items: {
17
17
  enum: ['mutation', 'subscription'],
18
18
  },
@@ -54,7 +54,7 @@ exports.rule = {
54
54
  schema,
55
55
  },
56
56
  create(context) {
57
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)('no-root-type', context);
57
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)('no-root-type', context);
58
58
  const disallow = new Set(context.options[0].disallow);
59
59
  const rootTypeNames = [
60
60
  disallow.has('mutation') && schema.getMutationType(),
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'no-scalar-result-type-on-mutation';
7
7
  exports.rule = {
8
8
  meta: {
@@ -35,7 +35,7 @@ exports.rule = {
35
35
  schema: [],
36
36
  },
37
37
  create(context) {
38
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
38
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
39
39
  const mutationType = schema.getMutationType();
40
40
  if (!mutationType) {
41
41
  return {};
@@ -4,7 +4,7 @@ exports.rule = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const graphql_1 = require("graphql");
6
6
  const lodash_lowercase_1 = tslib_1.__importDefault(require("lodash.lowercase"));
7
- const utils_1 = require("../utils");
7
+ const utils_js_1 = require("../utils.js");
8
8
  const RULE_ID = 'no-unreachable-types';
9
9
  const KINDS = [
10
10
  graphql_1.Kind.DIRECTIVE_DEFINITION,
@@ -40,7 +40,7 @@ function getReachableTypes(schema) {
40
40
  }
41
41
  const reachableTypes = new Set();
42
42
  const collect = (node) => {
43
- const typeName = (0, utils_1.getTypeName)(node);
43
+ const typeName = (0, utils_js_1.getTypeName)(node);
44
44
  if (reachableTypes.has(typeName)) {
45
45
  return;
46
46
  }
@@ -130,7 +130,7 @@ exports.rule = {
130
130
  hasSuggestions: true,
131
131
  },
132
132
  create(context) {
133
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
133
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
134
134
  const reachableTypes = getReachableTypes(schema);
135
135
  return {
136
136
  [`:matches(${KINDS}) > .name`](node) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'no-unused-fields';
7
7
  let usedFieldsCache;
8
8
  function getUsedFields(schema, operations) {
@@ -95,8 +95,8 @@ exports.rule = {
95
95
  hasSuggestions: true,
96
96
  },
97
97
  create(context) {
98
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
99
- const siblingsOperations = (0, utils_1.requireSiblingsOperations)(RULE_ID, context);
98
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
99
+ const siblingsOperations = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
100
100
  const usedFields = getUsedFields(schema, siblingsOperations);
101
101
  return {
102
102
  FieldDefinition(node) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'relay-arguments';
7
7
  const MISSING_ARGUMENTS = 'MISSING_ARGUMENTS';
8
8
  const schema = {
@@ -68,7 +68,7 @@ exports.rule = {
68
68
  schema,
69
69
  },
70
70
  create(context) {
71
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
71
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
72
72
  const { includeBoth = true } = context.options[0] || {};
73
73
  return {
74
74
  'FieldDefinition > .gqlType Name[value=/Connection$/]'(node) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
5
  const utils_1 = require("@graphql-tools/utils");
6
- const utils_2 = require("../utils");
6
+ const utils_js_1 = require("../utils.js");
7
7
  const RULE_ID = 'relay-edge-types';
8
8
  const MESSAGE_MUST_BE_OBJECT_TYPE = 'MESSAGE_MUST_BE_OBJECT_TYPE';
9
9
  const MESSAGE_MISSING_EDGE_SUFFIX = 'MESSAGE_MISSING_EDGE_SUFFIX';
@@ -26,7 +26,7 @@ function getEdgeTypes(schema) {
26
26
  }
27
27
  const edges = node.fields.find(field => field.name.value === 'edges');
28
28
  if (edges) {
29
- const edgesTypeName = (0, utils_2.getTypeName)(edges);
29
+ const edgesTypeName = (0, utils_js_1.getTypeName)(edges);
30
30
  const edgesType = schema.getType(edgesTypeName);
31
31
  if ((0, graphql_1.isObjectType)(edgesType)) {
32
32
  edgeTypes.add(edgesTypeName);
@@ -105,7 +105,7 @@ exports.rule = {
105
105
  schema,
106
106
  },
107
107
  create(context) {
108
- const schema = (0, utils_2.requireGraphQLSchemaFromContext)(RULE_ID, context);
108
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
109
109
  const edgeTypes = getEdgeTypes(schema);
110
110
  const options = {
111
111
  withEdgeSuffix: true,
@@ -128,7 +128,7 @@ exports.rule = {
128
128
  context.report({ node: nodeField.name, message: `Field \`node\` must ${message}` });
129
129
  }
130
130
  else if (options.shouldImplementNode) {
131
- const nodeReturnTypeName = (0, utils_2.getTypeName)(nodeField.gqlType.rawNode());
131
+ const nodeReturnTypeName = (0, utils_js_1.getTypeName)(nodeField.gqlType.rawNode());
132
132
  const type = schema.getType(nodeReturnTypeName);
133
133
  if (!(0, graphql_1.isObjectType)(type)) {
134
134
  return;
@@ -149,7 +149,7 @@ exports.rule = {
149
149
  });
150
150
  return;
151
151
  }
152
- const typeName = (0, utils_2.getTypeName)(cursorField.rawNode());
152
+ const typeName = (0, utils_js_1.getTypeName)(cursorField.rawNode());
153
153
  if (!isNamedOrNonNullNamed(cursorField.gqlType) ||
154
154
  (typeName !== 'String' && !(0, graphql_1.isScalarType)(schema.getType(typeName)))) {
155
155
  context.report({ node: cursorField.name, message: `Field \`cursor\` must ${message}` });
@@ -177,7 +177,7 @@ exports.rule = {
177
177
  listeners['FieldDefinition > .gqlType'] = (node) => {
178
178
  if (node.kind === graphql_1.Kind.LIST_TYPE ||
179
179
  (node.kind === graphql_1.Kind.NON_NULL_TYPE && node.gqlType.kind === graphql_1.Kind.LIST_TYPE)) {
180
- const typeName = (0, utils_2.getTypeName)(node.rawNode());
180
+ const typeName = (0, utils_js_1.getTypeName)(node.rawNode());
181
181
  if (!edgeTypes.has(typeName)) {
182
182
  context.report({ node, messageId: MESSAGE_LIST_TYPE_ONLY_EDGE_TYPE });
183
183
  }
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const relay_connection_types_1 = require("./relay-connection-types");
6
- const utils_1 = require("../utils");
5
+ const relay_connection_types_js_1 = require("./relay-connection-types.js");
6
+ const utils_js_1 = require("../utils.js");
7
7
  const RULE_ID = 'relay-page-info';
8
8
  const MESSAGE_MUST_EXIST = 'MESSAGE_MUST_EXIST';
9
9
  const MESSAGE_MUST_BE_OBJECT_TYPE = 'MESSAGE_MUST_BE_OBJECT_TYPE';
10
- const notPageInfoTypesSelector = `:matches(${relay_connection_types_1.NON_OBJECT_TYPES})[name.value=PageInfo] > .name`;
10
+ const notPageInfoTypesSelector = `:matches(${relay_connection_types_js_1.NON_OBJECT_TYPES})[name.value=PageInfo] > .name`;
11
11
  let hasPageInfoChecked = false;
12
12
  exports.rule = {
13
13
  meta: {
@@ -45,12 +45,12 @@ exports.rule = {
45
45
  schema: [],
46
46
  },
47
47
  create(context) {
48
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
48
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
49
49
  if (process.env.NODE_ENV === 'test' || !hasPageInfoChecked) {
50
50
  const pageInfoType = schema.getType('PageInfo');
51
51
  if (!pageInfoType) {
52
52
  context.report({
53
- loc: utils_1.REPORT_ON_FIRST_CHARACTER,
53
+ loc: utils_js_1.REPORT_ON_FIRST_CHARACTER,
54
54
  messageId: MESSAGE_MUST_EXIST,
55
55
  });
56
56
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
- const estree_converter_1 = require("../estree-converter");
4
+ const index_js_1 = require("../estree-converter/index.js");
5
5
  // eslint-disable-next-line unicorn/better-regex
6
6
  const DATE_REGEX = /^\d{2}\/\d{2}\/\d{4}$/;
7
7
  const MESSAGE_REQUIRE_DATE = 'MESSAGE_REQUIRE_DATE';
@@ -81,7 +81,7 @@ exports.rule = {
81
81
  });
82
82
  return;
83
83
  }
84
- const deletionDate = (0, estree_converter_1.valueFromNode)(deletionDateNode.value);
84
+ const deletionDate = (0, index_js_1.valueFromNode)(deletionDateNode.value);
85
85
  const isValidDate = DATE_REGEX.test(deletionDate);
86
86
  if (!isValidDate) {
87
87
  context.report({ node: deletionDateNode.value, messageId: MESSAGE_INVALID_FORMAT });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
- const estree_converter_1 = require("../estree-converter");
4
+ const index_js_1 = require("../estree-converter/index.js");
5
5
  exports.rule = {
6
6
  meta: {
7
7
  docs: {
@@ -43,7 +43,7 @@ exports.rule = {
43
43
  return {
44
44
  'Directive[name.value=deprecated]'(node) {
45
45
  const reasonArgument = node.arguments.find(arg => arg.name.value === 'reason');
46
- const value = reasonArgument && String((0, estree_converter_1.valueFromNode)(reasonArgument.value)).trim();
46
+ const value = reasonArgument && String((0, index_js_1.valueFromNode)(reasonArgument.value)).trim();
47
47
  if (!value) {
48
48
  context.report({
49
49
  node: node.name,
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
6
- const utils_2 = require("@graphql-tools/utils");
5
+ const utils_js_1 = require("../utils.js");
6
+ const utils_1 = require("@graphql-tools/utils");
7
7
  const RULE_ID = 'require-description';
8
8
  const ALLOWED_KINDS = [
9
- ...utils_1.TYPES_KINDS,
9
+ ...utils_js_1.TYPES_KINDS,
10
10
  graphql_1.Kind.DIRECTIVE_DEFINITION,
11
11
  graphql_1.Kind.FIELD_DEFINITION,
12
12
  graphql_1.Kind.INPUT_VALUE_DEFINITION,
@@ -52,7 +52,7 @@ const schema = {
52
52
  properties: {
53
53
  types: {
54
54
  type: 'boolean',
55
- description: `Includes:\n${utils_1.TYPES_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
55
+ description: `Includes:\n${utils_js_1.TYPES_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
56
56
  },
57
57
  rootField: {
58
58
  type: 'boolean',
@@ -142,7 +142,7 @@ exports.rule = {
142
142
  },
143
143
  create(context) {
144
144
  const { types, rootField, ...restOptions } = context.options[0] || {};
145
- const kinds = new Set(types ? utils_1.TYPES_KINDS : []);
145
+ const kinds = new Set(types ? utils_js_1.TYPES_KINDS : []);
146
146
  for (const [kind, isEnabled] of Object.entries(restOptions)) {
147
147
  if (isEnabled) {
148
148
  kinds.add(kind);
@@ -152,8 +152,8 @@ exports.rule = {
152
152
  }
153
153
  }
154
154
  if (rootField) {
155
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
156
- const rootTypeNames = (0, utils_2.getRootTypeNames)(schema);
155
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
156
+ const rootTypeNames = (0, utils_1.getRootTypeNames)(schema);
157
157
  kinds.add(`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
158
158
  ...rootTypeNames,
159
159
  ].join(',')})$/] > FieldDefinition`);
@@ -180,7 +180,7 @@ exports.rule = {
180
180
  }
181
181
  if (description.length === 0) {
182
182
  context.report({
183
- loc: isOperation ? (0, utils_1.getLocation)(node.loc.start, node.operation) : node.name.loc,
183
+ loc: isOperation ? (0, utils_js_1.getLocation)(node.loc.start, node.operation) : node.name.loc,
184
184
  messageId: RULE_ID,
185
185
  data: {
186
186
  nodeName: getNodeName(node),
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'require-field-of-type-query-in-mutation-result';
7
7
  exports.rule = {
8
8
  meta: {
@@ -45,7 +45,7 @@ exports.rule = {
45
45
  schema: [],
46
46
  },
47
47
  create(context) {
48
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
48
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
49
49
  const mutationType = schema.getMutationType();
50
50
  const queryType = schema.getQueryType();
51
51
  if (!mutationType || !queryType) {
@@ -58,7 +58,7 @@ exports.rule = {
58
58
  const graphQLType = schema.getType(typeName);
59
59
  if ((0, graphql_1.isObjectType)(graphQLType)) {
60
60
  const { fields } = graphQLType.astNode;
61
- const hasQueryType = fields.some(field => (0, utils_1.getTypeName)(field) === queryType.name);
61
+ const hasQueryType = fields.some(field => (0, utils_js_1.getTypeName)(field) === queryType.name);
62
62
  if (!hasQueryType) {
63
63
  context.report({
64
64
  node,
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
5
  const utils_1 = require("@graphql-tools/utils");
6
- const utils_2 = require("../utils");
7
- const estree_converter_1 = require("../estree-converter");
6
+ const utils_js_1 = require("../utils.js");
7
+ const index_js_1 = require("../estree-converter/index.js");
8
8
  const RULE_ID = 'require-id-when-available';
9
9
  const DEFAULT_ID_FIELD_NAME = 'id';
10
10
  const schema = {
@@ -12,7 +12,7 @@ const schema = {
12
12
  asString: {
13
13
  type: 'string',
14
14
  },
15
- asArray: utils_2.ARRAY_DEFAULT_OPTIONS,
15
+ asArray: utils_js_1.ARRAY_DEFAULT_OPTIONS,
16
16
  },
17
17
  type: 'array',
18
18
  maxItems: 1,
@@ -89,8 +89,8 @@ exports.rule = {
89
89
  schema,
90
90
  },
91
91
  create(context) {
92
- const schema = (0, utils_2.requireGraphQLSchemaFromContext)(RULE_ID, context);
93
- const siblings = (0, utils_2.requireSiblingsOperations)(RULE_ID, context);
92
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
93
+ const siblings = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
94
94
  const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
95
95
  const idNames = (0, utils_1.asArray)(fieldName);
96
96
  // Check selections only in OperationDefinition,
@@ -126,7 +126,7 @@ exports.rule = {
126
126
  loc,
127
127
  // Can't access to node.parent in GraphQL AST.Node, so pass as argument
128
128
  parent, checkedFragmentSpreads = new Set()) {
129
- const rawType = (0, estree_converter_1.getBaseType)(type);
129
+ const rawType = (0, index_js_1.getBaseType)(type);
130
130
  const isObjectType = rawType instanceof graphql_1.GraphQLObjectType;
131
131
  const isInterfaceType = rawType instanceof graphql_1.GraphQLInterfaceType;
132
132
  if (!isObjectType && !isInterfaceType) {
@@ -165,10 +165,10 @@ exports.rule = {
165
165
  return;
166
166
  }
167
167
  const pluralSuffix = idNames.length > 1 ? 's' : '';
168
- const fieldName = (0, utils_2.englishJoinWords)(idNames.map(name => `\`${(parent.alias || parent.name).value}.${name}\``));
168
+ const fieldName = (0, utils_js_1.englishJoinWords)(idNames.map(name => `\`${(parent.alias || parent.name).value}.${name}\``));
169
169
  const addition = checkedFragmentSpreads.size === 0
170
170
  ? ''
171
- : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? 's' : ''} ${(0, utils_2.englishJoinWords)([...checkedFragmentSpreads].map(name => `\`${name}\``))}`;
171
+ : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? 's' : ''} ${(0, utils_js_1.englishJoinWords)([...checkedFragmentSpreads].map(name => `\`${name}\``))}`;
172
172
  const problem = {
173
173
  loc,
174
174
  messageId: RULE_ID,
@@ -4,7 +4,7 @@ exports.rule = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const graphql_depth_limit_1 = tslib_1.__importDefault(require("graphql-depth-limit"));
6
6
  const graphql_1 = require("graphql");
7
- const utils_1 = require("../utils");
7
+ const utils_js_1 = require("../utils.js");
8
8
  const RULE_ID = 'selection-set-depth';
9
9
  const schema = {
10
10
  type: 'array',
@@ -18,7 +18,7 @@ const schema = {
18
18
  maxDepth: {
19
19
  type: 'number',
20
20
  },
21
- ignore: utils_1.ARRAY_DEFAULT_OPTIONS,
21
+ ignore: utils_js_1.ARRAY_DEFAULT_OPTIONS,
22
22
  },
23
23
  },
24
24
  };
@@ -80,10 +80,10 @@ exports.rule = {
80
80
  create(context) {
81
81
  let siblings = null;
82
82
  try {
83
- siblings = (0, utils_1.requireSiblingsOperations)(RULE_ID, context);
83
+ siblings = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
84
84
  }
85
85
  catch (_a) {
86
- utils_1.logger.warn(`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`);
86
+ utils_js_1.logger.warn(`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`);
87
87
  }
88
88
  const { maxDepth, ignore = [] } = context.options[0];
89
89
  const checkFn = (0, graphql_depth_limit_1.default)(maxDepth, { ignore });
@@ -127,7 +127,7 @@ exports.rule = {
127
127
  });
128
128
  }
129
129
  catch (e) {
130
- utils_1.logger.warn(`Rule "${RULE_ID}" check failed due to a missing siblings operations. For more info: https://bit.ly/graphql-eslint-operations`, e);
130
+ utils_js_1.logger.warn(`Rule "${RULE_ID}" check failed due to a missing siblings operations. For more info: https://bit.ly/graphql-eslint-operations`, e);
131
131
  }
132
132
  },
133
133
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const graphql_1 = require("graphql");
5
- const utils_1 = require("../utils");
5
+ const utils_js_1 = require("../utils.js");
6
6
  const RULE_ID = 'strict-id-in-types';
7
7
  const schema = {
8
8
  type: 'array',
@@ -12,11 +12,11 @@ const schema = {
12
12
  additionalProperties: false,
13
13
  properties: {
14
14
  acceptedIdNames: {
15
- ...utils_1.ARRAY_DEFAULT_OPTIONS,
15
+ ...utils_js_1.ARRAY_DEFAULT_OPTIONS,
16
16
  default: ['id'],
17
17
  },
18
18
  acceptedIdTypes: {
19
- ...utils_1.ARRAY_DEFAULT_OPTIONS,
19
+ ...utils_js_1.ARRAY_DEFAULT_OPTIONS,
20
20
  default: ['ID'],
21
21
  },
22
22
  exceptions: {
@@ -24,11 +24,11 @@ const schema = {
24
24
  additionalProperties: false,
25
25
  properties: {
26
26
  types: {
27
- ...utils_1.ARRAY_DEFAULT_OPTIONS,
27
+ ...utils_js_1.ARRAY_DEFAULT_OPTIONS,
28
28
  description: 'This is used to exclude types with names that match one of the specified values.',
29
29
  },
30
30
  suffixes: {
31
- ...utils_1.ARRAY_DEFAULT_OPTIONS,
31
+ ...utils_js_1.ARRAY_DEFAULT_OPTIONS,
32
32
  description: 'This is used to exclude types with names with suffixes that match one of the specified values.',
33
33
  },
34
34
  },
@@ -116,7 +116,7 @@ exports.rule = {
116
116
  exceptions: {},
117
117
  ...context.options[0],
118
118
  };
119
- const schema = (0, utils_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
119
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
120
120
  const rootTypeNames = [
121
121
  schema.getQueryType(),
122
122
  schema.getMutationType(),
@@ -153,7 +153,7 @@ exports.rule = {
153
153
  const pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? 's' : '';
154
154
  context.report({
155
155
  node: node.name,
156
- message: `${typeName} must have exactly one non-nullable unique identifier. Accepted name${pluralNamesSuffix}: ${(0, utils_1.englishJoinWords)(options.acceptedIdNames)}. Accepted type${pluralTypesSuffix}: ${(0, utils_1.englishJoinWords)(options.acceptedIdTypes)}.`,
156
+ message: `${typeName} must have exactly one non-nullable unique identifier. Accepted name${pluralNamesSuffix}: ${(0, utils_js_1.englishJoinWords)(options.acceptedIdNames)}. Accepted type${pluralTypesSuffix}: ${(0, utils_js_1.englishJoinWords)(options.acceptedIdTypes)}.`,
157
157
  });
158
158
  }
159
159
  },
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = exports.checkNode = void 0;
4
4
  const path_1 = require("path");
5
5
  const graphql_1 = require("graphql");
6
- const utils_1 = require("../utils");
6
+ const utils_js_1 = require("../utils.js");
7
7
  const RULE_ID = 'unique-fragment-name';
8
8
  const checkNode = (context, node, ruleId) => {
9
9
  const documentName = node.name.value;
10
- const siblings = (0, utils_1.requireSiblingsOperations)(ruleId, context);
10
+ const siblings = (0, utils_js_1.requireSiblingsOperations)(ruleId, context);
11
11
  const siblingDocuments = node.kind === graphql_1.Kind.FRAGMENT_DEFINITION
12
12
  ? siblings.getFragment(documentName)
13
13
  : siblings.getOperation(documentName);
@@ -15,7 +15,7 @@ const checkNode = (context, node, ruleId) => {
15
15
  const conflictingDocuments = siblingDocuments.filter(f => {
16
16
  var _a;
17
17
  const isSameName = ((_a = f.document.name) === null || _a === void 0 ? void 0 : _a.value) === documentName;
18
- const isSamePath = (0, utils_1.normalizePath)(f.filePath) === (0, utils_1.normalizePath)(filepath);
18
+ const isSamePath = (0, utils_js_1.normalizePath)(f.filePath) === (0, utils_js_1.normalizePath)(filepath);
19
19
  return isSameName && !isSamePath;
20
20
  });
21
21
  if (conflictingDocuments.length > 0) {
@@ -24,7 +24,7 @@ const checkNode = (context, node, ruleId) => {
24
24
  data: {
25
25
  documentName,
26
26
  summary: conflictingDocuments
27
- .map(f => `\t${(0, path_1.relative)(utils_1.CWD, f.filePath.replace(utils_1.VIRTUAL_DOCUMENT_REGEX, ''))}`)
27
+ .map(f => `\t${(0, path_1.relative)(utils_js_1.CWD, f.filePath.replace(utils_js_1.VIRTUAL_DOCUMENT_REGEX, ''))}`)
28
28
  .join('\n'),
29
29
  },
30
30
  node: node.name,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
- const unique_fragment_name_1 = require("./unique-fragment-name");
4
+ const unique_fragment_name_js_1 = require("./unique-fragment-name.js");
5
5
  const RULE_ID = 'unique-operation-name';
6
6
  exports.rule = {
7
7
  meta: {
@@ -58,7 +58,7 @@ exports.rule = {
58
58
  create(context) {
59
59
  return {
60
60
  'OperationDefinition[name!=undefined]'(node) {
61
- (0, unique_fragment_name_1.checkNode)(context, node, RULE_ID);
61
+ (0, unique_fragment_name_js_1.checkNode)(context, node, RULE_ID);
62
62
  },
63
63
  };
64
64
  },
package/cjs/schema.js CHANGED
@@ -6,8 +6,8 @@ const graphql_1 = require("graphql");
6
6
  const debug_1 = tslib_1.__importDefault(require("debug"));
7
7
  const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
8
8
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
- const cache_1 = require("./cache");
10
- const schemaCache = new cache_1.ModuleCache();
9
+ const cache_js_1 = require("./cache.js");
10
+ const schemaCache = new cache_js_1.ModuleCache();
11
11
  const debug = (0, debug_1.default)('graphql-eslint:schema');
12
12
  function getSchema(project, schemaOptions) {
13
13
  const schemaKey = project.schema;
package/esm/cache.js ADDED
@@ -0,0 +1,25 @@
1
+ // Based on the `eslint-plugin-import`'s cache
2
+ // https://github.com/import-js/eslint-plugin-import/blob/main/utils/ModuleCache.js
3
+ import debugFactory from 'debug';
4
+ const log = debugFactory('graphql-eslint:ModuleCache');
5
+ export class ModuleCache {
6
+ constructor() {
7
+ this.map = new Map();
8
+ }
9
+ set(cacheKey, result) {
10
+ this.map.set(cacheKey, { lastSeen: process.hrtime(), result });
11
+ log('setting entry for', cacheKey);
12
+ }
13
+ get(cacheKey, settings = { lifetime: 10 /* seconds */ }) {
14
+ if (!this.map.has(cacheKey)) {
15
+ log('cache miss for', cacheKey);
16
+ return;
17
+ }
18
+ const { lastSeen, result } = this.map.get(cacheKey);
19
+ // check freshness
20
+ if (process.env.NODE /* don't check for ESLint CLI */ ||
21
+ process.hrtime(lastSeen)[0] < settings.lifetime) {
22
+ return result;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,4 @@
1
+ export default {
2
+ parser: '@graphql-eslint/eslint-plugin',
3
+ plugins: ['@graphql-eslint'],
4
+ };
@@ -0,0 +1,12 @@
1
+ import schemaRecommendedConfig from './schema-recommended.js';
2
+ import schemaAllConfig from './schema-all.js';
3
+ import operationsRecommendedConfig from './operations-recommended.js';
4
+ import operationsAllConfig from './operations-all.js';
5
+ import relayConfig from './relay.js';
6
+ export const configs = {
7
+ 'schema-recommended': schemaRecommendedConfig,
8
+ 'schema-all': schemaAllConfig,
9
+ 'operations-recommended': operationsRecommendedConfig,
10
+ 'operations-all': operationsAllConfig,
11
+ relay: relayConfig,
12
+ };