@graphql-eslint/eslint-plugin 4.0.0-alpha.9 → 4.0.1-alpha-20241127205058-a4fec1a6cf7006ea913f13e6afbf7ed2d82503c3

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 (136) hide show
  1. package/cjs/cache.js +1 -2
  2. package/cjs/configs/index.d.cts +427 -10
  3. package/cjs/configs/index.js +1 -2
  4. package/cjs/configs/operations-all.d.cts +8 -8
  5. package/cjs/configs/operations-all.js +30 -33
  6. package/cjs/configs/operations-recommended.d.cts +35 -35
  7. package/cjs/configs/operations-recommended.js +56 -59
  8. package/cjs/configs/schema-all.d.cts +12 -12
  9. package/cjs/configs/schema-all.js +26 -29
  10. package/cjs/configs/schema-recommended.d.cts +23 -23
  11. package/cjs/configs/schema-recommended.js +70 -73
  12. package/cjs/configs/schema-relay.d.cts +5 -5
  13. package/cjs/configs/schema-relay.js +14 -17
  14. package/cjs/documents.js +1 -2
  15. package/cjs/estree-converter/converter.js +1 -2
  16. package/cjs/estree-converter/utils.js +1 -2
  17. package/cjs/graphql-config.d.cts +6 -1
  18. package/cjs/graphql-config.js +9 -3
  19. package/cjs/index.d.cts +436 -16
  20. package/cjs/index.js +2 -3
  21. package/cjs/meta.js +1 -2
  22. package/cjs/parser.js +2 -6
  23. package/cjs/processor.js +5 -2
  24. package/cjs/rules/alphabetize/index.js +1 -2
  25. package/cjs/rules/description-style/index.js +1 -2
  26. package/cjs/rules/graphql-js-validation.js +4 -5
  27. package/cjs/rules/index.d.cts +6 -4
  28. package/cjs/rules/index.js +1 -2
  29. package/cjs/rules/input-name/index.js +1 -2
  30. package/cjs/rules/lone-executable-definition/index.js +1 -2
  31. package/cjs/rules/match-document-filename/index.js +1 -2
  32. package/cjs/rules/naming-convention/index.js +4 -3
  33. package/cjs/rules/no-anonymous-operations/index.js +1 -2
  34. package/cjs/rules/no-deprecated/index.js +20 -8
  35. package/cjs/rules/no-duplicate-fields/index.js +1 -2
  36. package/cjs/rules/no-hashtag-description/index.js +1 -2
  37. package/cjs/rules/no-one-place-fragments/index.js +2 -3
  38. package/cjs/rules/no-root-type/index.js +2 -3
  39. package/cjs/rules/no-scalar-result-type-on-mutation/index.js +2 -3
  40. package/cjs/rules/no-typename-prefix/index.js +1 -2
  41. package/cjs/rules/no-unreachable-types/index.js +4 -6
  42. package/cjs/rules/no-unused-fields/index.d.cts +24 -3
  43. package/cjs/rules/no-unused-fields/index.js +119 -10
  44. package/cjs/rules/relay-arguments/index.js +2 -3
  45. package/cjs/rules/relay-connection-types/index.js +1 -2
  46. package/cjs/rules/relay-edge-types/index.js +2 -3
  47. package/cjs/rules/relay-page-info/index.js +2 -3
  48. package/cjs/rules/require-deprecation-date/index.js +1 -2
  49. package/cjs/rules/require-deprecation-reason/index.js +1 -2
  50. package/cjs/rules/require-description/index.js +4 -8
  51. package/cjs/rules/require-field-of-type-query-in-mutation-result/index.js +2 -3
  52. package/cjs/rules/require-import-fragment/index.js +2 -3
  53. package/cjs/rules/require-nullable-fields-with-oneof/index.js +1 -2
  54. package/cjs/rules/require-nullable-result-in-root/index.js +2 -3
  55. package/cjs/rules/require-selections/index.js +14 -8
  56. package/cjs/rules/require-type-pattern-with-oneof/index.js +1 -2
  57. package/cjs/rules/selection-set-depth/index.js +4 -5
  58. package/cjs/rules/strict-id-in-types/index.js +2 -3
  59. package/cjs/rules/unique-enum-value-names/index.js +1 -2
  60. package/cjs/rules/unique-fragment-name/index.js +2 -3
  61. package/cjs/rules/unique-operation-name/index.js +1 -2
  62. package/cjs/schema.js +1 -2
  63. package/cjs/siblings.js +1 -2
  64. package/cjs/types.d.cts +1 -0
  65. package/cjs/utils.d.cts +4 -4
  66. package/cjs/utils.js +7 -8
  67. package/esm/cache.js +0 -1
  68. package/esm/configs/index.d.ts +427 -10
  69. package/esm/configs/index.js +0 -1
  70. package/esm/configs/operations-all.d.ts +7 -7
  71. package/esm/configs/operations-all.js +28 -33
  72. package/esm/configs/operations-recommended.d.ts +34 -34
  73. package/esm/configs/operations-recommended.js +54 -59
  74. package/esm/configs/schema-all.d.ts +11 -11
  75. package/esm/configs/schema-all.js +24 -29
  76. package/esm/configs/schema-recommended.d.ts +22 -22
  77. package/esm/configs/schema-recommended.js +68 -73
  78. package/esm/configs/schema-relay.d.ts +4 -4
  79. package/esm/configs/schema-relay.js +12 -17
  80. package/esm/documents.js +0 -1
  81. package/esm/estree-converter/converter.js +0 -1
  82. package/esm/estree-converter/utils.js +0 -1
  83. package/esm/graphql-config.d.ts +6 -1
  84. package/esm/graphql-config.js +8 -2
  85. package/esm/index.d.ts +436 -16
  86. package/esm/index.js +3 -4
  87. package/esm/meta.js +1 -2
  88. package/esm/parser.js +3 -7
  89. package/esm/processor.js +4 -1
  90. package/esm/rules/alphabetize/index.js +0 -1
  91. package/esm/rules/description-style/index.js +0 -1
  92. package/esm/rules/graphql-js-validation.js +5 -6
  93. package/esm/rules/index.d.ts +6 -4
  94. package/esm/rules/index.js +0 -1
  95. package/esm/rules/input-name/index.js +0 -1
  96. package/esm/rules/lone-executable-definition/index.js +0 -1
  97. package/esm/rules/match-document-filename/index.js +0 -1
  98. package/esm/rules/naming-convention/index.js +3 -2
  99. package/esm/rules/no-anonymous-operations/index.js +0 -1
  100. package/esm/rules/no-deprecated/index.js +20 -8
  101. package/esm/rules/no-duplicate-fields/index.js +0 -1
  102. package/esm/rules/no-hashtag-description/index.js +0 -1
  103. package/esm/rules/no-one-place-fragments/index.js +2 -3
  104. package/esm/rules/no-root-type/index.js +2 -3
  105. package/esm/rules/no-scalar-result-type-on-mutation/index.js +2 -3
  106. package/esm/rules/no-typename-prefix/index.js +0 -1
  107. package/esm/rules/no-unreachable-types/index.js +5 -7
  108. package/esm/rules/no-unused-fields/index.d.ts +24 -3
  109. package/esm/rules/no-unused-fields/index.js +119 -10
  110. package/esm/rules/relay-arguments/index.js +2 -3
  111. package/esm/rules/relay-connection-types/index.js +0 -1
  112. package/esm/rules/relay-edge-types/index.js +2 -3
  113. package/esm/rules/relay-page-info/index.js +2 -3
  114. package/esm/rules/require-deprecation-date/index.js +0 -1
  115. package/esm/rules/require-deprecation-reason/index.js +0 -1
  116. package/esm/rules/require-description/index.js +4 -8
  117. package/esm/rules/require-field-of-type-query-in-mutation-result/index.js +2 -3
  118. package/esm/rules/require-import-fragment/index.js +2 -3
  119. package/esm/rules/require-nullable-fields-with-oneof/index.js +0 -1
  120. package/esm/rules/require-nullable-result-in-root/index.js +2 -3
  121. package/esm/rules/require-selections/index.js +15 -9
  122. package/esm/rules/require-type-pattern-with-oneof/index.js +0 -1
  123. package/esm/rules/selection-set-depth/index.js +4 -5
  124. package/esm/rules/strict-id-in-types/index.js +2 -3
  125. package/esm/rules/unique-enum-value-names/index.js +0 -1
  126. package/esm/rules/unique-fragment-name/index.js +2 -3
  127. package/esm/rules/unique-operation-name/index.js +0 -1
  128. package/esm/schema.js +0 -1
  129. package/esm/siblings.js +0 -1
  130. package/esm/types.d.ts +1 -0
  131. package/esm/utils.d.ts +4 -4
  132. package/esm/utils.js +7 -8
  133. package/index.browser.js +508 -423
  134. package/package.json +2 -2
  135. package/cjs/chunk-UIAXBAMD.js +0 -8
  136. package/esm/chunk-UIAXBAMD.js +0 -8
@@ -1,4 +1,3 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import {
3
2
  GraphQLInterfaceType,
4
3
  GraphQLObjectType,
@@ -13,8 +12,8 @@ import { getBaseType } from "../../estree-converter/index.js";
13
12
  import {
14
13
  ARRAY_DEFAULT_OPTIONS,
15
14
  englishJoinWords,
16
- requireGraphQLSchemaFromContext,
17
- requireSiblingsOperations
15
+ requireGraphQLOperations,
16
+ requireGraphQLSchema
18
17
  } from "../../utils.js";
19
18
  const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
20
19
  definitions: {
@@ -95,7 +94,8 @@ const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
95
94
  )
96
95
  }
97
96
  ],
98
- recommended: !0
97
+ recommended: !0,
98
+ whenNotToUseIt: "Relay Compiler automatically adds an `id` field to any type that has an `id` field, even if it hasn't been explicitly requested. Requesting a field that is not used directly in the code can conflict with another Relay rule: `relay/unused-fields`."
99
99
  },
100
100
  messages: {
101
101
  [RULE_ID]: `Field{{ pluralSuffix }} {{ fieldName }} must be selected when it's available on a type.
@@ -104,7 +104,7 @@ Include it in your selection set{{ addition }}.`
104
104
  schema
105
105
  },
106
106
  create(context) {
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);
107
+ const schema2 = requireGraphQLSchema(RULE_ID, context), siblings = requireGraphQLOperations(RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = asArray(fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo(schema2);
108
108
  function checkFragments(node) {
109
109
  for (const selection of node.selections) {
110
110
  if (selection.kind !== Kind.FRAGMENT_SPREAD)
@@ -131,13 +131,19 @@ Include it in your selection set{{ addition }}.`
131
131
  const rawType = getBaseType(type);
132
132
  if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType)
133
133
  checkFields(rawType);
134
- else if (rawType instanceof GraphQLUnionType) {
135
- for (const selection of node.selections)
134
+ else if (rawType instanceof GraphQLUnionType)
135
+ for (const selection of node.selections) {
136
+ const types = rawType.getTypes();
136
137
  if (selection.kind === Kind.INLINE_FRAGMENT) {
137
- const t = rawType.getTypes().find((t2) => t2.name === selection.typeCondition.name.value);
138
+ const t = types.find((t2) => t2.name === selection.typeCondition.name.value);
138
139
  t && checkFields(t);
140
+ } else if (selection.kind === Kind.FRAGMENT_SPREAD) {
141
+ const [foundSpread] = siblings.getFragment(selection.name.value);
142
+ if (!foundSpread) return;
143
+ const fragmentSpread = foundSpread.document, t = fragmentSpread.typeCondition.name.value === rawType.name ? rawType : types.find((t2) => t2.name === fragmentSpread.typeCondition.name.value);
144
+ checkedFragmentSpreads.add(fragmentSpread.name.value), checkSelections(fragmentSpread.selectionSet, t, loc, parent, checkedFragmentSpreads);
139
145
  }
140
- }
146
+ }
141
147
  function checkFields(rawType2) {
142
148
  const fields = rawType2.getFields();
143
149
  if (!idNames.some((name) => fields[name]))
@@ -1,4 +1,3 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import { displayNodeName } from "../../utils.js";
3
2
  const RULE_ID = "require-type-pattern-with-oneof", rule = {
4
3
  meta: {
@@ -1,7 +1,6 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import { Kind } from "graphql";
3
2
  import depthLimit from "graphql-depth-limit";
4
- import { ARRAY_DEFAULT_OPTIONS, logger, requireSiblingsOperations } from "../../utils.js";
3
+ import { ARRAY_DEFAULT_OPTIONS, logger, requireGraphQLOperations } from "../../utils.js";
5
4
  const RULE_ID = "selection-set-depth", schema = {
6
5
  type: "array",
7
6
  minItems: 1,
@@ -75,10 +74,10 @@ const RULE_ID = "selection-set-depth", schema = {
75
74
  create(context) {
76
75
  let siblings = null;
77
76
  try {
78
- siblings = requireSiblingsOperations(RULE_ID, context);
77
+ siblings = requireGraphQLOperations(RULE_ID, context);
79
78
  } catch {
80
79
  logger.warn(
81
- `Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`
80
+ `Rule "${RULE_ID}" works best with siblings operations loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`
82
81
  );
83
82
  }
84
83
  const { maxDepth, ignore = [] } = context.options[0], checkFn = depthLimit(maxDepth, { ignore });
@@ -120,7 +119,7 @@ const RULE_ID = "selection-set-depth", schema = {
120
119
  });
121
120
  } catch (e) {
122
121
  logger.warn(
123
- `Rule "${RULE_ID}" check failed due to a missing siblings operations. For more info: https://bit.ly/graphql-eslint-operations`,
122
+ `Rule "${RULE_ID}" check failed due to a missing siblings operations. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`,
124
123
  e
125
124
  );
126
125
  }
@@ -1,10 +1,9 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import { Kind } from "graphql";
3
2
  import {
4
3
  ARRAY_DEFAULT_OPTIONS,
5
4
  displayNodeName,
6
5
  englishJoinWords,
7
- requireGraphQLSchemaFromContext,
6
+ requireGraphQLSchema,
8
7
  truthy
9
8
  } from "../../utils.js";
10
9
  const RULE_ID = "strict-id-in-types", schema = {
@@ -123,7 +122,7 @@ const RULE_ID = "strict-id-in-types", schema = {
123
122
  acceptedIdTypes: ["ID"],
124
123
  exceptions: {},
125
124
  ...context.options[0]
126
- }, schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
125
+ }, schema2 = requireGraphQLSchema(RULE_ID, context);
127
126
  return {
128
127
  [`ObjectTypeDefinition[name.value!=/^(${[
129
128
  schema2.getQueryType(),
@@ -1,4 +1,3 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import { Kind } from "graphql";
3
2
  import { getNodeName } from "../../utils.js";
4
3
  const rule = {
@@ -1,9 +1,8 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import { relative } from "node:path";
3
2
  import { Kind } from "graphql";
4
- import { CWD, requireSiblingsOperations, slash, VIRTUAL_DOCUMENT_REGEX } from "../../utils.js";
3
+ import { CWD, requireGraphQLOperations, slash, VIRTUAL_DOCUMENT_REGEX } from "../../utils.js";
5
4
  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) => {
5
+ const documentName = node.name.value, siblings = requireGraphQLOperations(ruleId, context), siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName), filepath = context.filename, conflictingDocuments = siblingDocuments.filter((f) => {
7
6
  const isSameName = f.document.name?.value === documentName, isSamePath = slash(f.filePath) === slash(filepath);
8
7
  return isSameName && !isSamePath;
9
8
  });
@@ -1,4 +1,3 @@
1
- import "../../chunk-UIAXBAMD.js";
2
1
  import { checkNode } from "../unique-fragment-name/index.js";
3
2
  const RULE_ID = "unique-operation-name", rule = {
4
3
  meta: {
package/esm/schema.js CHANGED
@@ -1,4 +1,3 @@
1
- import "./chunk-UIAXBAMD.js";
2
1
  import debugFactory from "debug";
3
2
  import fg from "fast-glob";
4
3
  import { GraphQLSchema } from "graphql";
package/esm/siblings.js CHANGED
@@ -1,4 +1,3 @@
1
- import "./chunk-UIAXBAMD.js";
2
1
  import {
3
2
  Kind,
4
3
  visit
package/esm/types.d.ts CHANGED
@@ -52,6 +52,7 @@ type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & {
52
52
  };
53
53
  graphQLJSRuleName?: string;
54
54
  isDisabledForAllConfig?: true;
55
+ whenNotToUseIt?: string;
55
56
  };
56
57
  type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
57
58
  [K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
package/esm/utils.d.ts CHANGED
@@ -8,8 +8,8 @@ import '@graphql-tools/utils';
8
8
  import 'graphql-config';
9
9
  import 'json-schema-to-ts';
10
10
 
11
- declare function requireSiblingsOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
12
- declare function requireGraphQLSchemaFromContext(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
11
+ declare function requireGraphQLOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
12
+ declare function requireGraphQLSchema(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
13
13
  declare const logger: {
14
14
  error: (...args: unknown[]) => void;
15
15
  warn: (...args: unknown[]) => void;
@@ -39,7 +39,7 @@ declare const ARRAY_DEFAULT_OPTIONS: {
39
39
  declare const englishJoinWords: (words: string[]) => string;
40
40
  type Truthy<T> = T extends '' | 0 | false | null | undefined ? never : T;
41
41
  declare function truthy<T>(value: T): value is Truthy<T>;
42
- declare function displayNodeName(node: GraphQLESTreeNode<ASTNode>): string;
42
+ declare function displayNodeName(node: GraphQLESTreeNode<ASTNode, boolean>): string;
43
43
  declare function getNodeName(node: GraphQLESTreeNode<ASTNode>): string;
44
44
 
45
- export { ARRAY_DEFAULT_OPTIONS, CWD, type CaseStyle, REPORT_ON_FIRST_CHARACTER, TYPES_KINDS, VIRTUAL_DOCUMENT_REGEX, camelCase, convertCase, displayNodeName, englishJoinWords, getLocation, getNodeName, getTypeName, logger, pascalCase, requireGraphQLSchemaFromContext, requireSiblingsOperations, slash, truthy };
45
+ export { ARRAY_DEFAULT_OPTIONS, CWD, type CaseStyle, REPORT_ON_FIRST_CHARACTER, TYPES_KINDS, VIRTUAL_DOCUMENT_REGEX, camelCase, convertCase, displayNodeName, englishJoinWords, getLocation, getNodeName, getTypeName, logger, pascalCase, requireGraphQLOperations, requireGraphQLSchema, slash, truthy };
package/esm/utils.js CHANGED
@@ -1,19 +1,18 @@
1
- import "./chunk-UIAXBAMD.js";
2
1
  import { Kind } from "graphql";
3
2
  import lowerCase from "lodash.lowercase";
4
- function requireSiblingsOperations(ruleId, context) {
3
+ function requireGraphQLOperations(ruleId, context) {
5
4
  const { siblingOperations } = context.sourceCode.parserServices;
6
5
  if (!siblingOperations.available)
7
6
  throw new Error(
8
- `Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/config/docs/user/documents for more info`
7
+ `Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`
9
8
  );
10
9
  return siblingOperations;
11
10
  }
12
- function requireGraphQLSchemaFromContext(ruleId, context) {
11
+ function requireGraphQLSchema(ruleId, context) {
13
12
  const { schema } = context.sourceCode.parserServices;
14
13
  if (!schema)
15
14
  throw new Error(
16
- `Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/config/docs/user/schema for more info`
15
+ `Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-schema for more info`
17
16
  );
18
17
  return schema;
19
18
  }
@@ -123,7 +122,7 @@ const DisplayNodeNameMap = {
123
122
  [Kind.VARIABLE]: "variable"
124
123
  };
125
124
  function displayNodeName(node) {
126
- return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value}"`;
125
+ return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value || node.value}"`;
127
126
  }
128
127
  function getNodeName(node) {
129
128
  switch (node.kind) {
@@ -160,8 +159,8 @@ export {
160
159
  getTypeName,
161
160
  logger,
162
161
  pascalCase,
163
- requireGraphQLSchemaFromContext,
164
- requireSiblingsOperations,
162
+ requireGraphQLOperations,
163
+ requireGraphQLSchema,
165
164
  slash,
166
165
  truthy
167
166
  };