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

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 (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
@@ -1,4 +1,4 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { asArray } from "@graphql-tools/utils";
3
3
  import {
4
4
  GraphQLInterfaceType,
@@ -16,9 +16,7 @@ import {
16
16
  requireGraphQLSchemaFromContext,
17
17
  requireSiblingsOperations
18
18
  } from "../utils.js";
19
- const RULE_ID = "require-id-when-available";
20
- const DEFAULT_ID_FIELD_NAME = "id";
21
- const schema = {
19
+ const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
22
20
  definitions: {
23
21
  asString: {
24
22
  type: "string"
@@ -29,7 +27,7 @@ const schema = {
29
27
  maxItems: 1,
30
28
  items: {
31
29
  type: "object",
32
- additionalProperties: false,
30
+ additionalProperties: !1,
33
31
  properties: {
34
32
  fieldName: {
35
33
  oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asArray" }],
@@ -37,17 +35,16 @@ const schema = {
37
35
  }
38
36
  }
39
37
  }
40
- };
41
- const rule = {
38
+ }, rule = {
42
39
  meta: {
43
40
  type: "suggestion",
44
- hasSuggestions: true,
41
+ hasSuggestions: !0,
45
42
  docs: {
46
43
  category: "Operations",
47
44
  description: "Enforce selecting specific fields when they are available on the GraphQL type.",
48
45
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
49
- requiresSchema: true,
50
- requiresSiblings: true,
46
+ requiresSchema: !0,
47
+ requiresSiblings: !0,
51
48
  examples: [
52
49
  {
53
50
  title: "Incorrect",
@@ -98,44 +95,33 @@ const rule = {
98
95
  )
99
96
  }
100
97
  ],
101
- recommended: true
98
+ recommended: !0
102
99
  },
103
100
  messages: {
104
- [RULE_ID]: "Field{{ pluralSuffix }} {{ fieldName }} must be selected when it's available on a type.\nInclude it in your selection set{{ addition }}."
101
+ [RULE_ID]: `Field{{ pluralSuffix }} {{ fieldName }} must be selected when it's available on a type.
102
+ Include it in your selection set{{ addition }}.`
105
103
  },
106
104
  schema
107
105
  },
108
106
  create(context) {
109
- const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
110
- const siblings = requireSiblingsOperations(RULE_ID, context);
111
- const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
112
- const idNames = asArray(fieldName);
113
- const selector = "OperationDefinition SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]";
114
- const typeInfo = new TypeInfo(schema2);
107
+ const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context), siblings = requireSiblingsOperations(RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = asArray(fieldName), selector = "OperationDefinition SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo(schema2);
115
108
  function checkFragments(node) {
116
109
  for (const selection of node.selections) {
117
- if (selection.kind !== Kind.FRAGMENT_SPREAD) {
110
+ if (selection.kind !== Kind.FRAGMENT_SPREAD)
118
111
  continue;
119
- }
120
112
  const [foundSpread] = siblings.getFragment(selection.name.value);
121
- if (!foundSpread) {
113
+ if (!foundSpread)
122
114
  continue;
123
- }
124
- const checkedFragmentSpreads = /* @__PURE__ */ new Set();
125
- const visitor = visitWithTypeInfo(typeInfo, {
115
+ const checkedFragmentSpreads = /* @__PURE__ */ new Set(), visitor = visitWithTypeInfo(typeInfo, {
126
116
  SelectionSet(node2, key, _parent) {
127
117
  const parent = _parent;
128
- if (parent.kind === Kind.FRAGMENT_DEFINITION) {
129
- checkedFragmentSpreads.add(parent.name.value);
130
- } else if (parent.kind !== Kind.INLINE_FRAGMENT) {
131
- checkSelections(
132
- node2,
133
- typeInfo.getType(),
134
- selection.loc.start,
135
- parent,
136
- checkedFragmentSpreads
137
- );
138
- }
118
+ parent.kind === Kind.FRAGMENT_DEFINITION ? checkedFragmentSpreads.add(parent.name.value) : parent.kind !== Kind.INLINE_FRAGMENT && checkSelections(
119
+ node2,
120
+ typeInfo.getType(),
121
+ selection.loc.start,
122
+ parent,
123
+ checkedFragmentSpreads
124
+ );
139
125
  }
140
126
  });
141
127
  visit(foundSpread.document, visitor);
@@ -143,58 +129,41 @@ const rule = {
143
129
  }
144
130
  function checkSelections(node, type, loc, parent, checkedFragmentSpreads = /* @__PURE__ */ new Set()) {
145
131
  const rawType = getBaseType(type);
146
- if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType) {
132
+ if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType)
147
133
  checkFields(rawType);
148
- } else if (rawType instanceof GraphQLUnionType) {
149
- for (const selection of node.selections) {
134
+ else if (rawType instanceof GraphQLUnionType) {
135
+ for (const selection of node.selections)
150
136
  if (selection.kind === Kind.INLINE_FRAGMENT) {
151
- const types = rawType.getTypes();
152
- const t = types.find((t2) => t2.name === selection.typeCondition.name.value);
153
- if (t) {
154
- checkFields(t);
155
- }
137
+ const t = rawType.getTypes().find((t2) => t2.name === selection.typeCondition.name.value);
138
+ t && checkFields(t);
156
139
  }
157
- }
158
140
  }
159
141
  function checkFields(rawType2) {
160
142
  const fields = rawType2.getFields();
161
- const hasIdFieldInType = idNames.some((name) => fields[name]);
162
- if (!hasIdFieldInType) {
143
+ if (!idNames.some((name) => fields[name]))
163
144
  return;
164
- }
165
145
  function hasIdField({ selections }) {
166
146
  return selections.some((selection) => {
167
- if (selection.kind === Kind.FIELD) {
168
- if (selection.alias && idNames.includes(selection.alias.value)) {
169
- return true;
170
- }
171
- return idNames.includes(selection.name.value);
172
- }
173
- if (selection.kind === Kind.INLINE_FRAGMENT) {
147
+ if (selection.kind === Kind.FIELD)
148
+ return selection.alias && idNames.includes(selection.alias.value) ? !0 : idNames.includes(selection.name.value);
149
+ if (selection.kind === Kind.INLINE_FRAGMENT)
174
150
  return hasIdField(selection.selectionSet);
175
- }
176
151
  if (selection.kind === Kind.FRAGMENT_SPREAD) {
177
152
  const [foundSpread] = siblings.getFragment(selection.name.value);
178
153
  if (foundSpread) {
179
154
  const fragmentSpread = foundSpread.document;
180
- checkedFragmentSpreads.add(fragmentSpread.name.value);
181
- return hasIdField(fragmentSpread.selectionSet);
155
+ return checkedFragmentSpreads.add(fragmentSpread.name.value), hasIdField(fragmentSpread.selectionSet);
182
156
  }
183
157
  }
184
- return false;
158
+ return !1;
185
159
  });
186
160
  }
187
161
  const hasId = hasIdField(node);
188
- checkFragments(node);
189
- if (hasId) {
162
+ if (checkFragments(node), hasId)
190
163
  return;
191
- }
192
- const pluralSuffix = idNames.length > 1 ? "s" : "";
193
- const fieldName2 = englishJoinWords(
164
+ const pluralSuffix = idNames.length > 1 ? "s" : "", fieldName2 = englishJoinWords(
194
165
  idNames.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
195
- );
196
- const addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`;
197
- const problem = {
166
+ ), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
198
167
  loc,
199
168
  messageId: RULE_ID,
200
169
  data: {
@@ -203,25 +172,19 @@ const rule = {
203
172
  addition
204
173
  }
205
174
  };
206
- if ("type" in node) {
207
- problem.suggest = idNames.map((idName) => ({
208
- desc: `Add \`${idName}\` selection`,
209
- fix: (fixer) => {
210
- let insertNode = node.selections[0];
211
- insertNode = insertNode.kind === Kind.INLINE_FRAGMENT ? insertNode.selectionSet.selections[0] : insertNode;
212
- return fixer.insertTextBefore(insertNode, `${idName} `);
213
- }
214
- }));
215
- }
216
- context.report(problem);
175
+ "type" in node && (problem.suggest = idNames.map((idName) => ({
176
+ desc: `Add \`${idName}\` selection`,
177
+ fix: (fixer) => {
178
+ let insertNode = node.selections[0];
179
+ return insertNode = insertNode.kind === Kind.INLINE_FRAGMENT ? insertNode.selectionSet.selections[0] : insertNode, fixer.insertTextBefore(insertNode, `${idName} `);
180
+ }
181
+ }))), context.report(problem);
217
182
  }
218
183
  }
219
184
  return {
220
185
  [selector](node) {
221
186
  const typeInfo2 = node.typeInfo();
222
- if (typeInfo2.gqlType) {
223
- checkSelections(node, typeInfo2.gqlType, node.loc.start, node.parent);
224
- }
187
+ typeInfo2.gqlType && checkSelections(node, typeInfo2.gqlType, node.loc.start, node.parent);
225
188
  }
226
189
  };
227
190
  }
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
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.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -1,7 +1,6 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { displayNodeName } from "../utils.js";
3
- const RULE_ID = "require-type-pattern-with-oneof";
4
- const rule = {
3
+ const RULE_ID = "require-type-pattern-with-oneof", rule = {
5
4
  meta: {
6
5
  type: "suggestion",
7
6
  docs: {
@@ -45,20 +44,16 @@ const rule = {
45
44
  "Directive[name.value=oneOf][parent.kind=ObjectTypeDefinition]"({
46
45
  parent
47
46
  }) {
48
- var _a;
49
47
  const requiredFields = ["error", "ok"];
50
- for (const fieldName of requiredFields) {
51
- if (!((_a = parent.fields) == null ? void 0 : _a.some((field) => field.name.value === fieldName))) {
52
- context.report({
53
- node: parent.name,
54
- messageId: RULE_ID,
55
- data: {
56
- nodeName: displayNodeName(parent),
57
- fieldName
58
- }
59
- });
60
- }
61
- }
48
+ for (const fieldName of requiredFields)
49
+ parent.fields?.some((field) => field.name.value === fieldName) || context.report({
50
+ node: parent.name,
51
+ messageId: RULE_ID,
52
+ data: {
53
+ nodeName: displayNodeName(parent),
54
+ fieldName
55
+ }
56
+ });
62
57
  }
63
58
  };
64
59
  }
@@ -1,11 +1,12 @@
1
1
  import { FromSchema } from 'json-schema-to-ts';
2
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
3
- import '@graphql-tools/utils';
2
+ import { GraphQLESLintRule } from '../types.mjs';
4
3
  import 'eslint';
5
4
  import 'estree';
6
5
  import 'graphql';
7
- import 'graphql-config';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const schema: {
11
12
  readonly type: "array";
@@ -1,15 +1,14 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { Kind } from "graphql";
3
3
  import depthLimit from "graphql-depth-limit";
4
4
  import { ARRAY_DEFAULT_OPTIONS, logger, requireSiblingsOperations } from "../utils.js";
5
- const RULE_ID = "selection-set-depth";
6
- const schema = {
5
+ const RULE_ID = "selection-set-depth", schema = {
7
6
  type: "array",
8
7
  minItems: 1,
9
8
  maxItems: 1,
10
9
  items: {
11
10
  type: "object",
12
- additionalProperties: false,
11
+ additionalProperties: !1,
13
12
  required: ["maxDepth"],
14
13
  properties: {
15
14
  maxDepth: {
@@ -18,16 +17,15 @@ const schema = {
18
17
  ignore: ARRAY_DEFAULT_OPTIONS
19
18
  }
20
19
  }
21
- };
22
- const rule = {
20
+ }, rule = {
23
21
  meta: {
24
22
  type: "suggestion",
25
- hasSuggestions: true,
23
+ hasSuggestions: !0,
26
24
  docs: {
27
25
  category: "Operations",
28
26
  description: "Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).",
29
27
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
30
- requiresSiblings: true,
28
+ requiresSiblings: !0,
31
29
  examples: [
32
30
  {
33
31
  title: "Incorrect",
@@ -69,7 +67,7 @@ const rule = {
69
67
  `
70
68
  }
71
69
  ],
72
- recommended: true,
70
+ recommended: !0,
73
71
  configOptions: [{ maxDepth: 7 }]
74
72
  },
75
73
  schema
@@ -83,23 +81,18 @@ const rule = {
83
81
  `Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`
84
82
  );
85
83
  }
86
- const { maxDepth, ignore = [] } = context.options[0];
87
- const checkFn = depthLimit(maxDepth, { ignore });
84
+ const { maxDepth, ignore = [] } = context.options[0], checkFn = depthLimit(maxDepth, { ignore });
88
85
  return {
89
86
  "OperationDefinition, FragmentDefinition"(node) {
90
87
  try {
91
- const rawNode = node.rawNode();
92
- const fragmentsInUse = siblings ? siblings.getFragmentsInUse(rawNode) : [];
93
- const document = {
88
+ const rawNode = node.rawNode(), fragmentsInUse = siblings ? siblings.getFragmentsInUse(rawNode) : [], document = {
94
89
  kind: Kind.DOCUMENT,
95
90
  definitions: [rawNode, ...fragmentsInUse]
96
91
  };
97
92
  checkFn({
98
93
  getDocument: () => document,
99
94
  reportError(error) {
100
- const { line, column } = error.locations[0];
101
- const ancestors = context.getAncestors();
102
- const token = ancestors[0].tokens.find(
95
+ const { line, column } = error.locations[0], token = context.getAncestors()[0].tokens.find(
103
96
  (token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
104
97
  );
105
98
  context.report({
@@ -114,9 +107,7 @@ const rule = {
114
107
  {
115
108
  desc: "Remove selections",
116
109
  fix(fixer) {
117
- const sourceCode = context.getSourceCode();
118
- const foundNode = sourceCode.getNodeByRangeIndex(token.range[0]);
119
- const parentNode = foundNode.parent.parent;
110
+ const foundNode = context.getSourceCode().getNodeByRangeIndex(token.range[0]), parentNode = foundNode.parent.parent;
120
111
  return fixer.remove(
121
112
  foundNode.kind === "Name" ? parentNode.parent : parentNode
122
113
  );
@@ -1,11 +1,12 @@
1
1
  import { FromSchema } from 'json-schema-to-ts';
2
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
3
- import '@graphql-tools/utils';
2
+ import { GraphQLESLintRule } from '../types.mjs';
4
3
  import 'eslint';
5
4
  import 'estree';
6
5
  import 'graphql';
7
- import 'graphql-config';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const schema: {
11
12
  readonly type: "array";
@@ -1,4 +1,4 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { Kind } from "graphql";
3
3
  import {
4
4
  ARRAY_DEFAULT_OPTIONS,
@@ -7,13 +7,12 @@ import {
7
7
  requireGraphQLSchemaFromContext,
8
8
  truthy
9
9
  } from "../utils.js";
10
- const RULE_ID = "strict-id-in-types";
11
- const schema = {
10
+ const RULE_ID = "strict-id-in-types", schema = {
12
11
  type: "array",
13
12
  maxItems: 1,
14
13
  items: {
15
14
  type: "object",
16
- additionalProperties: false,
15
+ additionalProperties: !1,
17
16
  properties: {
18
17
  acceptedIdNames: {
19
18
  ...ARRAY_DEFAULT_OPTIONS,
@@ -25,7 +24,7 @@ const schema = {
25
24
  },
26
25
  exceptions: {
27
26
  type: "object",
28
- additionalProperties: false,
27
+ additionalProperties: !1,
29
28
  properties: {
30
29
  types: {
31
30
  ...ARRAY_DEFAULT_OPTIONS,
@@ -39,16 +38,15 @@ const schema = {
39
38
  }
40
39
  }
41
40
  }
42
- };
43
- const rule = {
41
+ }, rule = {
44
42
  meta: {
45
43
  type: "suggestion",
46
44
  docs: {
47
45
  description: "Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.",
48
46
  category: "Schema",
49
- recommended: true,
47
+ recommended: !0,
50
48
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
51
- requiresSchema: true,
49
+ requiresSchema: !0,
52
50
  examples: [
53
51
  {
54
52
  title: "Incorrect",
@@ -125,34 +123,22 @@ const rule = {
125
123
  acceptedIdTypes: ["ID"],
126
124
  exceptions: {},
127
125
  ...context.options[0]
128
- };
129
- const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
130
- const rootTypeNames = [
131
- schema2.getQueryType(),
132
- schema2.getMutationType(),
133
- schema2.getSubscriptionType()
134
- ].filter(truthy).map((type) => type.name);
135
- const selector = `ObjectTypeDefinition[name.value!=/^(${rootTypeNames.join("|")})$/]`;
126
+ }, schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
136
127
  return {
137
- [selector](node) {
138
- var _a, _b, _c;
128
+ [`ObjectTypeDefinition[name.value!=/^(${[
129
+ schema2.getQueryType(),
130
+ schema2.getMutationType(),
131
+ schema2.getSubscriptionType()
132
+ ].filter(truthy).map((type) => type.name).join("|")})$/]`](node) {
139
133
  const typeName = node.name.value;
140
- const shouldIgnoreNode = ((_a = options.exceptions.types) == null ? void 0 : _a.includes(typeName)) || ((_b = options.exceptions.suffixes) == null ? void 0 : _b.some((suffix) => typeName.endsWith(suffix)));
141
- if (shouldIgnoreNode) {
134
+ if (options.exceptions.types?.includes(typeName) || options.exceptions.suffixes?.some((suffix) => typeName.endsWith(suffix)))
142
135
  return;
143
- }
144
- const validIds = (_c = node.fields) == null ? void 0 : _c.filter((field) => {
145
- const fieldNode = field.rawNode();
146
- const isValidIdName = options.acceptedIdNames.includes(fieldNode.name.value);
147
- let isValidIdType = false;
148
- if (fieldNode.type.kind === Kind.NON_NULL_TYPE && fieldNode.type.type.kind === Kind.NAMED_TYPE) {
149
- isValidIdType = options.acceptedIdTypes.includes(fieldNode.type.type.name.value);
150
- }
151
- return isValidIdName && isValidIdType;
152
- });
153
- if ((validIds == null ? void 0 : validIds.length) !== 1) {
154
- const pluralNamesSuffix = options.acceptedIdNames.length > 1 ? "s" : "";
155
- const pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? "s" : "";
136
+ if (node.fields?.filter((field) => {
137
+ const fieldNode = field.rawNode(), isValidIdName = options.acceptedIdNames.includes(fieldNode.name.value);
138
+ let isValidIdType = !1;
139
+ return fieldNode.type.kind === Kind.NON_NULL_TYPE && fieldNode.type.type.kind === Kind.NAMED_TYPE && (isValidIdType = options.acceptedIdTypes.includes(fieldNode.type.type.name.value)), isValidIdName && isValidIdType;
140
+ })?.length !== 1) {
141
+ const pluralNamesSuffix = options.acceptedIdNames.length > 1 ? "s" : "", pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? "s" : "";
156
142
  context.report({
157
143
  node: node.name,
158
144
  message: `${displayNodeName(node)} must have exactly one non-nullable unique identifier.
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
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.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -1,15 +1,16 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { Kind } from "graphql";
3
3
  import { getNodeName } from "../utils.js";
4
4
  const rule = {
5
5
  meta: {
6
6
  type: "suggestion",
7
- hasSuggestions: true,
7
+ hasSuggestions: !0,
8
8
  docs: {
9
- url: "https://the-guild.dev/graphql/eslint/rules/no-case-insensitive-enum-values-duplicates",
9
+ url: "https://the-guild.dev/graphql/eslint/rules/unique-enum-value-names",
10
10
  category: "Schema",
11
- recommended: true,
12
- description: "Disallow case-insensitive enum values duplicates.",
11
+ recommended: !0,
12
+ description: `A GraphQL enum type is only valid if all its values are uniquely named.
13
+ > This rule disallows case-insensitive enum values duplicates too.`,
13
14
  examples: [
14
15
  {
15
16
  title: "Incorrect",
@@ -42,11 +43,9 @@ const rule = {
42
43
  schema: []
43
44
  },
44
45
  create(context) {
45
- const selector = [Kind.ENUM_TYPE_DEFINITION, Kind.ENUM_TYPE_EXTENSION].join(",");
46
46
  return {
47
- [selector](node) {
48
- var _a;
49
- const duplicates = (_a = node.values) == null ? void 0 : _a.filter(
47
+ [[Kind.ENUM_TYPE_DEFINITION, Kind.ENUM_TYPE_EXTENSION].join(",")](node) {
48
+ const duplicates = node.values?.filter(
50
49
  (item, index, array) => array.findIndex((v) => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index
51
50
  );
52
51
  for (const duplicate of duplicates || []) {
@@ -1,11 +1,12 @@
1
1
  import { ExecutableDefinitionNode } from 'graphql';
2
2
  import { GraphQLESTreeNode } from '../estree-converter/types.mjs';
3
- import { c as GraphQLESLintRuleContext, f as GraphQLESLintRule } from '../types-ace77d86.js';
3
+ import { GraphQLESLintRuleContext, GraphQLESLintRule } from '../types.mjs';
4
4
  import 'eslint';
5
5
  import 'estree';
6
+ import 'json-schema-to-ts';
7
+ import '../siblings.mjs';
6
8
  import '@graphql-tools/utils';
7
9
  import 'graphql-config';
8
- import 'json-schema-to-ts';
9
10
 
10
11
  declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string) => void;
11
12
  declare const rule: GraphQLESLintRule;
@@ -1,39 +1,31 @@
1
- import "../chunk-BMTV3EA2.js";
2
- import { relative } from "path";
1
+ import "../chunk-U3TKCM4X.js";
2
+ import { relative } from "node:path";
3
3
  import { Kind } from "graphql";
4
4
  import { CWD, normalizePath, requireSiblingsOperations, VIRTUAL_DOCUMENT_REGEX } from "../utils.js";
5
- const RULE_ID = "unique-fragment-name";
6
- const checkNode = (context, node, ruleId) => {
7
- const documentName = node.name.value;
8
- const siblings = requireSiblingsOperations(ruleId, context);
9
- const siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName);
10
- const filepath = context.getFilename();
11
- const conflictingDocuments = siblingDocuments.filter((f) => {
12
- var _a;
13
- const isSameName = ((_a = f.document.name) == null ? void 0 : _a.value) === documentName;
14
- const isSamePath = normalizePath(f.filePath) === normalizePath(filepath);
5
+ const RULE_ID = "unique-fragment-name", checkNode = (context, node, ruleId) => {
6
+ const documentName = node.name.value, siblings = requireSiblingsOperations(ruleId, context), siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName), filepath = context.filename, conflictingDocuments = siblingDocuments.filter((f) => {
7
+ const isSameName = f.document.name?.value === documentName, isSamePath = normalizePath(f.filePath) === normalizePath(filepath);
15
8
  return isSameName && !isSamePath;
16
9
  });
17
- if (conflictingDocuments.length > 0) {
18
- context.report({
19
- messageId: ruleId,
20
- data: {
21
- documentName,
22
- summary: conflictingDocuments.map((f) => ` ${relative(CWD, f.filePath.replace(VIRTUAL_DOCUMENT_REGEX, ""))}`).join("\n")
23
- },
24
- // @ts-expect-error name will exist
25
- node: node.name
26
- });
27
- }
28
- };
29
- const rule = {
10
+ conflictingDocuments.length > 0 && context.report({
11
+ messageId: ruleId,
12
+ data: {
13
+ documentName,
14
+ summary: conflictingDocuments.map((f) => ` ${relative(CWD, f.filePath.replace(VIRTUAL_DOCUMENT_REGEX, ""))}`).join(`
15
+ `)
16
+ },
17
+ // @ts-expect-error name will exist
18
+ node: node.name
19
+ });
20
+ }, rule = {
30
21
  meta: {
31
22
  type: "suggestion",
32
23
  docs: {
33
24
  category: "Operations",
34
25
  description: "Enforce unique fragment names across your project.",
35
26
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
36
- requiresSiblings: true,
27
+ requiresSiblings: !0,
28
+ recommended: !0,
37
29
  examples: [
38
30
  {
39
31
  title: "Incorrect",
@@ -76,7 +68,8 @@ const rule = {
76
68
  ]
77
69
  },
78
70
  messages: {
79
- [RULE_ID]: 'Fragment named "{{ documentName }}" already defined in:\n{{ summary }}'
71
+ [RULE_ID]: `Fragment named "{{ documentName }}" already defined in:
72
+ {{ summary }}`
80
73
  },
81
74
  schema: []
82
75
  },
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
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.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12