graphql 16.14.2 → 16.15.0

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 (240) hide show
  1. package/error/GraphQLError.d.ts +5 -1
  2. package/error/GraphQLError.js +12 -7
  3. package/error/GraphQLError.mjs +13 -6
  4. package/error/locatedError.d.ts +6 -4
  5. package/error/locatedError.js +6 -4
  6. package/error/locatedError.mjs +6 -4
  7. package/execution/collectFields.d.ts +1 -0
  8. package/execution/collectFields.js +9 -0
  9. package/execution/collectFields.mjs +9 -0
  10. package/execution/execute.d.ts +9 -10
  11. package/execution/execute.js +44 -29
  12. package/execution/execute.mjs +44 -29
  13. package/execution/mapAsyncIterator.js +12 -11
  14. package/execution/mapAsyncIterator.mjs +12 -11
  15. package/execution/subscribe.d.ts +5 -2
  16. package/execution/subscribe.js +5 -2
  17. package/execution/subscribe.mjs +5 -2
  18. package/execution/values.d.ts +43 -21
  19. package/execution/values.js +52 -24
  20. package/execution/values.mjs +51 -23
  21. package/graphql.d.ts +8 -14
  22. package/graphql.js +16 -15
  23. package/graphql.mjs +11 -15
  24. package/jsutils/SetMap.d.ts +14 -0
  25. package/jsutils/SetMap.js +48 -0
  26. package/jsutils/SetMap.mjs +39 -0
  27. package/jsutils/isIterableObject.d.ts +2 -0
  28. package/jsutils/isIterableObject.js +2 -0
  29. package/jsutils/isIterableObject.mjs +2 -0
  30. package/jsutils/keyMap.d.ts +2 -0
  31. package/jsutils/keyMap.js +2 -0
  32. package/jsutils/keyMap.mjs +2 -0
  33. package/jsutils/keyValMap.d.ts +3 -3
  34. package/jsutils/keyValMap.js +3 -3
  35. package/jsutils/keyValMap.mjs +3 -3
  36. package/language/ast.d.ts +2 -6
  37. package/language/ast.js +2 -6
  38. package/language/ast.mjs +2 -6
  39. package/language/lexer.d.ts +6 -0
  40. package/language/lexer.js +22 -0
  41. package/language/lexer.mjs +22 -0
  42. package/language/location.d.ts +8 -3
  43. package/language/location.js +57 -17
  44. package/language/location.mjs +56 -16
  45. package/language/parser.d.ts +27 -13
  46. package/language/parser.js +31 -9
  47. package/language/parser.mjs +31 -9
  48. package/language/predicates.d.ts +10 -3
  49. package/language/predicates.js +10 -3
  50. package/language/predicates.mjs +10 -3
  51. package/language/printLocation.d.ts +2 -6
  52. package/language/printLocation.js +2 -6
  53. package/language/printLocation.mjs +2 -6
  54. package/language/printer.d.ts +22 -3
  55. package/language/printer.js +394 -308
  56. package/language/printer.mjs +394 -308
  57. package/language/reducer.d.ts +32 -0
  58. package/language/reducer.js +95 -0
  59. package/language/reducer.mjs +86 -0
  60. package/language/source.d.ts +4 -5
  61. package/language/source.js +4 -5
  62. package/language/source.mjs +4 -5
  63. package/language/visitor.d.ts +16 -10
  64. package/language/visitor.js +15 -7
  65. package/language/visitor.mjs +15 -7
  66. package/package.json +1 -4
  67. package/type/definition.d.ts +170 -102
  68. package/type/definition.js +169 -96
  69. package/type/definition.mjs +168 -95
  70. package/type/directives.d.ts +12 -6
  71. package/type/directives.js +12 -6
  72. package/type/directives.mjs +12 -6
  73. package/type/scalars.js +8 -11
  74. package/type/scalars.mjs +1 -1
  75. package/type/schema.d.ts +36 -11
  76. package/type/schema.js +35 -10
  77. package/type/schema.mjs +35 -10
  78. package/type/validate.d.ts +1 -3
  79. package/type/validate.js +1 -3
  80. package/type/validate.mjs +1 -3
  81. package/utilities/TypeInfo.d.ts +15 -11
  82. package/utilities/TypeInfo.js +15 -11
  83. package/utilities/TypeInfo.mjs +15 -11
  84. package/utilities/assertValidName.d.ts +1 -1
  85. package/utilities/assertValidName.js +1 -1
  86. package/utilities/assertValidName.mjs +1 -1
  87. package/utilities/astFromValue.d.ts +3 -1
  88. package/utilities/astFromValue.js +3 -1
  89. package/utilities/astFromValue.mjs +3 -1
  90. package/utilities/buildASTSchema.d.ts +8 -8
  91. package/utilities/buildASTSchema.js +9 -20
  92. package/utilities/buildASTSchema.mjs +9 -20
  93. package/utilities/buildClientSchema.d.ts +6 -2
  94. package/utilities/buildClientSchema.js +6 -2
  95. package/utilities/buildClientSchema.mjs +6 -2
  96. package/utilities/coerceInputValue.d.ts +9 -3
  97. package/utilities/coerceInputValue.js +60 -13
  98. package/utilities/coerceInputValue.mjs +58 -13
  99. package/utilities/concatAST.d.ts +4 -1
  100. package/utilities/concatAST.js +4 -1
  101. package/utilities/concatAST.mjs +4 -1
  102. package/utilities/extendSchema.d.ts +7 -4
  103. package/utilities/extendSchema.js +7 -4
  104. package/utilities/extendSchema.mjs +7 -4
  105. package/utilities/findBreakingChanges.d.ts +2 -2
  106. package/utilities/findBreakingChanges.js +2 -2
  107. package/utilities/findBreakingChanges.mjs +2 -2
  108. package/utilities/getIntrospectionQuery.d.ts +9 -9
  109. package/utilities/getIntrospectionQuery.js +8 -8
  110. package/utilities/getIntrospectionQuery.mjs +8 -8
  111. package/utilities/getOperationAST.d.ts +2 -2
  112. package/utilities/getOperationAST.js +2 -2
  113. package/utilities/getOperationAST.mjs +2 -2
  114. package/utilities/getOperationRootType.d.ts +3 -1
  115. package/utilities/getOperationRootType.js +3 -1
  116. package/utilities/getOperationRootType.mjs +3 -1
  117. package/utilities/introspectionFromSchema.d.ts +12 -4
  118. package/utilities/introspectionFromSchema.js +12 -4
  119. package/utilities/introspectionFromSchema.mjs +12 -4
  120. package/utilities/lexicographicSortSchema.d.ts +17 -13
  121. package/utilities/lexicographicSortSchema.js +17 -13
  122. package/utilities/lexicographicSortSchema.mjs +17 -13
  123. package/utilities/printSchema.d.ts +7 -4
  124. package/utilities/printSchema.js +7 -4
  125. package/utilities/printSchema.mjs +7 -4
  126. package/utilities/resolveSchemaCoordinate.d.ts +9 -8
  127. package/utilities/resolveSchemaCoordinate.js +9 -8
  128. package/utilities/resolveSchemaCoordinate.mjs +9 -8
  129. package/utilities/separateOperations.d.ts +2 -2
  130. package/utilities/separateOperations.js +2 -2
  131. package/utilities/separateOperations.mjs +2 -2
  132. package/utilities/stripIgnoredCharacters.d.ts +19 -5
  133. package/utilities/stripIgnoredCharacters.js +19 -5
  134. package/utilities/stripIgnoredCharacters.mjs +19 -5
  135. package/utilities/typeComparators.d.ts +1 -5
  136. package/utilities/typeComparators.js +1 -5
  137. package/utilities/typeComparators.mjs +1 -5
  138. package/utilities/valueFromAST.js +4 -4
  139. package/utilities/valueFromAST.mjs +4 -4
  140. package/utilities/valueFromASTUntyped.d.ts +1 -3
  141. package/utilities/valueFromASTUntyped.js +1 -3
  142. package/utilities/valueFromASTUntyped.mjs +1 -3
  143. package/validation/ValidationContext.d.ts +22 -3
  144. package/validation/ValidationContext.js +84 -27
  145. package/validation/ValidationContext.mjs +82 -27
  146. package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -4
  147. package/validation/rules/ExecutableDefinitionsRule.js +6 -4
  148. package/validation/rules/ExecutableDefinitionsRule.mjs +6 -4
  149. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +4 -4
  150. package/validation/rules/FieldsOnCorrectTypeRule.js +10 -6
  151. package/validation/rules/FieldsOnCorrectTypeRule.mjs +12 -6
  152. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -4
  153. package/validation/rules/FragmentsOnCompositeTypesRule.js +6 -4
  154. package/validation/rules/FragmentsOnCompositeTypesRule.mjs +6 -4
  155. package/validation/rules/KnownArgumentNamesRule.d.ts +4 -4
  156. package/validation/rules/KnownArgumentNamesRule.js +26 -17
  157. package/validation/rules/KnownArgumentNamesRule.mjs +21 -11
  158. package/validation/rules/KnownDirectivesRule.d.ts +1 -3
  159. package/validation/rules/KnownDirectivesRule.js +1 -3
  160. package/validation/rules/KnownDirectivesRule.mjs +1 -3
  161. package/validation/rules/KnownFragmentNamesRule.d.ts +4 -4
  162. package/validation/rules/KnownFragmentNamesRule.js +4 -4
  163. package/validation/rules/KnownFragmentNamesRule.mjs +4 -4
  164. package/validation/rules/KnownTypeNamesRule.d.ts +1 -3
  165. package/validation/rules/KnownTypeNamesRule.js +7 -7
  166. package/validation/rules/KnownTypeNamesRule.mjs +7 -7
  167. package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -4
  168. package/validation/rules/LoneAnonymousOperationRule.js +6 -4
  169. package/validation/rules/LoneAnonymousOperationRule.mjs +6 -4
  170. package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -4
  171. package/validation/rules/MaxIntrospectionDepthRule.js +44 -19
  172. package/validation/rules/MaxIntrospectionDepthRule.mjs +44 -19
  173. package/validation/rules/NoFragmentCyclesRule.d.ts +1 -3
  174. package/validation/rules/NoFragmentCyclesRule.js +1 -3
  175. package/validation/rules/NoFragmentCyclesRule.mjs +1 -3
  176. package/validation/rules/NoUndefinedVariablesRule.d.ts +4 -4
  177. package/validation/rules/NoUndefinedVariablesRule.js +4 -4
  178. package/validation/rules/NoUndefinedVariablesRule.mjs +4 -4
  179. package/validation/rules/NoUnusedFragmentsRule.d.ts +4 -4
  180. package/validation/rules/NoUnusedFragmentsRule.js +10 -14
  181. package/validation/rules/NoUnusedFragmentsRule.mjs +10 -14
  182. package/validation/rules/NoUnusedVariablesRule.d.ts +4 -4
  183. package/validation/rules/NoUnusedVariablesRule.js +4 -4
  184. package/validation/rules/NoUnusedVariablesRule.mjs +4 -4
  185. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +8 -6
  186. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +552 -354
  187. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +545 -352
  188. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -4
  189. package/validation/rules/PossibleFragmentSpreadsRule.js +6 -4
  190. package/validation/rules/PossibleFragmentSpreadsRule.mjs +6 -4
  191. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -4
  192. package/validation/rules/ProvidedRequiredArgumentsRule.js +6 -4
  193. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +6 -4
  194. package/validation/rules/ScalarLeafsRule.d.ts +1 -3
  195. package/validation/rules/ScalarLeafsRule.js +1 -3
  196. package/validation/rules/ScalarLeafsRule.mjs +1 -3
  197. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -4
  198. package/validation/rules/SingleFieldSubscriptionsRule.js +50 -9
  199. package/validation/rules/SingleFieldSubscriptionsRule.mjs +50 -9
  200. package/validation/rules/UniqueArgumentNamesRule.d.ts +4 -4
  201. package/validation/rules/UniqueArgumentNamesRule.js +4 -4
  202. package/validation/rules/UniqueArgumentNamesRule.mjs +4 -4
  203. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -4
  204. package/validation/rules/UniqueDirectivesPerLocationRule.js +6 -4
  205. package/validation/rules/UniqueDirectivesPerLocationRule.mjs +6 -4
  206. package/validation/rules/UniqueFragmentNamesRule.d.ts +4 -4
  207. package/validation/rules/UniqueFragmentNamesRule.js +4 -4
  208. package/validation/rules/UniqueFragmentNamesRule.mjs +4 -4
  209. package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -4
  210. package/validation/rules/UniqueInputFieldNamesRule.js +6 -4
  211. package/validation/rules/UniqueInputFieldNamesRule.mjs +6 -4
  212. package/validation/rules/UniqueOperationNamesRule.d.ts +4 -4
  213. package/validation/rules/UniqueOperationNamesRule.js +4 -4
  214. package/validation/rules/UniqueOperationNamesRule.mjs +4 -4
  215. package/validation/rules/UniqueVariableNamesRule.d.ts +4 -4
  216. package/validation/rules/UniqueVariableNamesRule.js +4 -4
  217. package/validation/rules/UniqueVariableNamesRule.mjs +4 -4
  218. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +4 -4
  219. package/validation/rules/ValuesOfCorrectTypeRule.js +29 -23
  220. package/validation/rules/ValuesOfCorrectTypeRule.mjs +24 -14
  221. package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -4
  222. package/validation/rules/VariablesAreInputTypesRule.js +6 -4
  223. package/validation/rules/VariablesAreInputTypesRule.mjs +6 -4
  224. package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -4
  225. package/validation/rules/VariablesInAllowedPositionRule.js +6 -4
  226. package/validation/rules/VariablesInAllowedPositionRule.mjs +6 -4
  227. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +4 -4
  228. package/validation/rules/custom/NoDeprecatedCustomRule.js +4 -4
  229. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +4 -4
  230. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +7 -5
  231. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +7 -5
  232. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +7 -5
  233. package/validation/validate.d.ts +2 -0
  234. package/validation/validate.js +14 -2
  235. package/validation/validate.mjs +13 -2
  236. package/validation/validationAbortedError.d.ts +3 -0
  237. package/validation/validationAbortedError.js +14 -0
  238. package/validation/validationAbortedError.mjs +4 -0
  239. package/version.js +3 -3
  240. package/version.mjs +3 -3
@@ -25,16 +25,18 @@ import { Kind } from '../../language/kinds.mjs';
25
25
  * const invalidDocument = parse(`
26
26
  * query { name } query Other { name }
27
27
  * `);
28
- * const invalidErrors = validate(schema, invalidDocument, [LoneAnonymousOperationRule]);
28
+ * const invalidErrors = validate(schema, invalidDocument, [
29
+ * LoneAnonymousOperationRule,
30
+ * ]);
29
31
  *
30
32
  * invalidErrors.length; // => 1
31
33
  *
32
34
  * const validDocument = parse(`
33
35
  * { name }
34
36
  * `);
35
- * const validErrors = validate(schema, validDocument, [LoneAnonymousOperationRule]);
36
- *
37
- * validErrors; // => []
37
+ * const validErrors = validate(schema, validDocument, [
38
+ * LoneAnonymousOperationRule,
39
+ * ]); // => []
38
40
  * ```
39
41
  */
40
42
  export function LoneAnonymousOperationRule(context) {
@@ -19,16 +19,18 @@ import type { ASTValidationContext } from '../ValidationContext';
19
19
  * const invalidDocument = parse(`
20
20
  * { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
21
21
  * `);
22
- * const invalidErrors = validate(schema, invalidDocument, [MaxIntrospectionDepthRule]);
22
+ * const invalidErrors = validate(schema, invalidDocument, [
23
+ * MaxIntrospectionDepthRule,
24
+ * ]);
23
25
  *
24
26
  * invalidErrors.length; // => 1
25
27
  *
26
28
  * const validDocument = parse(`
27
29
  * { __schema { queryType { name } } }
28
30
  * `);
29
- * const validErrors = validate(schema, validDocument, [MaxIntrospectionDepthRule]);
30
- *
31
- * validErrors; // => []
31
+ * const validErrors = validate(schema, validDocument, [
32
+ * MaxIntrospectionDepthRule,
33
+ * ]); // => []
32
34
  * ```
33
35
  */
34
36
  export declare function MaxIntrospectionDepthRule(
@@ -29,32 +29,54 @@ const MAX_LISTS_DEPTH = 3;
29
29
  * const invalidDocument = parse(`
30
30
  * { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
31
31
  * `);
32
- * const invalidErrors = validate(schema, invalidDocument, [MaxIntrospectionDepthRule]);
32
+ * const invalidErrors = validate(schema, invalidDocument, [
33
+ * MaxIntrospectionDepthRule,
34
+ * ]);
33
35
  *
34
36
  * invalidErrors.length; // => 1
35
37
  *
36
38
  * const validDocument = parse(`
37
39
  * { __schema { queryType { name } } }
38
40
  * `);
39
- * const validErrors = validate(schema, validDocument, [MaxIntrospectionDepthRule]);
40
- *
41
- * validErrors; // => []
41
+ * const validErrors = validate(schema, validDocument, [
42
+ * MaxIntrospectionDepthRule,
43
+ * ]); // => []
42
44
  * ```
43
45
  */
44
46
 
45
47
  function MaxIntrospectionDepthRule(context) {
48
+ // For each fragment, the greatest entry depth at which its check completed
49
+ // without reaching the limit. Shared across root checks.
50
+ // Entry depth is the list depth before entering the fragment.
51
+ const checkedFragments = Object.create(null); // For each fragment, the smallest entry depth at which its check reached
52
+ // the limit. Shared across root checks.
53
+
54
+ const exceededFragments = Object.create(null);
46
55
  /**
47
56
  * Counts the depth of list fields in "__Type" recursively and
48
57
  * returns `true` if the limit has been reached.
49
58
  *
50
59
  * @internal
51
60
  */
52
- function checkDepth(node, visitedFragments = Object.create(null), depth = 0) {
61
+
62
+ function checkDepth(node, visitedFragments, depth = 0) {
53
63
  if (node.kind === _kinds.Kind.FRAGMENT_SPREAD) {
54
64
  const fragmentName = node.name.value;
65
+ const exceededEntryDepth = exceededFragments[fragmentName]; // A check that reached the limit will also do so when repeated at an
66
+ // equal or greater entry depth.
67
+
68
+ if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
69
+ return true;
70
+ }
71
+
72
+ const visitedEntryDepth = visitedFragments[fragmentName];
73
+ const checkedEntryDepth = checkedFragments[fragmentName]; // At equal or shallower entry depths, skip revisits to break cycles
74
+ // or reuse a completed successful check.
55
75
 
56
- if (visitedFragments[fragmentName] === true) {
57
- // Fragment cycles are handled by `NoFragmentCyclesRule`.
76
+ if (
77
+ (visitedEntryDepth !== undefined && visitedEntryDepth >= depth) ||
78
+ (checkedEntryDepth !== undefined && checkedEntryDepth >= depth)
79
+ ) {
58
80
  return false;
59
81
  }
60
82
 
@@ -63,18 +85,17 @@ function MaxIntrospectionDepthRule(context) {
63
85
  if (!fragment) {
64
86
  // Missing fragments checks are handled by `KnownFragmentNamesRule`.
65
87
  return false;
66
- } // Rather than following an immutable programming pattern which has
67
- // significant memory and garbage collection overhead, we've opted to
68
- // take a mutable approach for efficiency's sake. Importantly visiting a
69
- // fragment twice is fine, so long as you don't do one visit inside the
70
- // other.
71
-
72
- try {
73
- visitedFragments[fragmentName] = true;
74
- return checkDepth(fragment, visitedFragments, depth);
75
- } finally {
76
- visitedFragments[fragmentName] = undefined;
77
88
  }
89
+
90
+ visitedFragments[fragmentName] = depth;
91
+
92
+ if (checkDepth(fragment, visitedFragments, depth)) {
93
+ exceededFragments[fragmentName] = depth;
94
+ return true;
95
+ }
96
+
97
+ checkedFragments[fragmentName] = depth;
98
+ return false;
78
99
  }
79
100
 
80
101
  if (
@@ -106,7 +127,11 @@ function MaxIntrospectionDepthRule(context) {
106
127
  return {
107
128
  Field(node) {
108
129
  if (node.name.value === '__schema' || node.name.value === '__type') {
109
- if (checkDepth(node)) {
130
+ // For each fragment, the greatest entry depth at which it was visited
131
+ // during this root check, including visits still in progress.
132
+ const visitedFragments = Object.create(null);
133
+
134
+ if (checkDepth(node, visitedFragments)) {
110
135
  context.reportError(
111
136
  new _GraphQLError.GraphQLError(
112
137
  'Maximum introspection depth exceeded',
@@ -20,32 +20,54 @@ const MAX_LISTS_DEPTH = 3;
20
20
  * const invalidDocument = parse(`
21
21
  * { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
22
22
  * `);
23
- * const invalidErrors = validate(schema, invalidDocument, [MaxIntrospectionDepthRule]);
23
+ * const invalidErrors = validate(schema, invalidDocument, [
24
+ * MaxIntrospectionDepthRule,
25
+ * ]);
24
26
  *
25
27
  * invalidErrors.length; // => 1
26
28
  *
27
29
  * const validDocument = parse(`
28
30
  * { __schema { queryType { name } } }
29
31
  * `);
30
- * const validErrors = validate(schema, validDocument, [MaxIntrospectionDepthRule]);
31
- *
32
- * validErrors; // => []
32
+ * const validErrors = validate(schema, validDocument, [
33
+ * MaxIntrospectionDepthRule,
34
+ * ]); // => []
33
35
  * ```
34
36
  */
35
37
 
36
38
  export function MaxIntrospectionDepthRule(context) {
39
+ // For each fragment, the greatest entry depth at which its check completed
40
+ // without reaching the limit. Shared across root checks.
41
+ // Entry depth is the list depth before entering the fragment.
42
+ const checkedFragments = Object.create(null); // For each fragment, the smallest entry depth at which its check reached
43
+ // the limit. Shared across root checks.
44
+
45
+ const exceededFragments = Object.create(null);
37
46
  /**
38
47
  * Counts the depth of list fields in "__Type" recursively and
39
48
  * returns `true` if the limit has been reached.
40
49
  *
41
50
  * @internal
42
51
  */
43
- function checkDepth(node, visitedFragments = Object.create(null), depth = 0) {
52
+
53
+ function checkDepth(node, visitedFragments, depth = 0) {
44
54
  if (node.kind === Kind.FRAGMENT_SPREAD) {
45
55
  const fragmentName = node.name.value;
56
+ const exceededEntryDepth = exceededFragments[fragmentName]; // A check that reached the limit will also do so when repeated at an
57
+ // equal or greater entry depth.
58
+
59
+ if (exceededEntryDepth !== undefined && exceededEntryDepth <= depth) {
60
+ return true;
61
+ }
62
+
63
+ const visitedEntryDepth = visitedFragments[fragmentName];
64
+ const checkedEntryDepth = checkedFragments[fragmentName]; // At equal or shallower entry depths, skip revisits to break cycles
65
+ // or reuse a completed successful check.
46
66
 
47
- if (visitedFragments[fragmentName] === true) {
48
- // Fragment cycles are handled by `NoFragmentCyclesRule`.
67
+ if (
68
+ (visitedEntryDepth !== undefined && visitedEntryDepth >= depth) ||
69
+ (checkedEntryDepth !== undefined && checkedEntryDepth >= depth)
70
+ ) {
49
71
  return false;
50
72
  }
51
73
 
@@ -54,18 +76,17 @@ export function MaxIntrospectionDepthRule(context) {
54
76
  if (!fragment) {
55
77
  // Missing fragments checks are handled by `KnownFragmentNamesRule`.
56
78
  return false;
57
- } // Rather than following an immutable programming pattern which has
58
- // significant memory and garbage collection overhead, we've opted to
59
- // take a mutable approach for efficiency's sake. Importantly visiting a
60
- // fragment twice is fine, so long as you don't do one visit inside the
61
- // other.
62
-
63
- try {
64
- visitedFragments[fragmentName] = true;
65
- return checkDepth(fragment, visitedFragments, depth);
66
- } finally {
67
- visitedFragments[fragmentName] = undefined;
68
79
  }
80
+
81
+ visitedFragments[fragmentName] = depth;
82
+
83
+ if (checkDepth(fragment, visitedFragments, depth)) {
84
+ exceededFragments[fragmentName] = depth;
85
+ return true;
86
+ }
87
+
88
+ checkedFragments[fragmentName] = depth;
89
+ return false;
69
90
  }
70
91
 
71
92
  if (
@@ -97,7 +118,11 @@ export function MaxIntrospectionDepthRule(context) {
97
118
  return {
98
119
  Field(node) {
99
120
  if (node.name.value === '__schema' || node.name.value === '__type') {
100
- if (checkDepth(node)) {
121
+ // For each fragment, the greatest entry depth at which it was visited
122
+ // during this root check, including visits still in progress.
123
+ const visitedFragments = Object.create(null);
124
+
125
+ if (checkDepth(node, visitedFragments)) {
101
126
  context.reportError(
102
127
  new GraphQLError('Maximum introspection depth exceeded', {
103
128
  nodes: [node],
@@ -31,9 +31,7 @@ import type { ASTValidationContext } from '../ValidationContext';
31
31
  * const validDocument = parse(`
32
32
  * fragment A on Query { name } query { ...A }
33
33
  * `);
34
- * const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]);
35
- *
36
- * validErrors; // => []
34
+ * const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]); // => []
37
35
  * ```
38
36
  */
39
37
  export declare function NoFragmentCyclesRule(
@@ -39,9 +39,7 @@ var _GraphQLError = require('../../error/GraphQLError.js');
39
39
  * const validDocument = parse(`
40
40
  * fragment A on Query { name } query { ...A }
41
41
  * `);
42
- * const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]);
43
- *
44
- * validErrors; // => []
42
+ * const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]); // => []
45
43
  * ```
46
44
  */
47
45
  function NoFragmentCyclesRule(context) {
@@ -31,9 +31,7 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
31
31
  * const validDocument = parse(`
32
32
  * fragment A on Query { name } query { ...A }
33
33
  * `);
34
- * const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]);
35
- *
36
- * validErrors; // => []
34
+ * const validErrors = validate(schema, validDocument, [NoFragmentCyclesRule]); // => []
37
35
  * ```
38
36
  */
39
37
  export function NoFragmentCyclesRule(context) {
@@ -24,16 +24,16 @@ import type { ValidationContext } from '../ValidationContext';
24
24
  * const invalidDocument = parse(`
25
25
  * query ($id: ID) { field(arg: $missing) }
26
26
  * `);
27
- * const invalidErrors = validate(schema, invalidDocument, [NoUndefinedVariablesRule]);
27
+ * const invalidErrors = validate(schema, invalidDocument, [
28
+ * NoUndefinedVariablesRule,
29
+ * ]);
28
30
  *
29
31
  * invalidErrors.length; // => 1
30
32
  *
31
33
  * const validDocument = parse(`
32
34
  * query ($id: ID) { field(arg: $id) }
33
35
  * `);
34
- * const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]);
35
- *
36
- * validErrors; // => []
36
+ * const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]); // => []
37
37
  * ```
38
38
  */
39
39
  export declare function NoUndefinedVariablesRule(
@@ -32,16 +32,16 @@ var _GraphQLError = require('../../error/GraphQLError.js');
32
32
  * const invalidDocument = parse(`
33
33
  * query ($id: ID) { field(arg: $missing) }
34
34
  * `);
35
- * const invalidErrors = validate(schema, invalidDocument, [NoUndefinedVariablesRule]);
35
+ * const invalidErrors = validate(schema, invalidDocument, [
36
+ * NoUndefinedVariablesRule,
37
+ * ]);
36
38
  *
37
39
  * invalidErrors.length; // => 1
38
40
  *
39
41
  * const validDocument = parse(`
40
42
  * query ($id: ID) { field(arg: $id) }
41
43
  * `);
42
- * const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]);
43
- *
44
- * validErrors; // => []
44
+ * const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]); // => []
45
45
  * ```
46
46
  */
47
47
  function NoUndefinedVariablesRule(context) {
@@ -24,16 +24,16 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
24
24
  * const invalidDocument = parse(`
25
25
  * query ($id: ID) { field(arg: $missing) }
26
26
  * `);
27
- * const invalidErrors = validate(schema, invalidDocument, [NoUndefinedVariablesRule]);
27
+ * const invalidErrors = validate(schema, invalidDocument, [
28
+ * NoUndefinedVariablesRule,
29
+ * ]);
28
30
  *
29
31
  * invalidErrors.length; // => 1
30
32
  *
31
33
  * const validDocument = parse(`
32
34
  * query ($id: ID) { field(arg: $id) }
33
35
  * `);
34
- * const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]);
35
- *
36
- * validErrors; // => []
36
+ * const validErrors = validate(schema, validDocument, [NoUndefinedVariablesRule]); // => []
37
37
  * ```
38
38
  */
39
39
  export function NoUndefinedVariablesRule(context) {
@@ -24,16 +24,16 @@ import type { ASTValidationContext } from '../ValidationContext';
24
24
  * const invalidDocument = parse(`
25
25
  * fragment Unused on Query { name } query { name }
26
26
  * `);
27
- * const invalidErrors = validate(schema, invalidDocument, [NoUnusedFragmentsRule]);
27
+ * const invalidErrors = validate(schema, invalidDocument, [
28
+ * NoUnusedFragmentsRule,
29
+ * ]);
28
30
  *
29
31
  * invalidErrors.length; // => 1
30
32
  *
31
33
  * const validDocument = parse(`
32
34
  * fragment Used on Query { name } query { ...Used }
33
35
  * `);
34
- * const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]);
35
- *
36
- * validErrors; // => []
36
+ * const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]); // => []
37
37
  * ```
38
38
  */
39
39
  export declare function NoUnusedFragmentsRule(
@@ -32,16 +32,16 @@ var _GraphQLError = require('../../error/GraphQLError.js');
32
32
  * const invalidDocument = parse(`
33
33
  * fragment Unused on Query { name } query { name }
34
34
  * `);
35
- * const invalidErrors = validate(schema, invalidDocument, [NoUnusedFragmentsRule]);
35
+ * const invalidErrors = validate(schema, invalidDocument, [
36
+ * NoUnusedFragmentsRule,
37
+ * ]);
36
38
  *
37
39
  * invalidErrors.length; // => 1
38
40
  *
39
41
  * const validDocument = parse(`
40
42
  * fragment Used on Query { name } query { ...Used }
41
43
  * `);
42
- * const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]);
43
- *
44
- * validErrors; // => []
44
+ * const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]); // => []
45
45
  * ```
46
46
  */
47
47
  function NoUnusedFragmentsRule(context) {
@@ -60,20 +60,16 @@ function NoUnusedFragmentsRule(context) {
60
60
 
61
61
  Document: {
62
62
  leave() {
63
- const fragmentNameUsed = Object.create(null);
64
-
65
- for (const operation of operationDefs) {
66
- for (const fragment of context.getRecursivelyReferencedFragments(
67
- operation,
68
- )) {
69
- fragmentNameUsed[fragment.name.value] = true;
70
- }
71
- }
63
+ const fragmentNameUsed = new Set(
64
+ context
65
+ .getRecursivelyReferencedFragmentsForOperations(operationDefs)
66
+ .map((fragment) => fragment.name.value),
67
+ );
72
68
 
73
69
  for (const fragmentDef of fragmentDefs) {
74
70
  const fragName = fragmentDef.name.value;
75
71
 
76
- if (fragmentNameUsed[fragName] !== true) {
72
+ if (!fragmentNameUsed.has(fragName)) {
77
73
  context.reportError(
78
74
  new _GraphQLError.GraphQLError(
79
75
  `Fragment "${fragName}" is never used.`,
@@ -24,16 +24,16 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
24
24
  * const invalidDocument = parse(`
25
25
  * fragment Unused on Query { name } query { name }
26
26
  * `);
27
- * const invalidErrors = validate(schema, invalidDocument, [NoUnusedFragmentsRule]);
27
+ * const invalidErrors = validate(schema, invalidDocument, [
28
+ * NoUnusedFragmentsRule,
29
+ * ]);
28
30
  *
29
31
  * invalidErrors.length; // => 1
30
32
  *
31
33
  * const validDocument = parse(`
32
34
  * fragment Used on Query { name } query { ...Used }
33
35
  * `);
34
- * const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]);
35
- *
36
- * validErrors; // => []
36
+ * const validErrors = validate(schema, validDocument, [NoUnusedFragmentsRule]); // => []
37
37
  * ```
38
38
  */
39
39
  export function NoUnusedFragmentsRule(context) {
@@ -52,20 +52,16 @@ export function NoUnusedFragmentsRule(context) {
52
52
 
53
53
  Document: {
54
54
  leave() {
55
- const fragmentNameUsed = Object.create(null);
56
-
57
- for (const operation of operationDefs) {
58
- for (const fragment of context.getRecursivelyReferencedFragments(
59
- operation,
60
- )) {
61
- fragmentNameUsed[fragment.name.value] = true;
62
- }
63
- }
55
+ const fragmentNameUsed = new Set(
56
+ context
57
+ .getRecursivelyReferencedFragmentsForOperations(operationDefs)
58
+ .map((fragment) => fragment.name.value),
59
+ );
64
60
 
65
61
  for (const fragmentDef of fragmentDefs) {
66
62
  const fragName = fragmentDef.name.value;
67
63
 
68
- if (fragmentNameUsed[fragName] !== true) {
64
+ if (!fragmentNameUsed.has(fragName)) {
69
65
  context.reportError(
70
66
  new GraphQLError(`Fragment "${fragName}" is never used.`, {
71
67
  nodes: fragmentDef,
@@ -25,16 +25,16 @@ import type { ValidationContext } from '../ValidationContext';
25
25
  * const invalidDocument = parse(`
26
26
  * query ($id: ID) { name }
27
27
  * `);
28
- * const invalidErrors = validate(schema, invalidDocument, [NoUnusedVariablesRule]);
28
+ * const invalidErrors = validate(schema, invalidDocument, [
29
+ * NoUnusedVariablesRule,
30
+ * ]);
29
31
  *
30
32
  * invalidErrors.length; // => 1
31
33
  *
32
34
  * const validDocument = parse(`
33
35
  * query ($id: ID) { field(arg: $id) }
34
36
  * `);
35
- * const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]);
36
- *
37
- * validErrors; // => []
37
+ * const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]); // => []
38
38
  * ```
39
39
  */
40
40
  export declare function NoUnusedVariablesRule(
@@ -33,16 +33,16 @@ var _GraphQLError = require('../../error/GraphQLError.js');
33
33
  * const invalidDocument = parse(`
34
34
  * query ($id: ID) { name }
35
35
  * `);
36
- * const invalidErrors = validate(schema, invalidDocument, [NoUnusedVariablesRule]);
36
+ * const invalidErrors = validate(schema, invalidDocument, [
37
+ * NoUnusedVariablesRule,
38
+ * ]);
37
39
  *
38
40
  * invalidErrors.length; // => 1
39
41
  *
40
42
  * const validDocument = parse(`
41
43
  * query ($id: ID) { field(arg: $id) }
42
44
  * `);
43
- * const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]);
44
- *
45
- * validErrors; // => []
45
+ * const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]); // => []
46
46
  * ```
47
47
  */
48
48
  function NoUnusedVariablesRule(context) {
@@ -25,16 +25,16 @@ import { GraphQLError } from '../../error/GraphQLError.mjs';
25
25
  * const invalidDocument = parse(`
26
26
  * query ($id: ID) { name }
27
27
  * `);
28
- * const invalidErrors = validate(schema, invalidDocument, [NoUnusedVariablesRule]);
28
+ * const invalidErrors = validate(schema, invalidDocument, [
29
+ * NoUnusedVariablesRule,
30
+ * ]);
29
31
  *
30
32
  * invalidErrors.length; // => 1
31
33
  *
32
34
  * const validDocument = parse(`
33
35
  * query ($id: ID) { field(arg: $id) }
34
36
  * `);
35
- * const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]);
36
- *
37
- * validErrors; // => []
37
+ * const validErrors = validate(schema, validDocument, [NoUnusedVariablesRule]); // => []
38
38
  * ```
39
39
  */
40
40
  export function NoUnusedVariablesRule(context) {
@@ -9,7 +9,7 @@ import type { ValidationContext } from '../ValidationContext';
9
9
  * without ambiguity.
10
10
  *
11
11
  * See https://spec.graphql.org/draft/#sec-Field-Selection-Merging
12
- * @param context - The validation context used while checking the document.
12
+ * @param validationContext - The validation context used while checking the document.
13
13
  * @returns A visitor that reports validation errors for this rule.
14
14
  * @example
15
15
  * ```ts
@@ -30,18 +30,20 @@ import type { ValidationContext } from '../ValidationContext';
30
30
  * const invalidDocument = parse(`
31
31
  * { dog { value: barkVolume value: name } }
32
32
  * `);
33
- * const invalidErrors = validate(schema, invalidDocument, [OverlappingFieldsCanBeMergedRule]);
33
+ * const invalidErrors = validate(schema, invalidDocument, [
34
+ * OverlappingFieldsCanBeMergedRule,
35
+ * ]);
34
36
  *
35
37
  * invalidErrors.length; // => 1
36
38
  *
37
39
  * const validDocument = parse(`
38
40
  * { dog { barkVolume name } }
39
41
  * `);
40
- * const validErrors = validate(schema, validDocument, [OverlappingFieldsCanBeMergedRule]);
41
- *
42
- * validErrors; // => []
42
+ * const validErrors = validate(schema, validDocument, [
43
+ * OverlappingFieldsCanBeMergedRule,
44
+ * ]); // => []
43
45
  * ```
44
46
  */
45
47
  export declare function OverlappingFieldsCanBeMergedRule(
46
- context: ValidationContext,
48
+ validationContext: ValidationContext,
47
49
  ): ASTVisitor;