graphql 16.14.1 → 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 +190 -122
  68. package/type/definition.js +175 -102
  69. package/type/definition.mjs +174 -101
  70. package/type/directives.d.ts +14 -8
  71. package/type/directives.js +13 -7
  72. package/type/directives.mjs +13 -7
  73. package/type/scalars.js +8 -11
  74. package/type/scalars.mjs +1 -1
  75. package/type/schema.d.ts +38 -13
  76. package/type/schema.js +36 -11
  77. package/type/schema.mjs +36 -11
  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
@@ -1,6 +1,5 @@
1
1
  /** @category Source */
2
- import { invariant } from '../jsutils/invariant.mjs';
3
- const LineRegExp = /\r\n|[\n\r]/g;
2
+
4
3
  /** Represents a location in a Source. */
5
4
 
6
5
  /**
@@ -14,28 +13,69 @@ const LineRegExp = /\r\n|[\n\r]/g;
14
13
  * import { Source, getLocation } from 'graphql/language';
15
14
  *
16
15
  * const source = new Source('type Query { hello: String }');
17
- * const location = getLocation(source, 13);
18
- *
19
- * location; // => { line: 1, column: 14 }
16
+ * const location = getLocation(source, 13); // => { line: 1, column: 14 }
20
17
  * ```
21
18
  */
22
19
  export function getLocation(source, position) {
23
- let lastLineStart = 0;
20
+ const lineRegexp = /\r\n|[\n\r]/g;
24
21
  let line = 1;
22
+ let column = position + 1;
23
+ let match;
25
24
 
26
- for (const match of source.body.matchAll(LineRegExp)) {
27
- typeof match.index === 'number' || invariant(false);
28
-
29
- if (match.index >= position) {
30
- break;
31
- }
32
-
33
- lastLineStart = match.index + match[0].length;
34
- line += 1;
25
+ while ((match = lineRegexp.exec(source.body)) && match.index < position) {
26
+ line++;
27
+ column = position + 1 - (match.index + match[0].length);
35
28
  }
36
29
 
37
30
  return {
38
31
  line,
39
- column: position + 1 - lastLineStart,
32
+ column,
40
33
  };
41
34
  }
35
+ /** @internal */
36
+
37
+ export function getLocations(locations) {
38
+ if (locations.length < 2) {
39
+ return locations.map(({ source, start }) => getLocation(source, start));
40
+ }
41
+
42
+ const bySource = new Map();
43
+ locations.forEach(({ source, start }, index) => {
44
+ let positions = bySource.get(source);
45
+
46
+ if (positions === undefined) {
47
+ positions = [];
48
+ bySource.set(source, positions);
49
+ }
50
+
51
+ positions.push({
52
+ position: start,
53
+ index,
54
+ });
55
+ });
56
+ const result = new Array(locations.length);
57
+
58
+ for (const [source, positions] of bySource) {
59
+ const lineRegexp = /\r\n|[\n\r]/g;
60
+ let match = lineRegexp.exec(source.body);
61
+ let line = 1;
62
+ let lastLineStart = 0; // These arrays are local; sorting never changes the caller's input.
63
+
64
+ positions.sort((a, b) => a.position - b.position);
65
+
66
+ for (const { position, index } of positions) {
67
+ while (match !== null && match.index < position) {
68
+ lastLineStart = match.index + match[0].length;
69
+ line++;
70
+ match = lineRegexp.exec(source.body);
71
+ }
72
+
73
+ result[index] = {
74
+ line,
75
+ column: position + 1 - lastLineStart,
76
+ };
77
+ }
78
+ }
79
+
80
+ return result;
81
+ }
@@ -66,11 +66,22 @@ export interface ParseOptions {
66
66
  */
67
67
  noLocation?: boolean;
68
68
  /**
69
- * Parser CPU and memory usage is linear to the number of tokens in a document
70
- * however in extreme cases it becomes quadratic due to memory exhaustion.
71
- * Parsing happens before validation so even invalid queries can burn lots of
72
- * CPU time and memory.
73
- * To prevent this you can set a maximum number of tokens allowed within a document.
69
+ * Parser CPU and memory usage is linear to the number of lexical tokens in a
70
+ * document; however, in extreme cases it becomes quadratic due to memory
71
+ * exhaustion. Parsing happens before validation, so even invalid queries can
72
+ * consume significant CPU time and memory.
73
+ *
74
+ * Use this option to limit the number of lexical tokens allowed in a document.
75
+ * This does not limit the length of the source text or of an individual token.
76
+ */
77
+ maxLexicalTokens?: number | undefined;
78
+ /** Maximum number of comments. */
79
+ maxComments?: number | undefined;
80
+ /** Maximum source length in UTF-16 code units. */
81
+ maxSourceLength?: number | undefined;
82
+ /**
83
+ * Deprecated alias for `maxLexicalTokens`.
84
+ * @deprecated Use `maxLexicalTokens` instead. Will be removed in v18.
74
85
  */
75
86
  maxTokens?: number | undefined;
76
87
  /**
@@ -82,7 +93,7 @@ export interface ParseOptions {
82
93
  * @example
83
94
  * The syntax is identical to normal, query-defined variables.
84
95
  *
85
- * ```graphql
96
+ * ```graphql prettier-ignore
86
97
  * fragment A($var: Boolean = false) on T {
87
98
  * ...
88
99
  * }
@@ -100,7 +111,7 @@ export interface ParseOptions {
100
111
  * If enabled, the parser will parse directives on directive definitions.
101
112
  * This syntax is not part of the GraphQL specification and may change.
102
113
  * @example
103
- * ```graphql
114
+ * ```graphql prettier-ignore
104
115
  * directive @foo @bar on FIELD
105
116
  * ```
106
117
  */
@@ -134,7 +145,7 @@ export interface ParseOptions {
134
145
  *
135
146
  * const document = parse('fragment A($var: Boolean) on Query { field }', {
136
147
  * allowLegacyFragmentVariables: true,
137
- * maxTokens: 20,
148
+ * maxLexicalTokens: 20,
138
149
  * noLocation: true,
139
150
  * });
140
151
  * const directiveDocument = parse('directive @foo @bar on FIELD', {
@@ -720,15 +731,18 @@ export declare class Parser {
720
731
  * @returns Parsed schema coordinate AST.
721
732
  * @example
722
733
  * ```ts
723
- * import { Parser, Source } from 'graphql/language';
734
+ * import assert from 'node:assert/strict';
735
+ * import { Kind, parseSchemaCoordinate } from 'graphql/language';
724
736
  *
725
- * const typeCoordinate = new Parser(new Source('User.name')).parseSchemaCoordinate();
726
- * const directiveCoordinate = new Parser(new Source('@include(if:)')).parseSchemaCoordinate();
737
+ * const typeCoordinate = parseSchemaCoordinate('User.name');
738
+ * const directiveCoordinate = parseSchemaCoordinate('@include(if:)');
739
+ * assert(typeCoordinate.kind === Kind.MEMBER_COORDINATE);
740
+ * assert(directiveCoordinate.kind === Kind.DIRECTIVE_ARGUMENT_COORDINATE);
727
741
  *
728
742
  * typeCoordinate.name.value; // => 'User'
729
743
  * typeCoordinate.memberName?.value; // => 'name'
730
- * directiveCoordinate.name.value; // => 'deprecated'
731
- * directiveCoordinate.argumentName?.value; // => 'reason'
744
+ * directiveCoordinate.name.value; // => 'include'
745
+ * directiveCoordinate.argumentName?.value; // => 'if'
732
746
  * ```
733
747
  */
734
748
  parseSchemaCoordinate(): SchemaCoordinateNode;
@@ -50,7 +50,7 @@ var _tokenKind = require('./tokenKind.js');
50
50
  *
51
51
  * const document = parse('fragment A($var: Boolean) on Query { field }', {
52
52
  * allowLegacyFragmentVariables: true,
53
- * maxTokens: 20,
53
+ * maxLexicalTokens: 20,
54
54
  * noLocation: true,
55
55
  * });
56
56
  * const directiveDocument = parse('directive @foo @bar on FIELD', {
@@ -216,6 +216,22 @@ class Parser {
216
216
 
217
217
  this._options = _options;
218
218
  this._tokenCounter = 0;
219
+ this._lexer._maxComments =
220
+ options === null || options === void 0 ? void 0 : options.maxComments;
221
+ this._lexer._commentCount = 0;
222
+ const maxSourceLength =
223
+ options === null || options === void 0 ? void 0 : options.maxSourceLength;
224
+
225
+ if (
226
+ maxSourceLength !== undefined &&
227
+ this._lexer.source.body.length > maxSourceLength
228
+ ) {
229
+ throw (0, _syntaxError.syntaxError)(
230
+ this._lexer.source,
231
+ maxSourceLength,
232
+ `Source contains more than ${maxSourceLength} UTF-16 code units. Parsing aborted.`,
233
+ );
234
+ }
219
235
  }
220
236
 
221
237
  get tokenCount() {
@@ -1644,15 +1660,18 @@ class Parser {
1644
1660
  * @returns Parsed schema coordinate AST.
1645
1661
  * @example
1646
1662
  * ```ts
1647
- * import { Parser, Source } from 'graphql/language';
1663
+ * import assert from 'node:assert/strict';
1664
+ * import { Kind, parseSchemaCoordinate } from 'graphql/language';
1648
1665
  *
1649
- * const typeCoordinate = new Parser(new Source('User.name')).parseSchemaCoordinate();
1650
- * const directiveCoordinate = new Parser(new Source('@include(if:)')).parseSchemaCoordinate();
1666
+ * const typeCoordinate = parseSchemaCoordinate('User.name');
1667
+ * const directiveCoordinate = parseSchemaCoordinate('@include(if:)');
1668
+ * assert(typeCoordinate.kind === Kind.MEMBER_COORDINATE);
1669
+ * assert(directiveCoordinate.kind === Kind.DIRECTIVE_ARGUMENT_COORDINATE);
1651
1670
  *
1652
1671
  * typeCoordinate.name.value; // => 'User'
1653
1672
  * typeCoordinate.memberName?.value; // => 'name'
1654
- * directiveCoordinate.name.value; // => 'deprecated'
1655
- * directiveCoordinate.argumentName?.value; // => 'reason'
1673
+ * directiveCoordinate.name.value; // => 'include'
1674
+ * directiveCoordinate.argumentName?.value; // => 'if'
1656
1675
  * ```
1657
1676
  */
1658
1677
 
@@ -1909,18 +1928,21 @@ class Parser {
1909
1928
  }
1910
1929
 
1911
1930
  advanceLexer() {
1912
- const { maxTokens } = this._options;
1931
+ const { maxLexicalTokens = this._options.maxTokens } = this._options;
1913
1932
 
1914
1933
  const token = this._lexer.advance();
1915
1934
 
1916
1935
  if (token.kind !== _tokenKind.TokenKind.EOF) {
1917
1936
  ++this._tokenCounter;
1918
1937
 
1919
- if (maxTokens !== undefined && this._tokenCounter > maxTokens) {
1938
+ if (
1939
+ maxLexicalTokens !== undefined &&
1940
+ this._tokenCounter > maxLexicalTokens
1941
+ ) {
1920
1942
  throw (0, _syntaxError.syntaxError)(
1921
1943
  this._lexer.source,
1922
1944
  token.start,
1923
- `Document contains more that ${maxTokens} tokens. Parsing aborted.`,
1945
+ `Document contains more that ${maxLexicalTokens} tokens. Parsing aborted.`,
1924
1946
  );
1925
1947
  }
1926
1948
  }
@@ -31,7 +31,7 @@ import { TokenKind } from './tokenKind.mjs';
31
31
  *
32
32
  * const document = parse('fragment A($var: Boolean) on Query { field }', {
33
33
  * allowLegacyFragmentVariables: true,
34
- * maxTokens: 20,
34
+ * maxLexicalTokens: 20,
35
35
  * noLocation: true,
36
36
  * });
37
37
  * const directiveDocument = parse('directive @foo @bar on FIELD', {
@@ -193,6 +193,22 @@ export class Parser {
193
193
 
194
194
  this._options = _options;
195
195
  this._tokenCounter = 0;
196
+ this._lexer._maxComments =
197
+ options === null || options === void 0 ? void 0 : options.maxComments;
198
+ this._lexer._commentCount = 0;
199
+ const maxSourceLength =
200
+ options === null || options === void 0 ? void 0 : options.maxSourceLength;
201
+
202
+ if (
203
+ maxSourceLength !== undefined &&
204
+ this._lexer.source.body.length > maxSourceLength
205
+ ) {
206
+ throw syntaxError(
207
+ this._lexer.source,
208
+ maxSourceLength,
209
+ `Source contains more than ${maxSourceLength} UTF-16 code units. Parsing aborted.`,
210
+ );
211
+ }
196
212
  }
197
213
 
198
214
  get tokenCount() {
@@ -1596,15 +1612,18 @@ export class Parser {
1596
1612
  * @returns Parsed schema coordinate AST.
1597
1613
  * @example
1598
1614
  * ```ts
1599
- * import { Parser, Source } from 'graphql/language';
1615
+ * import assert from 'node:assert/strict';
1616
+ * import { Kind, parseSchemaCoordinate } from 'graphql/language';
1600
1617
  *
1601
- * const typeCoordinate = new Parser(new Source('User.name')).parseSchemaCoordinate();
1602
- * const directiveCoordinate = new Parser(new Source('@include(if:)')).parseSchemaCoordinate();
1618
+ * const typeCoordinate = parseSchemaCoordinate('User.name');
1619
+ * const directiveCoordinate = parseSchemaCoordinate('@include(if:)');
1620
+ * assert(typeCoordinate.kind === Kind.MEMBER_COORDINATE);
1621
+ * assert(directiveCoordinate.kind === Kind.DIRECTIVE_ARGUMENT_COORDINATE);
1603
1622
  *
1604
1623
  * typeCoordinate.name.value; // => 'User'
1605
1624
  * typeCoordinate.memberName?.value; // => 'name'
1606
- * directiveCoordinate.name.value; // => 'deprecated'
1607
- * directiveCoordinate.argumentName?.value; // => 'reason'
1625
+ * directiveCoordinate.name.value; // => 'include'
1626
+ * directiveCoordinate.argumentName?.value; // => 'if'
1608
1627
  * ```
1609
1628
  */
1610
1629
 
@@ -1861,18 +1880,21 @@ export class Parser {
1861
1880
  }
1862
1881
 
1863
1882
  advanceLexer() {
1864
- const { maxTokens } = this._options;
1883
+ const { maxLexicalTokens = this._options.maxTokens } = this._options;
1865
1884
 
1866
1885
  const token = this._lexer.advance();
1867
1886
 
1868
1887
  if (token.kind !== TokenKind.EOF) {
1869
1888
  ++this._tokenCounter;
1870
1889
 
1871
- if (maxTokens !== undefined && this._tokenCounter > maxTokens) {
1890
+ if (
1891
+ maxLexicalTokens !== undefined &&
1892
+ this._tokenCounter > maxLexicalTokens
1893
+ ) {
1872
1894
  throw syntaxError(
1873
1895
  this._lexer.source,
1874
1896
  token.start,
1875
- `Document contains more that ${maxTokens} tokens. Parsing aborted.`,
1897
+ `Document contains more that ${maxLexicalTokens} tokens. Parsing aborted.`,
1876
1898
  );
1877
1899
  }
1878
1900
  }
@@ -54,8 +54,11 @@ export declare function isExecutableDefinitionNode(
54
54
  * ```ts
55
55
  * import { Kind, isSelectionNode } from 'graphql/language';
56
56
  *
57
- * const field = { kind: Kind.FIELD, name: { kind: Kind.NAME, value: 'hello' } };
58
- * const document = { kind: Kind.DOCUMENT, definitions: [] };
57
+ * const field = {
58
+ * kind: Kind.FIELD,
59
+ * name: { kind: Kind.NAME, value: 'hello' },
60
+ * } as const;
61
+ * const document = { kind: Kind.DOCUMENT, definitions: [] } as const;
59
62
  *
60
63
  * isSelectionNode(field); // => true
61
64
  * isSelectionNode(document); // => false
@@ -84,7 +87,11 @@ export declare function isValueNode(node: ASTNode): node is ValueNode;
84
87
  * @returns True when the AST node is a constant value node.
85
88
  * @example
86
89
  * ```ts
87
- * import { parseConstValue, parseValue, isConstValueNode } from 'graphql/language';
90
+ * import {
91
+ * parseConstValue,
92
+ * parseValue,
93
+ * isConstValueNode,
94
+ * } from 'graphql/language';
88
95
  *
89
96
  * const value = parseConstValue('[42]');
90
97
  * const variable = parseValue('$id');
@@ -70,8 +70,11 @@ function isExecutableDefinitionNode(node) {
70
70
  * ```ts
71
71
  * import { Kind, isSelectionNode } from 'graphql/language';
72
72
  *
73
- * const field = { kind: Kind.FIELD, name: { kind: Kind.NAME, value: 'hello' } };
74
- * const document = { kind: Kind.DOCUMENT, definitions: [] };
73
+ * const field = {
74
+ * kind: Kind.FIELD,
75
+ * name: { kind: Kind.NAME, value: 'hello' },
76
+ * } as const;
77
+ * const document = { kind: Kind.DOCUMENT, definitions: [] } as const;
75
78
  *
76
79
  * isSelectionNode(field); // => true
77
80
  * isSelectionNode(document); // => false
@@ -120,7 +123,11 @@ function isValueNode(node) {
120
123
  * @returns True when the AST node is a constant value node.
121
124
  * @example
122
125
  * ```ts
123
- * import { parseConstValue, parseValue, isConstValueNode } from 'graphql/language';
126
+ * import {
127
+ * parseConstValue,
128
+ * parseValue,
129
+ * isConstValueNode,
130
+ * } from 'graphql/language';
124
131
  *
125
132
  * const value = parseConstValue('[42]');
126
133
  * const variable = parseValue('$id');
@@ -52,8 +52,11 @@ export function isExecutableDefinitionNode(node) {
52
52
  * ```ts
53
53
  * import { Kind, isSelectionNode } from 'graphql/language';
54
54
  *
55
- * const field = { kind: Kind.FIELD, name: { kind: Kind.NAME, value: 'hello' } };
56
- * const document = { kind: Kind.DOCUMENT, definitions: [] };
55
+ * const field = {
56
+ * kind: Kind.FIELD,
57
+ * name: { kind: Kind.NAME, value: 'hello' },
58
+ * } as const;
59
+ * const document = { kind: Kind.DOCUMENT, definitions: [] } as const;
57
60
  *
58
61
  * isSelectionNode(field); // => true
59
62
  * isSelectionNode(document); // => false
@@ -102,7 +105,11 @@ export function isValueNode(node) {
102
105
  * @returns True when the AST node is a constant value node.
103
106
  * @example
104
107
  * ```ts
105
- * import { parseConstValue, parseValue, isConstValueNode } from 'graphql/language';
108
+ * import {
109
+ * parseConstValue,
110
+ * parseValue,
111
+ * isConstValueNode,
112
+ * } from 'graphql/language';
106
113
  *
107
114
  * const value = parseConstValue('[42]');
108
115
  * const variable = parseValue('$id');
@@ -14,9 +14,7 @@ import type { Source } from './source';
14
14
  * const location = document.definitions[0].loc;
15
15
  *
16
16
  * if (location) {
17
- * const printed = printLocation(location);
18
- *
19
- * printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
17
+ * const printed = printLocation(location); // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
20
18
  * }
21
19
  * ```
22
20
  */
@@ -31,9 +29,7 @@ export declare function printLocation(location: Location): string;
31
29
  * import { Source, printSourceLocation } from 'graphql/language';
32
30
  *
33
31
  * const source = new Source('type Query { hello: String }');
34
- * const printed = printSourceLocation(source, { line: 1, column: 14 });
35
- *
36
- * printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
32
+ * const printed = printSourceLocation(source, { line: 1, column: 14 }); // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
37
33
  * ```
38
34
  */
39
35
  export declare function printSourceLocation(
@@ -22,9 +22,7 @@ var _location = require('./location.js');
22
22
  * const location = document.definitions[0].loc;
23
23
  *
24
24
  * if (location) {
25
- * const printed = printLocation(location);
26
- *
27
- * printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
25
+ * const printed = printLocation(location); // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
28
26
  * }
29
27
  * ```
30
28
  */
@@ -44,9 +42,7 @@ function printLocation(location) {
44
42
  * import { Source, printSourceLocation } from 'graphql/language';
45
43
  *
46
44
  * const source = new Source('type Query { hello: String }');
47
- * const printed = printSourceLocation(source, { line: 1, column: 14 });
48
- *
49
- * printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
45
+ * const printed = printSourceLocation(source, { line: 1, column: 14 }); // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
50
46
  * ```
51
47
  */
52
48
 
@@ -13,9 +13,7 @@ import { getLocation } from './location.mjs';
13
13
  * const location = document.definitions[0].loc;
14
14
  *
15
15
  * if (location) {
16
- * const printed = printLocation(location);
17
- *
18
- * printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
16
+ * const printed = printLocation(location); // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n | ^'
19
17
  * }
20
18
  * ```
21
19
  */
@@ -35,9 +33,7 @@ export function printLocation(location) {
35
33
  * import { Source, printSourceLocation } from 'graphql/language';
36
34
  *
37
35
  * const source = new Source('type Query { hello: String }');
38
- * const printed = printSourceLocation(source, { line: 1, column: 14 });
39
- *
40
- * printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
36
+ * const printed = printSourceLocation(source, { line: 1, column: 14 }); // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n | ^'
41
37
  * ```
42
38
  */
43
39
 
@@ -1,5 +1,23 @@
1
1
  /** @category Printing */
2
2
  import type { ASTNode } from './ast';
3
+ interface PrintOptions {
4
+ /** Maximum indentation depth. Defaults to Infinity. */
5
+ maxIndentDepth?: number;
6
+ }
7
+ /**
8
+ * Prints an AST with indentation and inserted newlines disabled at the given depth.
9
+ * @param ast - The GraphQL AST node to print.
10
+ * @param options - Output configuration.
11
+ * Indentation depth defaults to `Infinity`.
12
+ * @returns A string representation of the AST.
13
+ * @example
14
+ * ```ts
15
+ * import { parse, print } from 'graphql/language';
16
+ *
17
+ * print(parse('{ a { b } }'), { maxIndentDepth: 0 }); // => '{ a { b } }'
18
+ * ```
19
+ */
20
+ export declare function print(ast: ASTNode, options: PrintOptions): string;
3
21
  /**
4
22
  * Converts an AST into a string, using one set of reasonable
5
23
  * formatting rules.
@@ -10,9 +28,10 @@ import type { ASTNode } from './ast';
10
28
  * import { parse, print } from 'graphql';
11
29
  *
12
30
  * const ast = parse('{ hero { name } }');
13
- * const text = print(ast);
14
- *
15
- * text; // => '{\n hero {\n name\n }\n}'
31
+ * const text = print(ast); // => '{\n hero {\n name\n }\n}'
16
32
  * ```
17
33
  */
18
34
  export declare function print(ast: ASTNode): string;
35
+ /** @internal */
36
+ export declare function printForError(ast: ASTNode): string;
37
+ export {};