@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810160036-304c2c0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. package/README.md +2 -0
  2. package/cjs/cache.js +10 -19
  3. package/cjs/configs/index.d.ts +42 -16
  4. package/cjs/configs/index.js +10 -19
  5. package/cjs/configs/operations-all.d.ts +4 -3
  6. package/cjs/configs/operations-all.js +5 -4
  7. package/cjs/configs/operations-recommended.d.ts +3 -1
  8. package/cjs/configs/operations-recommended.js +3 -1
  9. package/cjs/configs/schema-all.d.ts +6 -1
  10. package/cjs/configs/schema-all.js +5 -2
  11. package/cjs/configs/schema-recommended.d.ts +19 -1
  12. package/cjs/configs/schema-recommended.js +22 -2
  13. package/cjs/documents.js +17 -32
  14. package/cjs/estree-converter/converter.js +14 -27
  15. package/cjs/estree-converter/index.js +4 -7
  16. package/cjs/estree-converter/types.js +3 -5
  17. package/cjs/estree-converter/utils.d.ts +2 -3
  18. package/cjs/estree-converter/utils.js +15 -45
  19. package/cjs/flat-configs.d.ts +59 -12
  20. package/cjs/flat-configs.js +9 -14
  21. package/cjs/graphql-config.d.ts +4 -3
  22. package/cjs/graphql-config.js +23 -44
  23. package/cjs/index.d.ts +10 -4
  24. package/cjs/index.js +8 -16
  25. package/cjs/parser.d.ts +4 -3
  26. package/cjs/parser.js +38 -45
  27. package/cjs/processor.d.ts +5 -1
  28. package/cjs/processor.js +25 -57
  29. package/cjs/rules/alphabetize.d.ts +6 -16
  30. package/cjs/rules/alphabetize.js +60 -132
  31. package/cjs/rules/description-style.d.ts +4 -3
  32. package/cjs/rules/description-style.js +11 -18
  33. package/cjs/rules/graphql-js-validation.d.ts +4 -3
  34. package/cjs/rules/graphql-js-validation.js +151 -225
  35. package/cjs/rules/index.d.ts +15 -13
  36. package/cjs/rules/index.js +8 -45
  37. package/cjs/rules/input-name.d.ts +4 -3
  38. package/cjs/rules/input-name.js +43 -59
  39. package/cjs/rules/lone-executable-definition.d.ts +6 -5
  40. package/cjs/rules/lone-executable-definition.js +14 -28
  41. package/cjs/rules/match-document-filename.d.ts +4 -3
  42. package/cjs/rules/match-document-filename.js +39 -70
  43. package/cjs/rules/naming-convention.d.ts +4 -3
  44. package/cjs/rules/naming-convention.js +56 -74
  45. package/cjs/rules/no-anonymous-operations.d.ts +4 -3
  46. package/cjs/rules/no-anonymous-operations.js +11 -18
  47. package/cjs/rules/no-deprecated.d.ts +4 -3
  48. package/cjs/rules/no-deprecated.js +15 -29
  49. package/cjs/rules/no-duplicate-fields.d.ts +4 -3
  50. package/cjs/rules/no-duplicate-fields.js +13 -23
  51. package/cjs/rules/no-hashtag-description.d.ts +4 -3
  52. package/cjs/rules/no-hashtag-description.js +16 -29
  53. package/cjs/rules/no-one-place-fragments.d.ts +4 -3
  54. package/cjs/rules/no-one-place-fragments.js +17 -29
  55. package/cjs/rules/no-root-type.d.ts +4 -3
  56. package/cjs/rules/no-root-type.js +15 -25
  57. package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
  58. package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
  59. package/cjs/rules/no-typename-prefix.d.ts +4 -3
  60. package/cjs/rules/no-typename-prefix.js +26 -33
  61. package/cjs/rules/no-unreachable-types.d.ts +4 -3
  62. package/cjs/rules/no-unreachable-types.js +25 -47
  63. package/cjs/rules/no-unused-fields.d.ts +4 -3
  64. package/cjs/rules/no-unused-fields.js +24 -49
  65. package/cjs/rules/relay-arguments.d.ts +4 -3
  66. package/cjs/rules/relay-arguments.js +20 -43
  67. package/cjs/rules/relay-connection-types.d.ts +4 -3
  68. package/cjs/rules/relay-connection-types.js +14 -45
  69. package/cjs/rules/relay-edge-types.d.ts +4 -3
  70. package/cjs/rules/relay-edge-types.js +48 -99
  71. package/cjs/rules/relay-page-info.d.ts +4 -3
  72. package/cjs/rules/relay-page-info.js +21 -44
  73. package/cjs/rules/require-deprecation-date.d.ts +4 -3
  74. package/cjs/rules/require-deprecation-date.js +15 -31
  75. package/cjs/rules/require-deprecation-reason.d.ts +4 -3
  76. package/cjs/rules/require-deprecation-reason.js +12 -20
  77. package/cjs/rules/require-description.d.ts +4 -3
  78. package/cjs/rules/require-description.js +39 -65
  79. package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
  80. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
  81. package/cjs/rules/require-import-fragment.d.ts +4 -3
  82. package/cjs/rules/require-import-fragment.js +22 -40
  83. package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
  84. package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
  85. package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
  86. package/cjs/rules/require-nullable-result-in-root.js +34 -44
  87. package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
  88. package/cjs/rules/require-selections.js +198 -0
  89. package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
  90. package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
  91. package/cjs/rules/selection-set-depth.d.ts +4 -3
  92. package/cjs/rules/selection-set-depth.js +18 -34
  93. package/cjs/rules/strict-id-in-types.d.ts +4 -3
  94. package/cjs/rules/strict-id-in-types.js +25 -43
  95. package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
  96. package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
  97. package/cjs/rules/unique-fragment-name.d.ts +3 -2
  98. package/cjs/rules/unique-fragment-name.js +24 -36
  99. package/cjs/rules/unique-operation-name.d.ts +4 -3
  100. package/cjs/rules/unique-operation-name.js +10 -12
  101. package/cjs/schema.d.ts +4 -3
  102. package/cjs/schema.js +14 -27
  103. package/cjs/siblings.d.ts +24 -8
  104. package/cjs/siblings.js +42 -82
  105. package/cjs/types.d.ts +74 -7
  106. package/cjs/types.js +3 -5
  107. package/cjs/utils.d.ts +3 -2
  108. package/cjs/utils.js +27 -44
  109. package/esm/cache.js +4 -8
  110. package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
  111. package/esm/configs/index.d.mts +42 -16
  112. package/esm/configs/index.js +4 -4
  113. package/esm/configs/operations-all.d.mts +4 -3
  114. package/esm/configs/operations-all.js +6 -5
  115. package/esm/configs/operations-recommended.d.mts +3 -1
  116. package/esm/configs/operations-recommended.js +4 -2
  117. package/esm/configs/schema-all.d.mts +6 -1
  118. package/esm/configs/schema-all.js +6 -3
  119. package/esm/configs/schema-recommended.d.mts +19 -1
  120. package/esm/configs/schema-recommended.js +23 -3
  121. package/esm/configs/{relay.js → schema-relay.js} +4 -4
  122. package/esm/documents.js +10 -17
  123. package/esm/estree-converter/converter.js +9 -18
  124. package/esm/estree-converter/utils.d.mts +2 -3
  125. package/esm/estree-converter/utils.js +11 -38
  126. package/esm/flat-configs.d.mts +59 -12
  127. package/esm/flat-configs.js +4 -5
  128. package/esm/graphql-config.d.mts +4 -3
  129. package/esm/graphql-config.js +18 -34
  130. package/esm/index.d.mts +10 -4
  131. package/esm/index.js +1 -1
  132. package/esm/parser.d.mts +4 -3
  133. package/esm/parser.js +33 -27
  134. package/esm/processor.d.mts +5 -1
  135. package/esm/processor.js +21 -46
  136. package/esm/rules/alphabetize.d.mts +6 -16
  137. package/esm/rules/alphabetize.js +53 -118
  138. package/esm/rules/description-style.d.mts +4 -3
  139. package/esm/rules/description-style.js +7 -11
  140. package/esm/rules/graphql-js-validation.d.mts +4 -3
  141. package/esm/rules/graphql-js-validation.js +178 -218
  142. package/esm/rules/index.d.mts +15 -13
  143. package/esm/rules/index.js +5 -5
  144. package/esm/rules/input-name.d.mts +4 -3
  145. package/esm/rules/input-name.js +39 -52
  146. package/esm/rules/lone-executable-definition.d.mts +6 -5
  147. package/esm/rules/lone-executable-definition.js +10 -20
  148. package/esm/rules/match-document-filename.d.mts +4 -3
  149. package/esm/rules/match-document-filename.js +35 -61
  150. package/esm/rules/naming-convention.d.mts +4 -3
  151. package/esm/rules/naming-convention.js +51 -65
  152. package/esm/rules/no-anonymous-operations.d.mts +4 -3
  153. package/esm/rules/no-anonymous-operations.js +6 -9
  154. package/esm/rules/no-deprecated.d.mts +4 -3
  155. package/esm/rules/no-deprecated.js +10 -20
  156. package/esm/rules/no-duplicate-fields.d.mts +4 -3
  157. package/esm/rules/no-duplicate-fields.js +9 -16
  158. package/esm/rules/no-hashtag-description.d.mts +4 -3
  159. package/esm/rules/no-hashtag-description.js +11 -20
  160. package/esm/rules/no-one-place-fragments.d.mts +4 -3
  161. package/esm/rules/no-one-place-fragments.js +12 -19
  162. package/esm/rules/no-root-type.d.mts +4 -3
  163. package/esm/rules/no-root-type.js +11 -18
  164. package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
  165. package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
  166. package/esm/rules/no-typename-prefix.d.mts +4 -3
  167. package/esm/rules/no-typename-prefix.js +22 -26
  168. package/esm/rules/no-unreachable-types.d.mts +4 -3
  169. package/esm/rules/no-unreachable-types.js +18 -33
  170. package/esm/rules/no-unused-fields.d.mts +4 -3
  171. package/esm/rules/no-unused-fields.js +19 -40
  172. package/esm/rules/relay-arguments.d.mts +4 -3
  173. package/esm/rules/relay-arguments.js +15 -34
  174. package/esm/rules/relay-connection-types.d.mts +4 -3
  175. package/esm/rules/relay-connection-types.js +10 -38
  176. package/esm/rules/relay-edge-types.d.mts +4 -3
  177. package/esm/rules/relay-edge-types.js +43 -89
  178. package/esm/rules/relay-page-info.d.mts +4 -3
  179. package/esm/rules/relay-page-info.js +16 -34
  180. package/esm/rules/require-deprecation-date.d.mts +4 -3
  181. package/esm/rules/require-deprecation-date.js +10 -22
  182. package/esm/rules/require-deprecation-reason.d.mts +4 -3
  183. package/esm/rules/require-deprecation-reason.js +7 -11
  184. package/esm/rules/require-description.d.mts +4 -3
  185. package/esm/rules/require-description.js +34 -55
  186. package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
  187. package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
  188. package/esm/rules/require-import-fragment.d.mts +4 -3
  189. package/esm/rules/require-import-fragment.js +14 -26
  190. package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
  191. package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
  192. package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
  193. package/esm/rules/require-nullable-result-in-root.js +29 -35
  194. package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
  195. package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
  196. package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
  197. package/esm/rules/require-type-pattern-with-oneof.js +11 -16
  198. package/esm/rules/selection-set-depth.d.mts +4 -3
  199. package/esm/rules/selection-set-depth.js +11 -20
  200. package/esm/rules/strict-id-in-types.d.mts +4 -3
  201. package/esm/rules/strict-id-in-types.js +20 -34
  202. package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
  203. package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
  204. package/esm/rules/unique-fragment-name.d.mts +3 -2
  205. package/esm/rules/unique-fragment-name.js +20 -27
  206. package/esm/rules/unique-operation-name.d.mts +4 -3
  207. package/esm/rules/unique-operation-name.js +6 -5
  208. package/esm/schema.d.mts +4 -3
  209. package/esm/schema.js +7 -12
  210. package/esm/siblings.d.mts +24 -8
  211. package/esm/siblings.js +37 -73
  212. package/esm/types.d.mts +74 -7
  213. package/esm/utils.d.mts +3 -2
  214. package/esm/utils.js +20 -31
  215. package/index.browser.mjs +5323 -0
  216. package/package.json +8 -13
  217. package/cjs/rules/require-id-when-available.js +0 -241
  218. package/cjs/types-8d5f4ae0.d.ts +0 -107
  219. package/esm/types-ace77d86.d.ts +0 -107
  220. /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
  221. /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
  222. /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
@@ -3,18 +3,14 @@ var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
8
7
  var __export = (target, all) => {
9
8
  for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
9
+ __defProp(target, name, { get: all[name], enumerable: !0 });
10
+ }, __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from == "object" || typeof from == "function")
14
12
  for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
13
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
14
  return to;
19
15
  };
20
16
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
@@ -22,20 +18,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
18
  // file that has been converted to a CommonJS file using a Babel-
23
19
  // compatible transform (i.e. "__esModule" has not been set), then set
24
20
  // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
26
22
  mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
29
24
  var no_unreachable_types_exports = {};
30
25
  __export(no_unreachable_types_exports, {
31
26
  rule: () => rule
32
27
  });
33
28
  module.exports = __toCommonJS(no_unreachable_types_exports);
34
- var import_graphql = require("graphql");
35
- var import_lodash = __toESM(require("lodash.lowercase"));
36
- var import_utils = require("../utils.js");
37
- const RULE_ID = "no-unreachable-types";
38
- const KINDS = [
29
+ var import_graphql = require("graphql"), import_lodash = __toESM(require("lodash.lowercase")), import_utils = require("../utils.js");
30
+ const RULE_ID = "no-unreachable-types", KINDS = [
39
31
  import_graphql.Kind.DIRECTIVE_DEFINITION,
40
32
  import_graphql.Kind.OBJECT_TYPE_DEFINITION,
41
33
  import_graphql.Kind.OBJECT_TYPE_EXTENSION,
@@ -62,27 +54,21 @@ const RequestDirectiveLocations = /* @__PURE__ */ new Set([
62
54
  import_graphql.DirectiveLocation.VARIABLE_DEFINITION
63
55
  ]);
64
56
  function getReachableTypes(schema) {
65
- if (reachableTypesCache) {
57
+ if (reachableTypesCache)
66
58
  return reachableTypesCache;
67
- }
68
- const reachableTypes = /* @__PURE__ */ new Set();
69
- const collect = (node) => {
59
+ const reachableTypes = /* @__PURE__ */ new Set(), collect = (node) => {
70
60
  const typeName = (0, import_utils.getTypeName)(node);
71
- if (reachableTypes.has(typeName)) {
61
+ if (reachableTypes.has(typeName))
72
62
  return;
73
- }
74
63
  reachableTypes.add(typeName);
75
64
  const type = schema.getType(typeName) || schema.getDirective(typeName);
76
65
  if ((0, import_graphql.isInterfaceType)(type)) {
77
66
  const { objects, interfaces } = schema.getImplementations(type);
78
- for (const { astNode } of [...objects, ...interfaces]) {
67
+ for (const { astNode } of [...objects, ...interfaces])
79
68
  (0, import_graphql.visit)(astNode, visitor);
80
- }
81
- } else if (type == null ? void 0 : type.astNode) {
82
- (0, import_graphql.visit)(type.astNode, visitor);
83
- }
84
- };
85
- const visitor = {
69
+ } else
70
+ type?.astNode && (0, import_graphql.visit)(type.astNode, visitor);
71
+ }, visitor = {
86
72
  InterfaceTypeDefinition: collect,
87
73
  ObjectTypeDefinition: collect,
88
74
  InputValueDefinition: collect,
@@ -97,24 +83,17 @@ function getReachableTypes(schema) {
97
83
  schema.getQueryType(),
98
84
  schema.getMutationType(),
99
85
  schema.getSubscriptionType()
100
- ]) {
101
- if (type == null ? void 0 : type.astNode) {
102
- (0, import_graphql.visit)(type.astNode, visitor);
103
- }
104
- }
105
- for (const node of schema.getDirectives()) {
86
+ ])
87
+ type?.astNode && (0, import_graphql.visit)(type.astNode, visitor);
88
+ for (const node of schema.getDirectives())
106
89
  if (node.locations.some((location) => RequestDirectiveLocations.has(location))) {
107
90
  reachableTypes.add(node.name);
108
91
  for (const arg of node.args) {
109
92
  const argTypeName = "name" in arg.type && arg.type.name;
110
- if (argTypeName) {
111
- reachableTypes.add(argTypeName);
112
- }
93
+ argTypeName && reachableTypes.add(argTypeName);
113
94
  }
114
95
  }
115
- }
116
- reachableTypesCache = reachableTypes;
117
- return reachableTypesCache;
96
+ return reachableTypesCache = reachableTypes, reachableTypesCache;
118
97
  }
119
98
  const rule = {
120
99
  meta: {
@@ -125,7 +104,7 @@ const rule = {
125
104
  description: "Requires all types to be reachable at some level by root level fields.",
126
105
  category: "Schema",
127
106
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
128
- requiresSchema: true,
107
+ requiresSchema: !0,
129
108
  examples: [
130
109
  {
131
110
  title: "Incorrect",
@@ -160,15 +139,14 @@ const rule = {
160
139
  )
161
140
  }
162
141
  ],
163
- recommended: true
142
+ recommended: !0
164
143
  },
165
144
  type: "suggestion",
166
145
  schema: [],
167
- hasSuggestions: true
146
+ hasSuggestions: !0
168
147
  },
169
148
  create(context) {
170
- const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context);
171
- const reachableTypes = getReachableTypes(schema);
149
+ const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context), reachableTypes = getReachableTypes(schema);
172
150
  return {
173
151
  [`:matches(${KINDS}) > .name`](node) {
174
152
  const typeName = node.value;
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-8d5f4ae0.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.js';
3
2
  import 'eslint';
4
3
  import 'estree';
5
4
  import 'graphql';
6
- import 'graphql-config';
7
5
  import 'json-schema-to-ts';
6
+ import '../siblings.js';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.js';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -5,51 +5,36 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
7
  for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
12
11
  for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
13
  return to;
17
14
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
19
16
  var no_unused_fields_exports = {};
20
17
  __export(no_unused_fields_exports, {
21
18
  rule: () => rule
22
19
  });
23
20
  module.exports = __toCommonJS(no_unused_fields_exports);
24
- var import_graphql = require("graphql");
25
- var import_utils = require("../utils.js");
21
+ var import_graphql = require("graphql"), import_utils = require("../utils.js");
26
22
  const RULE_ID = "no-unused-fields";
27
23
  let usedFieldsCache;
28
24
  function getUsedFields(schema, operations) {
29
- if (usedFieldsCache) {
25
+ if (usedFieldsCache)
30
26
  return usedFieldsCache;
31
- }
32
- const usedFields = /* @__PURE__ */ Object.create(null);
33
- const typeInfo = new import_graphql.TypeInfo(schema);
34
- const visitor = (0, import_graphql.visitWithTypeInfo)(typeInfo, {
27
+ const usedFields = /* @__PURE__ */ Object.create(null), typeInfo = new import_graphql.TypeInfo(schema), visitor = (0, import_graphql.visitWithTypeInfo)(typeInfo, {
35
28
  Field(node) {
36
- var _a;
37
- const fieldDef = typeInfo.getFieldDef();
38
- if (!fieldDef) {
39
- return false;
40
- }
41
- const parentTypeName = typeInfo.getParentType().name;
42
- const fieldName = node.name.value;
43
- (_a = usedFields[parentTypeName]) != null ? _a : usedFields[parentTypeName] = /* @__PURE__ */ new Set();
44
- usedFields[parentTypeName].add(fieldName);
29
+ if (!typeInfo.getFieldDef())
30
+ return !1;
31
+ const parentTypeName = typeInfo.getParentType().name, fieldName = node.name.value;
32
+ usedFields[parentTypeName] ??= /* @__PURE__ */ new Set(), usedFields[parentTypeName].add(fieldName);
45
33
  }
46
- });
47
- const allDocuments = [...operations.getOperations(), ...operations.getFragments()];
48
- for (const { document } of allDocuments) {
34
+ }), allDocuments = [...operations.getOperations(), ...operations.getFragments()];
35
+ for (const { document } of allDocuments)
49
36
  (0, import_graphql.visit)(document, visitor);
50
- }
51
- usedFieldsCache = usedFields;
52
- return usedFieldsCache;
37
+ return usedFieldsCache = usedFields, usedFieldsCache;
53
38
  }
54
39
  const rule = {
55
40
  meta: {
@@ -60,9 +45,10 @@ const rule = {
60
45
  description: "Requires all fields to be used at some level by siblings operations.",
61
46
  category: "Schema",
62
47
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
63
- requiresSiblings: true,
64
- requiresSchema: true,
65
- isDisabledForAllConfig: true,
48
+ requiresSiblings: !0,
49
+ requiresSchema: !0,
50
+ // Requires documents to be set
51
+ isDisabledForAllConfig: !0,
66
52
  examples: [
67
53
  {
68
54
  title: "Incorrect",
@@ -115,22 +101,14 @@ const rule = {
115
101
  },
116
102
  type: "suggestion",
117
103
  schema: [],
118
- hasSuggestions: true
104
+ hasSuggestions: !0
119
105
  },
120
106
  create(context) {
121
- const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context);
122
- const siblingsOperations = (0, import_utils.requireSiblingsOperations)(RULE_ID, context);
123
- const usedFields = getUsedFields(schema, siblingsOperations);
107
+ const schema = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context), siblingsOperations = (0, import_utils.requireSiblingsOperations)(RULE_ID, context), usedFields = getUsedFields(schema, siblingsOperations);
124
108
  return {
125
109
  FieldDefinition(node) {
126
- var _a;
127
- const fieldName = node.name.value;
128
- const parentTypeName = node.parent.name.value;
129
- const isUsed = (_a = usedFields[parentTypeName]) == null ? void 0 : _a.has(fieldName);
130
- if (isUsed) {
131
- return;
132
- }
133
- context.report({
110
+ const fieldName = node.name.value, parentTypeName = node.parent.name.value;
111
+ usedFields[parentTypeName]?.has(fieldName) || context.report({
134
112
  node: node.name,
135
113
  messageId: RULE_ID,
136
114
  data: { fieldName },
@@ -138,10 +116,7 @@ const rule = {
138
116
  {
139
117
  desc: `Remove \`${fieldName}\` field`,
140
118
  fix(fixer) {
141
- const sourceCode = context.getSourceCode();
142
- const tokenBefore = sourceCode.getTokenBefore(node);
143
- const tokenAfter = sourceCode.getTokenAfter(node);
144
- const isEmptyType = tokenBefore.type === "{" && tokenAfter.type === "}";
119
+ const sourceCode = context.getSourceCode(), tokenBefore = sourceCode.getTokenBefore(node), tokenAfter = sourceCode.getTokenAfter(node), isEmptyType = tokenBefore.type === "{" && tokenAfter.type === "}";
145
120
  return fixer.remove(isEmptyType ? node.parent : node);
146
121
  }
147
122
  }
@@ -1,11 +1,12 @@
1
1
  import { FromSchema } from 'json-schema-to-ts';
2
- import { f as GraphQLESLintRule } from '../types-8d5f4ae0.js';
3
- import '@graphql-tools/utils';
2
+ import { GraphQLESLintRule } from '../types.js';
4
3
  import 'eslint';
5
4
  import 'estree';
6
5
  import 'graphql';
7
- import 'graphql-config';
6
+ import '../siblings.js';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.js';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const schema: {
11
12
  readonly type: "array";
@@ -5,43 +5,36 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
7
  for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
12
11
  for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
13
  return to;
17
14
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
19
16
  var relay_arguments_exports = {};
20
17
  __export(relay_arguments_exports, {
21
18
  rule: () => rule
22
19
  });
23
20
  module.exports = __toCommonJS(relay_arguments_exports);
24
- var import_graphql = require("graphql");
25
- var import_utils = require("../utils.js");
26
- const RULE_ID = "relay-arguments";
27
- const MISSING_ARGUMENTS = "MISSING_ARGUMENTS";
28
- const schema = {
21
+ var import_graphql = require("graphql"), import_utils = require("../utils.js");
22
+ const RULE_ID = "relay-arguments", MISSING_ARGUMENTS = "MISSING_ARGUMENTS", schema = {
29
23
  type: "array",
30
24
  maxItems: 1,
31
25
  items: {
32
26
  type: "object",
33
- additionalProperties: false,
27
+ additionalProperties: !1,
34
28
  minProperties: 1,
35
29
  properties: {
36
30
  includeBoth: {
37
31
  type: "boolean",
38
- default: true,
32
+ default: !0,
39
33
  description: "Enforce including both forward and backward pagination arguments"
40
34
  }
41
35
  }
42
36
  }
43
- };
44
- const rule = {
37
+ }, rule = {
45
38
  meta: {
46
39
  type: "problem",
47
40
  docs: {
@@ -60,7 +53,8 @@ const rule = {
60
53
  "",
61
54
  "- `last` takes a non-negative integer",
62
55
  "- `before` takes the Cursor type"
63
- ].join("\n"),
56
+ ].join(`
57
+ `),
64
58
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
65
59
  examples: [
66
60
  {
@@ -86,7 +80,7 @@ const rule = {
86
80
  )
87
81
  }
88
82
  ],
89
- isDisabledForAllConfig: true
83
+ isDisabledForAllConfig: !0
90
84
  },
91
85
  messages: {
92
86
  [MISSING_ARGUMENTS]: "A field that returns a Connection type must include forward pagination arguments (`first` and `after`), backward pagination arguments (`last` and `before`), or both."
@@ -94,20 +88,15 @@ const rule = {
94
88
  schema
95
89
  },
96
90
  create(context) {
97
- const schema2 = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context);
98
- const { includeBoth = true } = context.options[0] || {};
91
+ const schema2 = (0, import_utils.requireGraphQLSchemaFromContext)(RULE_ID, context), { includeBoth = !0 } = context.options[0] || {};
99
92
  return {
100
93
  "FieldDefinition > .gqlType Name[value=/Connection$/]"(node) {
101
- var _a;
102
94
  let fieldNode = node.parent;
103
- while (fieldNode.kind !== import_graphql.Kind.FIELD_DEFINITION) {
95
+ for (; fieldNode.kind !== import_graphql.Kind.FIELD_DEFINITION; )
104
96
  fieldNode = fieldNode.parent;
105
- }
106
97
  const args = Object.fromEntries(
107
- ((_a = fieldNode.arguments) == null ? void 0 : _a.map((argument) => [argument.name.value, argument])) || []
108
- );
109
- const hasForwardPagination = !!(args.first && args.after);
110
- const hasBackwardPagination = !!(args.last && args.before);
98
+ fieldNode.arguments?.map((argument) => [argument.name.value, argument]) || []
99
+ ), hasForwardPagination = !!(args.first && args.after), hasBackwardPagination = !!(args.last && args.before);
111
100
  if (!hasForwardPagination && !hasBackwardPagination) {
112
101
  context.report({
113
102
  node: fieldNode.name,
@@ -116,14 +105,9 @@ const rule = {
116
105
  return;
117
106
  }
118
107
  function checkField(typeName, argumentName) {
119
- const argument = args[argumentName];
120
- const hasArgument = !!argument;
108
+ const argument = args[argumentName], hasArgument = !!argument;
121
109
  let type = argument;
122
- if (hasArgument && type.gqlType.kind === import_graphql.Kind.NON_NULL_TYPE) {
123
- type = type.gqlType;
124
- }
125
- const isAllowedNonNullType = hasArgument && type.gqlType.kind === import_graphql.Kind.NAMED_TYPE && (type.gqlType.name.value === typeName || typeName === "String" && (0, import_graphql.isScalarType)(schema2.getType(type.gqlType.name.value)));
126
- if (!isAllowedNonNullType) {
110
+ if (hasArgument && type.gqlType.kind === import_graphql.Kind.NON_NULL_TYPE && (type = type.gqlType), !(hasArgument && type.gqlType.kind === import_graphql.Kind.NAMED_TYPE && (type.gqlType.name.value === typeName || typeName === "String" && (0, import_graphql.isScalarType)(schema2.getType(type.gqlType.name.value))))) {
127
111
  const returnType = typeName === "String" ? "String or Scalar" : typeName;
128
112
  context.report({
129
113
  node: (argument || fieldNode).name,
@@ -131,14 +115,7 @@ const rule = {
131
115
  });
132
116
  }
133
117
  }
134
- if (includeBoth || args.first || args.after) {
135
- checkField("Int", "first");
136
- checkField("String", "after");
137
- }
138
- if (includeBoth || args.last || args.before) {
139
- checkField("Int", "last");
140
- checkField("String", "before");
141
- }
118
+ (includeBoth || args.first || args.after) && (checkField("Int", "first"), checkField("String", "after")), (includeBoth || args.last || args.before) && (checkField("Int", "last"), checkField("String", "before"));
142
119
  }
143
120
  };
144
121
  }
@@ -1,11 +1,12 @@
1
1
  import { Kind } from 'graphql';
2
- import { f as GraphQLESLintRule } from '../types-8d5f4ae0.js';
3
- import '@graphql-tools/utils';
2
+ import { GraphQLESLintRule } from '../types.js';
4
3
  import 'eslint';
5
4
  import 'estree';
6
- import 'graphql-config';
7
5
  import 'json-schema-to-ts';
6
+ import '../siblings.js';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.js';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const NON_OBJECT_TYPES: Kind[];
11
12
  declare const rule: GraphQLESLintRule;
@@ -5,17 +5,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
7
  for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
12
11
  for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
13
  return to;
17
14
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
19
16
  var relay_connection_types_exports = {};
20
17
  __export(relay_connection_types_exports, {
21
18
  NON_OBJECT_TYPES: () => NON_OBJECT_TYPES,
@@ -23,13 +20,7 @@ __export(relay_connection_types_exports, {
23
20
  });
24
21
  module.exports = __toCommonJS(relay_connection_types_exports);
25
22
  var import_graphql = require("graphql");
26
- const MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE";
27
- const MUST_CONTAIN_FIELD_EDGES = "MUST_CONTAIN_FIELD_EDGES";
28
- const MUST_CONTAIN_FIELD_PAGE_INFO = "MUST_CONTAIN_FIELD_PAGE_INFO";
29
- const MUST_HAVE_CONNECTION_SUFFIX = "MUST_HAVE_CONNECTION_SUFFIX";
30
- const EDGES_FIELD_MUST_RETURN_LIST_TYPE = "EDGES_FIELD_MUST_RETURN_LIST_TYPE";
31
- const PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE = "PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE";
32
- const NON_OBJECT_TYPES = [
23
+ const MUST_BE_OBJECT_TYPE = "MUST_BE_OBJECT_TYPE", MUST_CONTAIN_FIELD_EDGES = "MUST_CONTAIN_FIELD_EDGES", MUST_CONTAIN_FIELD_PAGE_INFO = "MUST_CONTAIN_FIELD_PAGE_INFO", MUST_HAVE_CONNECTION_SUFFIX = "MUST_HAVE_CONNECTION_SUFFIX", EDGES_FIELD_MUST_RETURN_LIST_TYPE = "EDGES_FIELD_MUST_RETURN_LIST_TYPE", PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE = "PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE", NON_OBJECT_TYPES = [
33
24
  import_graphql.Kind.SCALAR_TYPE_DEFINITION,
34
25
  import_graphql.Kind.UNION_TYPE_DEFINITION,
35
26
  import_graphql.Kind.UNION_TYPE_EXTENSION,
@@ -39,17 +30,7 @@ const NON_OBJECT_TYPES = [
39
30
  import_graphql.Kind.ENUM_TYPE_EXTENSION,
40
31
  import_graphql.Kind.INTERFACE_TYPE_DEFINITION,
41
32
  import_graphql.Kind.INTERFACE_TYPE_EXTENSION
42
- ];
43
- const notConnectionTypesSelector = `:matches(${NON_OBJECT_TYPES})[name.value=/Connection$/] > .name`;
44
- const hasEdgesField = (node) => {
45
- var _a;
46
- return (_a = node.fields) == null ? void 0 : _a.some((field) => field.name.value === "edges");
47
- };
48
- const hasPageInfoField = (node) => {
49
- var _a;
50
- return (_a = node.fields) == null ? void 0 : _a.some((field) => field.name.value === "pageInfo");
51
- };
52
- const rule = {
33
+ ], notConnectionTypesSelector = `:matches(${NON_OBJECT_TYPES})[name.value=/Connection$/] > .name`, hasEdgesField = (node) => node.fields?.some((field) => field.name.value === "edges"), hasPageInfoField = (node) => node.fields?.some((field) => field.name.value === "pageInfo"), rule = {
53
34
  meta: {
54
35
  type: "problem",
55
36
  docs: {
@@ -61,9 +42,10 @@ const rule = {
61
42
  "- Connection type must be an Object type",
62
43
  "- Connection type must contain a field `edges` that return a list type that wraps an edge type",
63
44
  "- Connection type must contain a field `pageInfo` that return a non-null `PageInfo` Object type"
64
- ].join("\n"),
45
+ ].join(`
46
+ `),
65
47
  url: "https://the-guild.dev/graphql/eslint/rules/relay-connection-types",
66
- isDisabledForAllConfig: true,
48
+ isDisabledForAllConfig: !0,
67
49
  examples: [
68
50
  {
69
51
  title: "Incorrect",
@@ -108,29 +90,16 @@ const rule = {
108
90
  context.report({ node, messageId: MUST_BE_OBJECT_TYPE });
109
91
  },
110
92
  ":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value!=/Connection$/]"(node) {
111
- if (hasEdgesField(node) && hasPageInfoField(node)) {
112
- context.report({ node: node.name, messageId: MUST_HAVE_CONNECTION_SUFFIX });
113
- }
93
+ hasEdgesField(node) && hasPageInfoField(node) && context.report({ node: node.name, messageId: MUST_HAVE_CONNECTION_SUFFIX });
114
94
  },
115
95
  ":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Connection$/]"(node) {
116
- if (!hasEdgesField(node)) {
117
- context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_EDGES });
118
- }
119
- if (!hasPageInfoField(node)) {
120
- context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_PAGE_INFO });
121
- }
96
+ hasEdgesField(node) || context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_EDGES }), hasPageInfoField(node) || context.report({ node: node.name, messageId: MUST_CONTAIN_FIELD_PAGE_INFO });
122
97
  },
123
98
  ":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Connection$/] > FieldDefinition[name.value=edges] > .gqlType"(node) {
124
- const isListType = node.kind === import_graphql.Kind.LIST_TYPE || node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.LIST_TYPE;
125
- if (!isListType) {
126
- context.report({ node, messageId: EDGES_FIELD_MUST_RETURN_LIST_TYPE });
127
- }
99
+ node.kind === import_graphql.Kind.LIST_TYPE || node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.LIST_TYPE || context.report({ node, messageId: EDGES_FIELD_MUST_RETURN_LIST_TYPE });
128
100
  },
129
101
  ":matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Connection$/] > FieldDefinition[name.value=pageInfo] > .gqlType"(node) {
130
- const isNonNullPageInfoType = node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.NAMED_TYPE && node.gqlType.name.value === "PageInfo";
131
- if (!isNonNullPageInfoType) {
132
- context.report({ node, messageId: PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE });
133
- }
102
+ node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.NAMED_TYPE && node.gqlType.name.value === "PageInfo" || context.report({ node, messageId: PAGE_INFO_FIELD_MUST_RETURN_NON_NULL_TYPE });
134
103
  }
135
104
  };
136
105
  }
@@ -1,11 +1,12 @@
1
1
  import { FromSchema } from 'json-schema-to-ts';
2
- import { f as GraphQLESLintRule } from '../types-8d5f4ae0.js';
3
- import '@graphql-tools/utils';
2
+ import { GraphQLESLintRule } from '../types.js';
4
3
  import 'eslint';
5
4
  import 'estree';
6
5
  import 'graphql';
7
- import 'graphql-config';
6
+ import '../siblings.js';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.js';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const schema: {
11
12
  readonly type: "array";