@graphql-eslint/eslint-plugin 3.14.4-alpha-20230111221804-f30b422 → 3.14.4-alpha-20230111225020-02d9c28

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 (156) hide show
  1. package/README.md +5 -288
  2. package/cjs/documents.js +2 -105
  3. package/cjs/graphql-config.js +1 -1
  4. package/cjs/parser.js +9 -3
  5. package/cjs/rules/alphabetize.js +1 -1
  6. package/cjs/rules/description-style.js +1 -1
  7. package/cjs/rules/graphql-js-validation.js +1 -1
  8. package/cjs/rules/input-name.js +4 -4
  9. package/cjs/rules/lone-executable-definition.js +1 -1
  10. package/cjs/rules/match-document-filename.js +2 -3
  11. package/cjs/rules/naming-convention.js +1 -1
  12. package/cjs/rules/no-anonymous-operations.js +1 -1
  13. package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +1 -1
  14. package/cjs/rules/no-deprecated.js +1 -1
  15. package/cjs/rules/no-duplicate-fields.js +1 -1
  16. package/cjs/rules/no-hashtag-description.js +1 -1
  17. package/cjs/rules/no-one-place-fragments.js +1 -1
  18. package/cjs/rules/no-root-type.js +1 -1
  19. package/cjs/rules/no-scalar-result-type-on-mutation.js +1 -1
  20. package/cjs/rules/no-typename-prefix.js +1 -1
  21. package/cjs/rules/no-unreachable-types.js +1 -1
  22. package/cjs/rules/no-unused-fields.js +1 -1
  23. package/cjs/rules/relay-arguments.js +4 -4
  24. package/cjs/rules/relay-connection-types.js +1 -1
  25. package/cjs/rules/relay-edge-types.js +1 -1
  26. package/cjs/rules/relay-page-info.js +1 -1
  27. package/cjs/rules/require-deprecation-date.js +1 -1
  28. package/cjs/rules/require-deprecation-reason.js +1 -1
  29. package/cjs/rules/require-description.js +1 -1
  30. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +1 -1
  31. package/cjs/rules/require-id-when-available.js +1 -1
  32. package/cjs/rules/require-nullable-fields-with-oneof.js +1 -1
  33. package/cjs/rules/require-type-pattern-with-oneof.js +1 -1
  34. package/cjs/rules/selection-set-depth.js +1 -1
  35. package/cjs/rules/strict-id-in-types.js +1 -1
  36. package/cjs/rules/unique-fragment-name.js +1 -1
  37. package/cjs/rules/unique-operation-name.js +1 -1
  38. package/cjs/siblings.js +113 -0
  39. package/cjs/utils.js +3 -2
  40. package/docs/README.md +1 -85
  41. package/docs/custom-rules.md +1 -184
  42. package/docs/deprecated-rules.md +1 -24
  43. package/docs/parser-options.md +1 -107
  44. package/docs/parser.md +1 -67
  45. package/esm/documents.js +2 -105
  46. package/esm/graphql-config.js +1 -1
  47. package/esm/parser.js +10 -4
  48. package/esm/rules/alphabetize.js +1 -1
  49. package/esm/rules/description-style.js +1 -1
  50. package/esm/rules/graphql-js-validation.js +1 -1
  51. package/esm/rules/input-name.js +4 -4
  52. package/esm/rules/lone-executable-definition.js +1 -1
  53. package/esm/rules/match-document-filename.js +3 -4
  54. package/esm/rules/naming-convention.js +1 -1
  55. package/esm/rules/no-anonymous-operations.js +1 -1
  56. package/esm/rules/no-case-insensitive-enum-values-duplicates.js +1 -1
  57. package/esm/rules/no-deprecated.js +1 -1
  58. package/esm/rules/no-duplicate-fields.js +1 -1
  59. package/esm/rules/no-hashtag-description.js +1 -1
  60. package/esm/rules/no-one-place-fragments.js +1 -1
  61. package/esm/rules/no-root-type.js +1 -1
  62. package/esm/rules/no-scalar-result-type-on-mutation.js +1 -1
  63. package/esm/rules/no-typename-prefix.js +1 -1
  64. package/esm/rules/no-unreachable-types.js +1 -1
  65. package/esm/rules/no-unused-fields.js +1 -1
  66. package/esm/rules/relay-arguments.js +4 -4
  67. package/esm/rules/relay-connection-types.js +1 -1
  68. package/esm/rules/relay-edge-types.js +1 -1
  69. package/esm/rules/relay-page-info.js +1 -1
  70. package/esm/rules/require-deprecation-date.js +1 -1
  71. package/esm/rules/require-deprecation-reason.js +1 -1
  72. package/esm/rules/require-description.js +1 -1
  73. package/esm/rules/require-field-of-type-query-in-mutation-result.js +1 -1
  74. package/esm/rules/require-id-when-available.js +1 -1
  75. package/esm/rules/require-nullable-fields-with-oneof.js +1 -1
  76. package/esm/rules/require-type-pattern-with-oneof.js +1 -1
  77. package/esm/rules/selection-set-depth.js +1 -1
  78. package/esm/rules/strict-id-in-types.js +1 -1
  79. package/esm/rules/unique-fragment-name.js +1 -1
  80. package/esm/rules/unique-operation-name.js +1 -1
  81. package/esm/siblings.js +109 -0
  82. package/esm/utils.js +2 -1
  83. package/package.json +1 -1
  84. package/typings/documents.d.cts +2 -20
  85. package/typings/documents.d.ts +2 -20
  86. package/typings/rules/input-name.d.cts +1 -1
  87. package/typings/rules/input-name.d.ts +1 -1
  88. package/typings/siblings.d.cts +22 -0
  89. package/typings/siblings.d.ts +22 -0
  90. package/typings/types.d.cts +3 -2
  91. package/typings/types.d.ts +3 -2
  92. package/typings/utils.d.cts +2 -1
  93. package/typings/utils.d.ts +2 -1
  94. package/docs/rules/alphabetize.md +0 -194
  95. package/docs/rules/description-style.md +0 -57
  96. package/docs/rules/executable-definitions.md +0 -20
  97. package/docs/rules/fields-on-correct-type.md +0 -23
  98. package/docs/rules/fragments-on-composite-type.md +0 -20
  99. package/docs/rules/input-name.md +0 -80
  100. package/docs/rules/known-argument-names.md +0 -23
  101. package/docs/rules/known-directives.md +0 -48
  102. package/docs/rules/known-fragment-names.md +0 -72
  103. package/docs/rules/known-type-names.md +0 -24
  104. package/docs/rules/lone-anonymous-operation.md +0 -20
  105. package/docs/rules/lone-executable-definition.md +0 -59
  106. package/docs/rules/lone-schema-definition.md +0 -19
  107. package/docs/rules/match-document-filename.md +0 -181
  108. package/docs/rules/naming-convention.md +0 -320
  109. package/docs/rules/no-anonymous-operations.md +0 -43
  110. package/docs/rules/no-case-insensitive-enum-values-duplicates.md +0 -46
  111. package/docs/rules/no-deprecated.md +0 -88
  112. package/docs/rules/no-duplicate-fields.md +0 -69
  113. package/docs/rules/no-fragment-cycles.md +0 -19
  114. package/docs/rules/no-hashtag-description.md +0 -62
  115. package/docs/rules/no-one-place-fragments.md +0 -51
  116. package/docs/rules/no-root-type.md +0 -55
  117. package/docs/rules/no-scalar-result-type-on-mutation.md +0 -39
  118. package/docs/rules/no-typename-prefix.md +0 -42
  119. package/docs/rules/no-undefined-variables.md +0 -20
  120. package/docs/rules/no-unreachable-types.md +0 -52
  121. package/docs/rules/no-unused-fields.md +0 -64
  122. package/docs/rules/no-unused-fragments.md +0 -20
  123. package/docs/rules/no-unused-variables.md +0 -20
  124. package/docs/rules/one-field-subscriptions.md +0 -19
  125. package/docs/rules/overlapping-fields-can-be-merged.md +0 -20
  126. package/docs/rules/possible-fragment-spread.md +0 -21
  127. package/docs/rules/possible-type-extension.md +0 -19
  128. package/docs/rules/provided-required-arguments.md +0 -21
  129. package/docs/rules/relay-arguments.md +0 -59
  130. package/docs/rules/relay-connection-types.md +0 -43
  131. package/docs/rules/relay-edge-types.md +0 -60
  132. package/docs/rules/relay-page-info.md +0 -34
  133. package/docs/rules/require-deprecation-date.md +0 -59
  134. package/docs/rules/require-deprecation-reason.md +0 -49
  135. package/docs/rules/require-description.md +0 -147
  136. package/docs/rules/require-field-of-type-query-in-mutation-result.md +0 -50
  137. package/docs/rules/require-id-when-available.md +0 -91
  138. package/docs/rules/require-nullable-fields-with-oneof.md +0 -38
  139. package/docs/rules/require-type-pattern-with-oneof.md +0 -39
  140. package/docs/rules/scalar-leafs.md +0 -23
  141. package/docs/rules/selection-set-depth.md +0 -86
  142. package/docs/rules/strict-id-in-types.md +0 -129
  143. package/docs/rules/unique-argument-names.md +0 -19
  144. package/docs/rules/unique-directive-names-per-location.md +0 -21
  145. package/docs/rules/unique-directive-names.md +0 -19
  146. package/docs/rules/unique-enum-value-names.md +0 -16
  147. package/docs/rules/unique-field-definition-names.md +0 -19
  148. package/docs/rules/unique-fragment-name.md +0 -52
  149. package/docs/rules/unique-input-field-names.md +0 -19
  150. package/docs/rules/unique-operation-name.md +0 -56
  151. package/docs/rules/unique-operation-types.md +0 -19
  152. package/docs/rules/unique-type-names.md +0 -19
  153. package/docs/rules/unique-variable-names.md +0 -19
  154. package/docs/rules/value-literals-of-correct-type.md +0 -22
  155. package/docs/rules/variables-are-input-types.md +0 -20
  156. package/docs/rules/variables-in-allowed-position.md +0 -19
@@ -9,7 +9,7 @@ export const rule = {
9
9
  category: 'Operations',
10
10
  description: 'Require name for your GraphQL operations. This is useful since most GraphQL client libraries are using the operation name for caching purposes.',
11
11
  recommended: true,
12
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
12
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
13
13
  examples: [
14
14
  {
15
15
  title: 'Incorrect',
@@ -4,7 +4,7 @@ export const rule = {
4
4
  type: 'suggestion',
5
5
  hasSuggestions: true,
6
6
  docs: {
7
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/no-case-insensitive-enum-values-duplicates.md',
7
+ url: 'https://the-guild.dev/graphql/eslint/rules/no-case-insensitive-enum-values-duplicates',
8
8
  category: 'Schema',
9
9
  recommended: true,
10
10
  description: 'Disallow case-insensitive enum values duplicates.',
@@ -8,7 +8,7 @@ export const rule = {
8
8
  docs: {
9
9
  category: 'Operations',
10
10
  description: 'Enforce that deprecated fields or enum values are not in use by operations.',
11
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
11
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
12
12
  requiresSchema: true,
13
13
  examples: [
14
14
  {
@@ -7,7 +7,7 @@ export const rule = {
7
7
  docs: {
8
8
  description: 'Checks for duplicate fields in selection set, variables in operation definition, or in arguments set of a field.',
9
9
  category: 'Operations',
10
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
10
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
11
11
  recommended: true,
12
12
  examples: [
13
13
  {
@@ -11,7 +11,7 @@ export const rule = {
11
11
  docs: {
12
12
  description: 'Requires to use `"""` or `"` for adding a GraphQL description instead of `#`.\nAllows to use hashtag for comments, as long as it\'s not attached to an AST definition.',
13
13
  category: 'Schema',
14
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/no-hashtag-description.md',
14
+ url: 'https://the-guild.dev/graphql/eslint/rules/no-hashtag-description',
15
15
  examples: [
16
16
  {
17
17
  title: 'Incorrect',
@@ -8,7 +8,7 @@ export const rule = {
8
8
  docs: {
9
9
  category: 'Operations',
10
10
  description: 'Disallow fragments that are used only in one place.',
11
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
11
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
12
12
  examples: [
13
13
  {
14
14
  title: 'Incorrect',
@@ -24,7 +24,7 @@ export const rule = {
24
24
  docs: {
25
25
  category: 'Schema',
26
26
  description: 'Disallow using root types `mutation` and/or `subscription`.',
27
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/no-root-type.md',
27
+ url: 'https://the-guild.dev/graphql/eslint/rules/no-root-type',
28
28
  requiresSchema: true,
29
29
  isDisabledForAllConfig: true,
30
30
  examples: [
@@ -8,7 +8,7 @@ export const rule = {
8
8
  docs: {
9
9
  category: 'Schema',
10
10
  description: 'Avoid scalar result type on mutation type to make sure to return a valid state.',
11
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
11
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
12
12
  requiresSchema: true,
13
13
  examples: [
14
14
  {
@@ -7,7 +7,7 @@ export const rule = {
7
7
  category: 'Schema',
8
8
  description: 'Enforces users to avoid using the type name in a field name while defining your schema.',
9
9
  recommended: true,
10
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/no-typename-prefix.md',
10
+ url: 'https://the-guild.dev/graphql/eslint/rules/no-typename-prefix',
11
11
  examples: [
12
12
  {
13
13
  title: 'Incorrect',
@@ -89,7 +89,7 @@ export const rule = {
89
89
  docs: {
90
90
  description: 'Requires all types to be reachable at some level by root level fields.',
91
91
  category: 'Schema',
92
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
92
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
93
93
  requiresSchema: true,
94
94
  examples: [
95
95
  {
@@ -39,7 +39,7 @@ export const rule = {
39
39
  docs: {
40
40
  description: 'Requires all fields to be used at some level by siblings operations.',
41
41
  category: 'Schema',
42
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
42
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
43
43
  requiresSiblings: true,
44
44
  requiresSchema: true,
45
45
  isDisabledForAllConfig: true,
@@ -38,7 +38,7 @@ export const rule = {
38
38
  '- `last` takes a non-negative integer',
39
39
  '- `before` takes the Cursor type',
40
40
  ].join('\n'),
41
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
41
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
42
42
  examples: [
43
43
  {
44
44
  title: 'Incorrect',
@@ -75,8 +75,8 @@ export const rule = {
75
75
  fieldNode = fieldNode.parent;
76
76
  }
77
77
  const args = Object.fromEntries(((_a = fieldNode.arguments) === null || _a === void 0 ? void 0 : _a.map(argument => [argument.name.value, argument])) || []);
78
- const hasForwardPagination = Boolean(args.first && args.after);
79
- const hasBackwardPagination = Boolean(args.last && args.before);
78
+ const hasForwardPagination = !!(args.first && args.after);
79
+ const hasBackwardPagination = !!(args.last && args.before);
80
80
  if (!hasForwardPagination && !hasBackwardPagination) {
81
81
  context.report({
82
82
  node: fieldNode.name,
@@ -86,7 +86,7 @@ export const rule = {
86
86
  }
87
87
  function checkField(typeName, argumentName) {
88
88
  const argument = args[argumentName];
89
- const hasArgument = Boolean(argument);
89
+ const hasArgument = !!argument;
90
90
  let type = argument;
91
91
  if (hasArgument && type.gqlType.kind === Kind.NON_NULL_TYPE) {
92
92
  type = type.gqlType;
@@ -32,7 +32,7 @@ export const rule = {
32
32
  '- Connection type must contain a field `edges` that return a list type that wraps an edge type',
33
33
  '- Connection type must contain a field `pageInfo` that return a non-null `PageInfo` Object type',
34
34
  ].join('\n'),
35
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/relay-connection-types.md',
35
+ url: 'https://the-guild.dev/graphql/eslint/rules/relay-connection-types',
36
36
  isDisabledForAllConfig: true,
37
37
  examples: [
38
38
  {
@@ -79,7 +79,7 @@ export const rule = {
79
79
  "- Edge type's field `node` must implement `Node` interface _(optional)_",
80
80
  '- A list type should only wrap an edge type _(optional)_',
81
81
  ].join('\n'),
82
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
82
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
83
83
  isDisabledForAllConfig: true,
84
84
  requiresSchema: true,
85
85
  examples: [
@@ -18,7 +18,7 @@ export const rule = {
18
18
  '- `PageInfo` must contain fields `hasPreviousPage` and `hasNextPage`, that return non-null Boolean',
19
19
  '- `PageInfo` must contain fields `startCursor` and `endCursor`, that return either String or Scalar, which can be null if there are no results',
20
20
  ].join('\n'),
21
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
21
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
22
22
  examples: [
23
23
  {
24
24
  title: 'Correct',
@@ -25,7 +25,7 @@ export const rule = {
25
25
  docs: {
26
26
  category: 'Schema',
27
27
  description: 'Require deletion date on `@deprecated` directive. Suggest removing deprecated things after deprecated date.',
28
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/require-deprecation-date.md',
28
+ url: 'https://the-guild.dev/graphql/eslint/rules/require-deprecation-date',
29
29
  examples: [
30
30
  {
31
31
  title: 'Incorrect',
@@ -4,7 +4,7 @@ export const rule = {
4
4
  docs: {
5
5
  description: 'Require all deprecation directives to specify a reason.',
6
6
  category: 'Schema',
7
- url: 'https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/require-deprecation-reason.md',
7
+ url: 'https://the-guild.dev/graphql/eslint/rules/require-deprecation-reason',
8
8
  recommended: true,
9
9
  examples: [
10
10
  {
@@ -71,7 +71,7 @@ export const rule = {
71
71
  docs: {
72
72
  category: 'Schema',
73
73
  description: 'Enforce descriptions in type definitions and operations.',
74
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
74
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
75
75
  examples: [
76
76
  {
77
77
  title: 'Incorrect',
@@ -7,7 +7,7 @@ export const rule = {
7
7
  docs: {
8
8
  category: 'Schema',
9
9
  description: 'Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.\n> Currently, no errors are reported for result type `union`, `interface` and `scalar`.',
10
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
10
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
11
11
  requiresSchema: true,
12
12
  examples: [
13
13
  {
@@ -31,7 +31,7 @@ export const rule = {
31
31
  docs: {
32
32
  category: 'Operations',
33
33
  description: 'Enforce selecting specific fields when they are available on the GraphQL type.',
34
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
34
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
35
35
  requiresSchema: true,
36
36
  requiresSiblings: true,
37
37
  examples: [
@@ -6,7 +6,7 @@ export const rule = {
6
6
  docs: {
7
7
  category: 'Schema',
8
8
  description: 'Require `input` or `type` fields to be non-nullable with `@oneOf` directive.',
9
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
9
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
10
10
  examples: [
11
11
  {
12
12
  title: 'Incorrect',
@@ -5,7 +5,7 @@ export const rule = {
5
5
  docs: {
6
6
  category: 'Schema',
7
7
  description: 'Enforce types with `@oneOf` directive have `error` and `ok` fields.',
8
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
8
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
9
9
  examples: [
10
10
  {
11
11
  title: 'Correct',
@@ -25,7 +25,7 @@ export const rule = {
25
25
  docs: {
26
26
  category: 'Operations',
27
27
  description: 'Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).',
28
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
28
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
29
29
  requiresSiblings: true,
30
30
  examples: [
31
31
  {
@@ -40,7 +40,7 @@ export const rule = {
40
40
  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.',
41
41
  category: 'Schema',
42
42
  recommended: true,
43
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
43
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
44
44
  requiresSchema: true,
45
45
  examples: [
46
46
  {
@@ -35,7 +35,7 @@ export const rule = {
35
35
  docs: {
36
36
  category: 'Operations',
37
37
  description: 'Enforce unique fragment names across your project.',
38
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
38
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
39
39
  requiresSiblings: true,
40
40
  examples: [
41
41
  {
@@ -6,7 +6,7 @@ export const rule = {
6
6
  docs: {
7
7
  category: 'Operations',
8
8
  description: 'Enforce unique operation names across your project.',
9
- url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${RULE_ID}.md`,
9
+ url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
10
10
  requiresSiblings: true,
11
11
  examples: [
12
12
  {
@@ -0,0 +1,109 @@
1
+ import { parseGraphQLSDL } from '@graphql-tools/utils';
2
+ import { Kind, visit, } from 'graphql';
3
+ import { getDocuments } from './documents.js';
4
+ import { logger } from './utils.js';
5
+ const siblingOperationsCache = new Map();
6
+ export function getSiblings(project, documents) {
7
+ const siblings = project
8
+ ? getDocuments(project)
9
+ : typeof documents === 'string'
10
+ ? [parseGraphQLSDL('operation.graphql', documents, { noLocation: true })]
11
+ : [];
12
+ if (siblings.length === 0) {
13
+ let printed = false;
14
+ const noopWarn = () => {
15
+ if (!printed) {
16
+ logger.warn('getSiblingOperations was called without any operations. Make sure to set "parserOptions.operations" to make this feature available!');
17
+ printed = true;
18
+ }
19
+ return [];
20
+ };
21
+ return {
22
+ available: false,
23
+ getFragment: noopWarn,
24
+ getFragments: noopWarn,
25
+ getFragmentByType: noopWarn,
26
+ getFragmentsInUse: noopWarn,
27
+ getOperation: noopWarn,
28
+ getOperations: noopWarn,
29
+ getOperationByType: noopWarn,
30
+ };
31
+ }
32
+ // Since the siblings array is cached, we can use it as cache key.
33
+ // We should get the same array reference each time we get
34
+ // to this point for the same graphql project
35
+ const value = siblingOperationsCache.get(siblings);
36
+ if (value) {
37
+ return value;
38
+ }
39
+ let fragmentsCache = null;
40
+ const getFragments = () => {
41
+ var _a;
42
+ if (fragmentsCache === null) {
43
+ const result = [];
44
+ for (const source of siblings) {
45
+ for (const definition of ((_a = source.document) === null || _a === void 0 ? void 0 : _a.definitions) || []) {
46
+ if (definition.kind === Kind.FRAGMENT_DEFINITION) {
47
+ result.push({
48
+ filePath: source.location,
49
+ document: definition,
50
+ });
51
+ }
52
+ }
53
+ }
54
+ fragmentsCache = result;
55
+ }
56
+ return fragmentsCache;
57
+ };
58
+ let cachedOperations = null;
59
+ const getOperations = () => {
60
+ var _a;
61
+ if (cachedOperations === null) {
62
+ const result = [];
63
+ for (const source of siblings) {
64
+ for (const definition of ((_a = source.document) === null || _a === void 0 ? void 0 : _a.definitions) || []) {
65
+ if (definition.kind === Kind.OPERATION_DEFINITION) {
66
+ result.push({
67
+ filePath: source.location,
68
+ document: definition,
69
+ });
70
+ }
71
+ }
72
+ }
73
+ cachedOperations = result;
74
+ }
75
+ return cachedOperations;
76
+ };
77
+ const getFragment = (name) => getFragments().filter(f => { var _a; return ((_a = f.document.name) === null || _a === void 0 ? void 0 : _a.value) === name; });
78
+ const collectFragments = (selectable, recursive, collected = new Map()) => {
79
+ visit(selectable, {
80
+ FragmentSpread(spread) {
81
+ const fragmentName = spread.name.value;
82
+ const [fragment] = getFragment(fragmentName);
83
+ if (!fragment) {
84
+ logger.warn(`Unable to locate fragment named "${fragmentName}", please make sure it's loaded using "parserOptions.operations"`);
85
+ return;
86
+ }
87
+ if (!collected.has(fragmentName)) {
88
+ collected.set(fragmentName, fragment.document);
89
+ if (recursive) {
90
+ collectFragments(fragment.document, recursive, collected);
91
+ }
92
+ }
93
+ },
94
+ });
95
+ return collected;
96
+ };
97
+ const siblingOperations = {
98
+ available: true,
99
+ getFragment,
100
+ getFragments,
101
+ getFragmentByType: typeName => getFragments().filter(f => { var _a, _b; return ((_b = (_a = f.document.typeCondition) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) === typeName; }),
102
+ getFragmentsInUse: (selectable, recursive = true) => Array.from(collectFragments(selectable, recursive).values()),
103
+ getOperation: name => getOperations().filter(o => { var _a; return ((_a = o.document.name) === null || _a === void 0 ? void 0 : _a.value) === name; }),
104
+ getOperations,
105
+ getOperationByType: type => getOperations().filter(o => o.document.operation === type),
106
+ };
107
+ siblingOperationsCache.set(siblings, siblingOperations);
108
+ return siblingOperations;
109
+ }
package/esm/utils.js CHANGED
@@ -29,6 +29,7 @@ export const logger = {
29
29
  export const normalizePath = (path) => (path || '').replace(/\\/g, '/');
30
30
  export const VIRTUAL_DOCUMENT_REGEX = /\/\d+_document.graphql$/;
31
31
  export const CWD = process.cwd();
32
+ export const IS_BROWSER = typeof window !== 'undefined';
32
33
  export const getTypeName = (node) => 'type' in node ? getTypeName(node.type) : 'name' in node && node.name ? node.name.value : '';
33
34
  export const TYPES_KINDS = [
34
35
  Kind.OBJECT_TYPE_DEFINITION,
@@ -84,5 +85,5 @@ export const ARRAY_DEFAULT_OPTIONS = {
84
85
  };
85
86
  export const englishJoinWords = (words) => new Intl.ListFormat('en-US', { type: 'disjunction' }).format(words);
86
87
  export function truthy(value) {
87
- return Boolean(value);
88
+ return !!value;
88
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.14.4-alpha-20230111221804-f30b422",
3
+ "version": "3.14.4-alpha-20230111225020-02d9c28",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,21 +1,3 @@
1
- import { FragmentDefinitionNode, OperationDefinitionNode, OperationTypeNode, SelectionSetNode } from 'graphql';
1
+ import { Source } from '@graphql-tools/utils';
2
2
  import { GraphQLProjectConfig } from 'graphql-config';
3
- export type FragmentSource = {
4
- filePath: string;
5
- document: FragmentDefinitionNode;
6
- };
7
- export type OperationSource = {
8
- filePath: string;
9
- document: OperationDefinitionNode;
10
- };
11
- export type SiblingOperations = {
12
- available: boolean;
13
- getFragment(fragmentName: string): FragmentSource[];
14
- getFragments(): FragmentSource[];
15
- getFragmentByType(typeName: string): FragmentSource[];
16
- getFragmentsInUse(baseOperation: OperationDefinitionNode | FragmentDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
17
- getOperation(operationName: string): OperationSource[];
18
- getOperations(): OperationSource[];
19
- getOperationByType(operationType: OperationTypeNode): OperationSource[];
20
- };
21
- export declare function getDocuments(project: GraphQLProjectConfig): SiblingOperations;
3
+ export declare const getDocuments: (project: GraphQLProjectConfig) => Source[];
@@ -1,21 +1,3 @@
1
- import { FragmentDefinitionNode, OperationDefinitionNode, OperationTypeNode, SelectionSetNode } from 'graphql';
1
+ import { Source } from '@graphql-tools/utils';
2
2
  import { GraphQLProjectConfig } from 'graphql-config';
3
- export type FragmentSource = {
4
- filePath: string;
5
- document: FragmentDefinitionNode;
6
- };
7
- export type OperationSource = {
8
- filePath: string;
9
- document: OperationDefinitionNode;
10
- };
11
- export type SiblingOperations = {
12
- available: boolean;
13
- getFragment(fragmentName: string): FragmentSource[];
14
- getFragments(): FragmentSource[];
15
- getFragmentByType(typeName: string): FragmentSource[];
16
- getFragmentsInUse(baseOperation: OperationDefinitionNode | FragmentDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
17
- getOperation(operationName: string): OperationSource[];
18
- getOperations(): OperationSource[];
19
- getOperationByType(operationType: OperationTypeNode): OperationSource[];
20
- };
21
- export declare function getDocuments(project: GraphQLProjectConfig): SiblingOperations;
3
+ export declare const getDocuments: (project: GraphQLProjectConfig) => Source[];
@@ -10,7 +10,7 @@ declare const schema: {
10
10
  readonly checkInputType: {
11
11
  readonly type: "boolean";
12
12
  readonly default: false;
13
- readonly description: "Check that the input type name follows the convention <mutationName>Input";
13
+ readonly description: "Check that the input type name follows the convention \\<mutationName>Input";
14
14
  };
15
15
  readonly caseSensitiveInputType: {
16
16
  readonly type: "boolean";
@@ -10,7 +10,7 @@ declare const schema: {
10
10
  readonly checkInputType: {
11
11
  readonly type: "boolean";
12
12
  readonly default: false;
13
- readonly description: "Check that the input type name follows the convention <mutationName>Input";
13
+ readonly description: "Check that the input type name follows the convention \\<mutationName>Input";
14
14
  };
15
15
  readonly caseSensitiveInputType: {
16
16
  readonly type: "boolean";
@@ -0,0 +1,22 @@
1
+ import { FragmentDefinitionNode, OperationDefinitionNode, OperationTypeNode, SelectionSetNode } from 'graphql';
2
+ import { GraphQLProjectConfig } from 'graphql-config';
3
+ import { ParserOptions } from './types.cjs';
4
+ export type FragmentSource = {
5
+ filePath: string;
6
+ document: FragmentDefinitionNode;
7
+ };
8
+ export type OperationSource = {
9
+ filePath: string;
10
+ document: OperationDefinitionNode;
11
+ };
12
+ export type SiblingOperations = {
13
+ available: boolean;
14
+ getFragment(fragmentName: string): FragmentSource[];
15
+ getFragments(): FragmentSource[];
16
+ getFragmentByType(typeName: string): FragmentSource[];
17
+ getFragmentsInUse(baseOperation: OperationDefinitionNode | FragmentDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
18
+ getOperation(operationName: string): OperationSource[];
19
+ getOperations(): OperationSource[];
20
+ getOperationByType(operationType: OperationTypeNode): OperationSource[];
21
+ };
22
+ export declare function getSiblings(project?: GraphQLProjectConfig, documents?: ParserOptions['documents']): SiblingOperations;
@@ -0,0 +1,22 @@
1
+ import { FragmentDefinitionNode, OperationDefinitionNode, OperationTypeNode, SelectionSetNode } from 'graphql';
2
+ import { GraphQLProjectConfig } from 'graphql-config';
3
+ import { ParserOptions } from './types.js';
4
+ export type FragmentSource = {
5
+ filePath: string;
6
+ document: FragmentDefinitionNode;
7
+ };
8
+ export type OperationSource = {
9
+ filePath: string;
10
+ document: OperationDefinitionNode;
11
+ };
12
+ export type SiblingOperations = {
13
+ available: boolean;
14
+ getFragment(fragmentName: string): FragmentSource[];
15
+ getFragments(): FragmentSource[];
16
+ getFragmentByType(typeName: string): FragmentSource[];
17
+ getFragmentsInUse(baseOperation: OperationDefinitionNode | FragmentDefinitionNode | SelectionSetNode, recursive?: boolean): FragmentDefinitionNode[];
18
+ getOperation(operationName: string): OperationSource[];
19
+ getOperations(): OperationSource[];
20
+ getOperationByType(operationType: OperationTypeNode): OperationSource[];
21
+ };
22
+ export declare function getSiblings(project?: GraphQLProjectConfig, documents?: ParserOptions['documents']): SiblingOperations;
@@ -4,7 +4,7 @@ import * as ESTree from 'estree';
4
4
  import { GraphQLSchema } from 'graphql';
5
5
  import { IExtensions, IGraphQLProject } from 'graphql-config';
6
6
  import { JSONSchema } from 'json-schema-to-ts';
7
- import { SiblingOperations } from './documents.cjs';
7
+ import { SiblingOperations } from './siblings.cjs';
8
8
  import { GraphQLESLintRuleListener } from './testkit.cjs';
9
9
  export type Schema = GraphQLSchema | Error | null;
10
10
  export type Pointer = string | string[];
@@ -13,7 +13,6 @@ export interface ParserOptions {
13
13
  headers: Record<string, string>;
14
14
  }>;
15
15
  documents?: Pointer;
16
- operations?: Pointer;
17
16
  extensions?: IExtensions;
18
17
  include?: Pointer;
19
18
  exclude?: Pointer;
@@ -24,6 +23,8 @@ export interface ParserOptions {
24
23
  graphQLParserOptions?: Omit<GraphQLParseOptions, 'noLocation'>;
25
24
  skipGraphQLConfig?: boolean;
26
25
  filePath: string;
26
+ /** @deprecated Use `documents` instead */
27
+ operations?: Pointer;
27
28
  }
28
29
  export type ParserServices = {
29
30
  schema: Schema;
@@ -4,7 +4,7 @@ import * as ESTree from 'estree';
4
4
  import { GraphQLSchema } from 'graphql';
5
5
  import { IExtensions, IGraphQLProject } from 'graphql-config';
6
6
  import { JSONSchema } from 'json-schema-to-ts';
7
- import { SiblingOperations } from './documents.js';
7
+ import { SiblingOperations } from './siblings.js';
8
8
  import { GraphQLESLintRuleListener } from './testkit.js';
9
9
  export type Schema = GraphQLSchema | Error | null;
10
10
  export type Pointer = string | string[];
@@ -13,7 +13,6 @@ export interface ParserOptions {
13
13
  headers: Record<string, string>;
14
14
  }>;
15
15
  documents?: Pointer;
16
- operations?: Pointer;
17
16
  extensions?: IExtensions;
18
17
  include?: Pointer;
19
18
  exclude?: Pointer;
@@ -24,6 +23,8 @@ export interface ParserOptions {
24
23
  graphQLParserOptions?: Omit<GraphQLParseOptions, 'noLocation'>;
25
24
  skipGraphQLConfig?: boolean;
26
25
  filePath: string;
26
+ /** @deprecated Use `documents` instead */
27
+ operations?: Pointer;
27
28
  }
28
29
  export type ParserServices = {
29
30
  schema: Schema;
@@ -1,7 +1,7 @@
1
1
  import { AST } from 'eslint';
2
2
  import { Position } from 'estree';
3
3
  import { ASTNode, GraphQLSchema, Kind } from 'graphql';
4
- import { SiblingOperations } from './documents.cjs';
4
+ import { SiblingOperations } from './siblings.cjs';
5
5
  import { GraphQLESLintRuleContext } from './types.cjs';
6
6
  export declare function requireSiblingsOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
7
7
  export declare function requireGraphQLSchemaFromContext(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
@@ -12,6 +12,7 @@ export declare const logger: {
12
12
  export declare const normalizePath: (path: string) => string;
13
13
  export declare const VIRTUAL_DOCUMENT_REGEX: RegExp;
14
14
  export declare const CWD: string;
15
+ export declare const IS_BROWSER: boolean;
15
16
  export declare const getTypeName: (node: ASTNode) => string;
16
17
  export declare const TYPES_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION];
17
18
  export type CaseStyle = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE' | 'kebab-case';
@@ -1,7 +1,7 @@
1
1
  import { AST } from 'eslint';
2
2
  import { Position } from 'estree';
3
3
  import { ASTNode, GraphQLSchema, Kind } from 'graphql';
4
- import { SiblingOperations } from './documents.js';
4
+ import { SiblingOperations } from './siblings.js';
5
5
  import { GraphQLESLintRuleContext } from './types.js';
6
6
  export declare function requireSiblingsOperations(ruleId: string, context: GraphQLESLintRuleContext): SiblingOperations | never;
7
7
  export declare function requireGraphQLSchemaFromContext(ruleId: string, context: GraphQLESLintRuleContext): GraphQLSchema | never;
@@ -12,6 +12,7 @@ export declare const logger: {
12
12
  export declare const normalizePath: (path: string) => string;
13
13
  export declare const VIRTUAL_DOCUMENT_REGEX: RegExp;
14
14
  export declare const CWD: string;
15
+ export declare const IS_BROWSER: boolean;
15
16
  export declare const getTypeName: (node: ASTNode) => string;
16
17
  export declare const TYPES_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION];
17
18
  export type CaseStyle = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE' | 'kebab-case';