graphql 15.3.0 → 15.5.1

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 (337) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +10 -0
  3. package/error/GraphQLError.js +8 -8
  4. package/error/GraphQLError.js.flow +2 -3
  5. package/error/GraphQLError.mjs +2 -2
  6. package/error/formatError.js +1 -1
  7. package/error/formatError.js.flow +0 -1
  8. package/error/index.js +4 -4
  9. package/error/index.js.flow +0 -1
  10. package/error/locatedError.d.ts +2 -2
  11. package/error/locatedError.js +10 -5
  12. package/error/locatedError.js.flow +10 -4
  13. package/error/locatedError.mjs +6 -4
  14. package/error/syntaxError.js +1 -1
  15. package/error/syntaxError.js.flow +0 -1
  16. package/execution/execute.d.ts +0 -15
  17. package/execution/execute.js +104 -104
  18. package/execution/execute.js.flow +119 -133
  19. package/execution/execute.mjs +86 -82
  20. package/execution/index.js +3 -3
  21. package/execution/index.js.flow +0 -1
  22. package/execution/values.js +11 -11
  23. package/execution/values.js.flow +0 -1
  24. package/graphql.js +5 -5
  25. package/graphql.js.flow +0 -1
  26. package/index.d.ts +1 -0
  27. package/index.js +9 -9
  28. package/index.js.flow +0 -1
  29. package/jsutils/ObjMap.js.flow +0 -1
  30. package/jsutils/Path.js.flow +0 -1
  31. package/jsutils/PromiseOrValue.js.flow +0 -1
  32. package/jsutils/defineInspect.js +2 -2
  33. package/jsutils/defineInspect.js.flow +0 -1
  34. package/jsutils/devAssert.js.flow +0 -1
  35. package/jsutils/didYouMean.js.flow +0 -1
  36. package/jsutils/identityFunc.js.flow +0 -1
  37. package/jsutils/inspect.js +1 -2
  38. package/jsutils/inspect.js.flow +10 -8
  39. package/jsutils/inspect.mjs +1 -1
  40. package/jsutils/instanceOf.js +15 -9
  41. package/jsutils/instanceOf.js.flow +13 -7
  42. package/jsutils/instanceOf.mjs +13 -5
  43. package/jsutils/invariant.js.flow +0 -1
  44. package/jsutils/isAsyncIterable.js +13 -0
  45. package/jsutils/isAsyncIterable.js.flow +14 -0
  46. package/jsutils/isAsyncIterable.mjs +10 -0
  47. package/jsutils/isObjectLike.js.flow +0 -1
  48. package/jsutils/isPromise.js.flow +0 -1
  49. package/jsutils/keyMap.js.flow +0 -1
  50. package/jsutils/keyValMap.js.flow +0 -1
  51. package/jsutils/mapValue.js +1 -1
  52. package/jsutils/mapValue.js.flow +0 -1
  53. package/jsutils/memoize3.js +2 -5
  54. package/jsutils/memoize3.js.flow +2 -5
  55. package/jsutils/memoize3.mjs +2 -5
  56. package/jsutils/naturalCompare.js +69 -0
  57. package/jsutils/naturalCompare.js.flow +59 -0
  58. package/jsutils/naturalCompare.mjs +61 -0
  59. package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
  60. package/jsutils/printPathArray.js.flow +0 -1
  61. package/jsutils/promiseForObject.js.flow +0 -1
  62. package/jsutils/promiseReduce.js +1 -1
  63. package/jsutils/promiseReduce.js.flow +0 -1
  64. package/jsutils/safeArrayFrom.js +73 -0
  65. package/jsutils/safeArrayFrom.js.flow +59 -0
  66. package/jsutils/safeArrayFrom.mjs +66 -0
  67. package/jsutils/suggestionList.js +5 -1
  68. package/jsutils/suggestionList.js.flow +3 -2
  69. package/jsutils/suggestionList.mjs +3 -1
  70. package/jsutils/toObjMap.js +1 -1
  71. package/jsutils/toObjMap.js.flow +0 -1
  72. package/language/ast.js +1 -1
  73. package/language/ast.js.flow +0 -1
  74. package/language/blockString.d.ts +1 -1
  75. package/language/blockString.js +53 -32
  76. package/language/blockString.js.flow +51 -36
  77. package/language/blockString.mjs +54 -33
  78. package/language/directiveLocation.js.flow +0 -1
  79. package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
  80. package/language/experimentalOnlineParser/grammar.js +987 -0
  81. package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
  82. package/language/experimentalOnlineParser/grammar.mjs +980 -0
  83. package/language/experimentalOnlineParser/index.d.ts +6 -0
  84. package/language/experimentalOnlineParser/index.js +31 -0
  85. package/language/experimentalOnlineParser/index.js.flow +7 -0
  86. package/language/experimentalOnlineParser/index.mjs +1 -0
  87. package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
  88. package/language/experimentalOnlineParser/onlineParser.js +604 -0
  89. package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
  90. package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
  91. package/language/index.js +12 -12
  92. package/language/index.js.flow +0 -1
  93. package/language/kinds.js.flow +0 -1
  94. package/language/lexer.js +242 -183
  95. package/language/lexer.js.flow +188 -184
  96. package/language/lexer.mjs +238 -179
  97. package/language/location.js.flow +0 -1
  98. package/language/parser.js +73 -68
  99. package/language/parser.js.flow +62 -57
  100. package/language/parser.mjs +64 -60
  101. package/language/predicates.js +1 -1
  102. package/language/predicates.js.flow +0 -1
  103. package/language/printLocation.js +1 -1
  104. package/language/printLocation.js.flow +0 -1
  105. package/language/printer.js +20 -13
  106. package/language/printer.js.flow +26 -25
  107. package/language/printer.mjs +18 -11
  108. package/language/source.d.ts +7 -0
  109. package/language/source.js +20 -3
  110. package/language/source.js.flow +21 -3
  111. package/language/source.mjs +14 -1
  112. package/language/tokenKind.js.flow +0 -1
  113. package/language/visitor.js +2 -2
  114. package/language/visitor.js.flow +0 -1
  115. package/package.json +2 -3
  116. package/polyfills/arrayFrom.js +2 -2
  117. package/polyfills/arrayFrom.js.flow +1 -2
  118. package/polyfills/arrayFrom.mjs +1 -1
  119. package/polyfills/find.js +1 -1
  120. package/polyfills/find.js.flow +1 -2
  121. package/polyfills/find.mjs +1 -1
  122. package/polyfills/isFinite.js +1 -1
  123. package/polyfills/isFinite.js.flow +1 -2
  124. package/polyfills/isFinite.mjs +1 -1
  125. package/polyfills/isInteger.js +1 -1
  126. package/polyfills/isInteger.js.flow +1 -2
  127. package/polyfills/isInteger.mjs +1 -1
  128. package/polyfills/objectEntries.js +1 -1
  129. package/polyfills/objectEntries.js.flow +1 -2
  130. package/polyfills/objectEntries.mjs +1 -1
  131. package/polyfills/objectValues.js +1 -1
  132. package/polyfills/objectValues.js.flow +1 -2
  133. package/polyfills/objectValues.mjs +1 -1
  134. package/polyfills/symbols.js +3 -5
  135. package/polyfills/symbols.js.flow +9 -6
  136. package/polyfills/symbols.mjs +3 -5
  137. package/subscription/index.js +1 -1
  138. package/subscription/index.js.flow +0 -1
  139. package/subscription/mapAsyncIterator.js +2 -2
  140. package/subscription/mapAsyncIterator.js.flow +8 -9
  141. package/subscription/mapAsyncIterator.mjs +1 -1
  142. package/subscription/subscribe.js +61 -73
  143. package/subscription/subscribe.js.flow +71 -85
  144. package/subscription/subscribe.mjs +53 -65
  145. package/type/definition.d.ts +16 -6
  146. package/type/definition.js +37 -32
  147. package/type/definition.js.flow +93 -63
  148. package/type/definition.mjs +19 -14
  149. package/type/directives.js +17 -16
  150. package/type/directives.js.flow +20 -13
  151. package/type/directives.mjs +6 -5
  152. package/type/index.js +6 -6
  153. package/type/index.js.flow +0 -1
  154. package/type/introspection.js +86 -65
  155. package/type/introspection.js.flow +75 -43
  156. package/type/introspection.mjs +79 -58
  157. package/type/scalars.js +9 -9
  158. package/type/scalars.js.flow +1 -2
  159. package/type/scalars.mjs +1 -1
  160. package/type/schema.js +13 -13
  161. package/type/schema.js.flow +2 -3
  162. package/type/schema.mjs +1 -1
  163. package/type/validate.js +52 -19
  164. package/type/validate.js.flow +54 -8
  165. package/type/validate.mjs +43 -9
  166. package/utilities/TypeInfo.js +7 -7
  167. package/utilities/TypeInfo.js.flow +1 -2
  168. package/utilities/assertValidName.js +2 -2
  169. package/utilities/assertValidName.js.flow +0 -1
  170. package/utilities/astFromValue.js +14 -16
  171. package/utilities/astFromValue.js.flow +6 -7
  172. package/utilities/astFromValue.mjs +6 -7
  173. package/utilities/buildASTSchema.js +17 -27
  174. package/utilities/buildASTSchema.js.flow +5 -21
  175. package/utilities/buildASTSchema.mjs +11 -21
  176. package/utilities/buildClientSchema.js +16 -15
  177. package/utilities/buildClientSchema.js.flow +28 -12
  178. package/utilities/buildClientSchema.mjs +5 -4
  179. package/utilities/coerceInputValue.js +17 -18
  180. package/utilities/coerceInputValue.js.flow +12 -10
  181. package/utilities/coerceInputValue.mjs +7 -7
  182. package/utilities/concatAST.js +9 -8
  183. package/utilities/concatAST.js.flow +8 -8
  184. package/utilities/concatAST.mjs +9 -6
  185. package/utilities/extendSchema.js +26 -19
  186. package/utilities/extendSchema.js.flow +19 -7
  187. package/utilities/extendSchema.mjs +8 -1
  188. package/utilities/findBreakingChanges.js +15 -11
  189. package/utilities/findBreakingChanges.js.flow +6 -3
  190. package/utilities/findBreakingChanges.mjs +5 -2
  191. package/utilities/findDeprecatedUsages.js +2 -2
  192. package/utilities/findDeprecatedUsages.js.flow +0 -1
  193. package/utilities/getIntrospectionQuery.d.ts +6 -0
  194. package/utilities/getIntrospectionQuery.js +8 -2
  195. package/utilities/getIntrospectionQuery.js.flow +17 -5
  196. package/utilities/getIntrospectionQuery.mjs +8 -2
  197. package/utilities/getOperationAST.js +1 -1
  198. package/utilities/getOperationAST.js.flow +0 -1
  199. package/utilities/getOperationRootType.js +1 -1
  200. package/utilities/getOperationRootType.js.flow +0 -1
  201. package/utilities/index.d.ts +3 -0
  202. package/utilities/index.js +22 -22
  203. package/utilities/index.js.flow +0 -1
  204. package/utilities/introspectionFromSchema.js +7 -5
  205. package/utilities/introspectionFromSchema.js.flow +2 -1
  206. package/utilities/introspectionFromSchema.mjs +3 -1
  207. package/utilities/lexicographicSortSchema.js +13 -9
  208. package/utilities/lexicographicSortSchema.js.flow +21 -13
  209. package/utilities/lexicographicSortSchema.mjs +5 -2
  210. package/utilities/printSchema.js +15 -16
  211. package/utilities/printSchema.js.flow +23 -16
  212. package/utilities/printSchema.mjs +5 -6
  213. package/utilities/separateOperations.js +46 -42
  214. package/utilities/separateOperations.js.flow +46 -37
  215. package/utilities/separateOperations.mjs +44 -40
  216. package/utilities/stripIgnoredCharacters.js +6 -16
  217. package/utilities/stripIgnoredCharacters.js.flow +4 -13
  218. package/utilities/stripIgnoredCharacters.mjs +3 -10
  219. package/utilities/typeComparators.js +1 -1
  220. package/utilities/typeComparators.js.flow +0 -1
  221. package/utilities/typeFromAST.js +6 -6
  222. package/utilities/typeFromAST.js.flow +2 -3
  223. package/utilities/typeFromAST.mjs +2 -2
  224. package/utilities/typedQueryDocumentNode.d.ts +20 -0
  225. package/utilities/valueFromAST.js +6 -6
  226. package/utilities/valueFromAST.js.flow +4 -2
  227. package/utilities/valueFromASTUntyped.js +4 -4
  228. package/utilities/valueFromASTUntyped.js.flow +0 -1
  229. package/validation/ValidationContext.js +3 -3
  230. package/validation/ValidationContext.js.flow +3 -4
  231. package/validation/index.js +38 -38
  232. package/validation/index.js.flow +0 -1
  233. package/validation/rules/ExecutableDefinitions.js +1 -1
  234. package/validation/rules/ExecutableDefinitions.js.flow +0 -1
  235. package/validation/rules/ExecutableDefinitionsRule.js +3 -3
  236. package/validation/rules/ExecutableDefinitionsRule.js.flow +0 -1
  237. package/validation/rules/FieldsOnCorrectTypeRule.js +8 -6
  238. package/validation/rules/FieldsOnCorrectTypeRule.js.flow +2 -2
  239. package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -1
  240. package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
  241. package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +0 -1
  242. package/validation/rules/KnownArgumentNamesRule.js +5 -5
  243. package/validation/rules/KnownArgumentNamesRule.js.flow +1 -1
  244. package/validation/rules/KnownDirectivesRule.js +6 -6
  245. package/validation/rules/KnownDirectivesRule.js.flow +4 -3
  246. package/validation/rules/KnownFragmentNamesRule.js +1 -1
  247. package/validation/rules/KnownFragmentNamesRule.js.flow +0 -1
  248. package/validation/rules/KnownTypeNamesRule.js +6 -6
  249. package/validation/rules/KnownTypeNamesRule.js.flow +1 -2
  250. package/validation/rules/LoneAnonymousOperationRule.js +2 -2
  251. package/validation/rules/LoneAnonymousOperationRule.js.flow +0 -1
  252. package/validation/rules/LoneSchemaDefinition.js +1 -1
  253. package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
  254. package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
  255. package/validation/rules/LoneSchemaDefinitionRule.js.flow +0 -1
  256. package/validation/rules/NoFragmentCyclesRule.js +1 -1
  257. package/validation/rules/NoFragmentCyclesRule.js.flow +1 -2
  258. package/validation/rules/NoUndefinedVariablesRule.js +1 -1
  259. package/validation/rules/NoUndefinedVariablesRule.js.flow +0 -1
  260. package/validation/rules/NoUnusedFragmentsRule.js +1 -1
  261. package/validation/rules/NoUnusedFragmentsRule.js.flow +0 -1
  262. package/validation/rules/NoUnusedVariablesRule.js +1 -1
  263. package/validation/rules/NoUnusedVariablesRule.js.flow +0 -1
  264. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
  265. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +14 -14
  266. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
  267. package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
  268. package/validation/rules/PossibleFragmentSpreadsRule.js.flow +5 -2
  269. package/validation/rules/PossibleTypeExtensions.js +1 -1
  270. package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
  271. package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
  272. package/validation/rules/PossibleTypeExtensionsRule.js.flow +6 -4
  273. package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
  274. package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +4 -3
  275. package/validation/rules/ScalarLeafsRule.js +3 -3
  276. package/validation/rules/ScalarLeafsRule.js.flow +0 -1
  277. package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
  278. package/validation/rules/SingleFieldSubscriptionsRule.js.flow +0 -1
  279. package/validation/rules/UniqueArgumentNamesRule.js +1 -1
  280. package/validation/rules/UniqueArgumentNamesRule.js.flow +0 -1
  281. package/validation/rules/UniqueDirectiveNames.js +1 -1
  282. package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
  283. package/validation/rules/UniqueDirectiveNamesRule.js +2 -2
  284. package/validation/rules/UniqueDirectiveNamesRule.js.flow +0 -1
  285. package/validation/rules/UniqueDirectiveNamesRule.mjs +1 -1
  286. package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
  287. package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +0 -1
  288. package/validation/rules/UniqueEnumValueNames.js +1 -1
  289. package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
  290. package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
  291. package/validation/rules/UniqueEnumValueNamesRule.js.flow +7 -2
  292. package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
  293. package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
  294. package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
  295. package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +13 -4
  296. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
  297. package/validation/rules/UniqueFragmentNamesRule.js +1 -1
  298. package/validation/rules/UniqueFragmentNamesRule.js.flow +0 -1
  299. package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
  300. package/validation/rules/UniqueInputFieldNamesRule.js.flow +0 -1
  301. package/validation/rules/UniqueOperationNamesRule.js +1 -1
  302. package/validation/rules/UniqueOperationNamesRule.js.flow +0 -1
  303. package/validation/rules/UniqueOperationTypes.js +1 -1
  304. package/validation/rules/UniqueOperationTypes.js.flow +0 -1
  305. package/validation/rules/UniqueOperationTypesRule.js +1 -1
  306. package/validation/rules/UniqueOperationTypesRule.js.flow +7 -2
  307. package/validation/rules/UniqueTypeNames.js +1 -1
  308. package/validation/rules/UniqueTypeNames.js.flow +0 -1
  309. package/validation/rules/UniqueTypeNamesRule.js +2 -2
  310. package/validation/rules/UniqueTypeNamesRule.js.flow +0 -1
  311. package/validation/rules/UniqueTypeNamesRule.mjs +1 -1
  312. package/validation/rules/UniqueVariableNamesRule.js +1 -1
  313. package/validation/rules/UniqueVariableNamesRule.js.flow +0 -1
  314. package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
  315. package/validation/rules/ValuesOfCorrectTypeRule.js.flow +0 -1
  316. package/validation/rules/VariablesAreInputTypesRule.js +4 -4
  317. package/validation/rules/VariablesAreInputTypesRule.js.flow +0 -1
  318. package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
  319. package/validation/rules/VariablesInAllowedPositionRule.js.flow +0 -1
  320. package/validation/rules/custom/NoDeprecatedCustomRule.js +47 -9
  321. package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +56 -13
  322. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +43 -8
  323. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +3 -3
  324. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +0 -1
  325. package/validation/specifiedRules.js +33 -33
  326. package/validation/specifiedRules.js.flow +0 -1
  327. package/validation/validate.js +7 -7
  328. package/validation/validate.js.flow +4 -5
  329. package/version.js +3 -3
  330. package/version.js.flow +3 -4
  331. package/version.mjs +3 -3
  332. package/jsutils/isCollection.js +0 -47
  333. package/jsutils/isCollection.js.flow +0 -39
  334. package/jsutils/isCollection.mjs +0 -40
  335. package/polyfills/flatMap.js +0 -30
  336. package/polyfills/flatMap.js.flow +0 -28
  337. package/polyfills/flatMap.mjs +0 -23
@@ -6,26 +6,21 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.parse = parse;
7
7
  exports.parseValue = parseValue;
8
8
  exports.parseType = parseType;
9
+ exports.Parser = void 0;
9
10
 
10
- var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
11
+ var _syntaxError = require("../error/syntaxError.js");
11
12
 
12
- var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
13
+ var _kinds = require("./kinds.js");
13
14
 
14
- var _syntaxError = require("../error/syntaxError");
15
+ var _ast = require("./ast.js");
15
16
 
16
- var _kinds = require("./kinds");
17
+ var _tokenKind = require("./tokenKind.js");
17
18
 
18
- var _ast = require("./ast");
19
+ var _source = require("./source.js");
19
20
 
20
- var _source = require("./source");
21
+ var _directiveLocation = require("./directiveLocation.js");
21
22
 
22
- var _tokenKind = require("./tokenKind");
23
-
24
- var _directiveLocation = require("./directiveLocation");
25
-
26
- var _lexer = require("./lexer");
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+ var _lexer = require("./lexer.js");
29
24
 
30
25
  /**
31
26
  * Given a GraphQL source, parses it into a Document.
@@ -73,11 +68,22 @@ function parseType(source, options) {
73
68
  parser.expectToken(_tokenKind.TokenKind.EOF);
74
69
  return type;
75
70
  }
71
+ /**
72
+ * This class is exported only to assist people in implementing their own parsers
73
+ * without duplicating too much code and should be used only as last resort for cases
74
+ * such as experimental syntax or if certain features could not be contributed upstream.
75
+ *
76
+ * It is still part of the internal API and is versioned, so any changes to it are never
77
+ * considered breaking changes. If you still need to support multiple versions of the
78
+ * library, please use the `versionInfo` variable for version detection.
79
+ *
80
+ * @internal
81
+ */
82
+
76
83
 
77
84
  var Parser = /*#__PURE__*/function () {
78
85
  function Parser(source, options) {
79
- var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
80
- sourceObj instanceof _source.Source || (0, _devAssert.default)(0, "Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj), "."));
86
+ var sourceObj = (0, _source.isSource)(source) ? source : new _source.Source(source);
81
87
  this._lexer = new _lexer.Lexer(sourceObj);
82
88
  this._options = options;
83
89
  }
@@ -822,21 +828,25 @@ var Parser = /*#__PURE__*/function () {
822
828
  ;
823
829
 
824
830
  _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
825
- var types = [];
831
+ var _this$_options2;
832
+
833
+ if (!this.expectOptionalKeyword('implements')) {
834
+ return [];
835
+ }
836
+
837
+ if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
838
+ var types = []; // Optional leading ampersand
826
839
 
827
- if (this.expectOptionalKeyword('implements')) {
828
- // Optional leading ampersand
829
840
  this.expectOptionalToken(_tokenKind.TokenKind.AMP);
830
841
 
831
842
  do {
832
- var _this$_options2;
833
-
834
843
  types.push(this.parseNamedType());
835
- } while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) || // Legacy support for the SDL?
836
- ((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true && this.peek(_tokenKind.TokenKind.NAME));
844
+ } while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) || this.peek(_tokenKind.TokenKind.NAME));
845
+
846
+ return types;
837
847
  }
838
848
 
839
- return types;
849
+ return this.delimitedMany(_tokenKind.TokenKind.AMP, this.parseNamedType);
840
850
  }
841
851
  /**
842
852
  * FieldsDefinition : { FieldDefinition+ }
@@ -972,18 +982,7 @@ var Parser = /*#__PURE__*/function () {
972
982
  ;
973
983
 
974
984
  _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
975
- var types = [];
976
-
977
- if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
978
- // Optional leading pipe
979
- this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
980
-
981
- do {
982
- types.push(this.parseNamedType());
983
- } while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
984
- }
985
-
986
- return types;
985
+ return this.expectOptionalToken(_tokenKind.TokenKind.EQUALS) ? this.delimitedMany(_tokenKind.TokenKind.PIPE, this.parseNamedType) : [];
987
986
  }
988
987
  /**
989
988
  * EnumTypeDefinition :
@@ -1334,15 +1333,7 @@ var Parser = /*#__PURE__*/function () {
1334
1333
  ;
1335
1334
 
1336
1335
  _proto.parseDirectiveLocations = function parseDirectiveLocations() {
1337
- // Optional leading pipe
1338
- this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
1339
- var locations = [];
1340
-
1341
- do {
1342
- locations.push(this.parseDirectiveLocation());
1343
- } while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
1344
-
1345
- return locations;
1336
+ return this.delimitedMany(_tokenKind.TokenKind.PIPE, this.parseDirectiveLocation);
1346
1337
  }
1347
1338
  /*
1348
1339
  * DirectiveLocation :
@@ -1385,8 +1376,7 @@ var Parser = /*#__PURE__*/function () {
1385
1376
  } // Core parsing utility functions
1386
1377
 
1387
1378
  /**
1388
- * Returns a location object, used to identify the place in
1389
- * the source that created a given parsed object.
1379
+ * Returns a location object, used to identify the place in the source that created a given parsed object.
1390
1380
  */
1391
1381
  ;
1392
1382
 
@@ -1406,8 +1396,8 @@ var Parser = /*#__PURE__*/function () {
1406
1396
  return this._lexer.token.kind === kind;
1407
1397
  }
1408
1398
  /**
1409
- * If the next token is of the given kind, return that token after advancing
1410
- * the lexer. Otherwise, do not change the parser state and throw an error.
1399
+ * If the next token is of the given kind, return that token after advancing the lexer.
1400
+ * Otherwise, do not change the parser state and throw an error.
1411
1401
  */
1412
1402
  ;
1413
1403
 
@@ -1423,8 +1413,8 @@ var Parser = /*#__PURE__*/function () {
1423
1413
  throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
1424
1414
  }
1425
1415
  /**
1426
- * If the next token is of the given kind, return that token after advancing
1427
- * the lexer. Otherwise, do not change the parser state and return undefined.
1416
+ * If the next token is of the given kind, return that token after advancing the lexer.
1417
+ * Otherwise, do not change the parser state and return undefined.
1428
1418
  */
1429
1419
  ;
1430
1420
 
@@ -1455,8 +1445,8 @@ var Parser = /*#__PURE__*/function () {
1455
1445
  }
1456
1446
  }
1457
1447
  /**
1458
- * If the next token is a given keyword, return "true" after advancing
1459
- * the lexer. Otherwise, do not change the parser state and return "false".
1448
+ * If the next token is a given keyword, return "true" after advancing the lexer.
1449
+ * Otherwise, do not change the parser state and return "false".
1460
1450
  */
1461
1451
  ;
1462
1452
 
@@ -1472,8 +1462,7 @@ var Parser = /*#__PURE__*/function () {
1472
1462
  return false;
1473
1463
  }
1474
1464
  /**
1475
- * Helper function for creating an error when an unexpected lexed token
1476
- * is encountered.
1465
+ * Helper function for creating an error when an unexpected lexed token is encountered.
1477
1466
  */
1478
1467
  ;
1479
1468
 
@@ -1482,10 +1471,9 @@ var Parser = /*#__PURE__*/function () {
1482
1471
  return (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token), "."));
1483
1472
  }
1484
1473
  /**
1485
- * Returns a possibly empty list of parse nodes, determined by
1486
- * the parseFn. This list begins with a lex token of openKind
1487
- * and ends with a lex token of closeKind. Advances the parser
1488
- * to the next lex token after the closing token.
1474
+ * Returns a possibly empty list of parse nodes, determined by the parseFn.
1475
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
1476
+ * Advances the parser to the next lex token after the closing token.
1489
1477
  */
1490
1478
  ;
1491
1479
 
@@ -1501,10 +1489,9 @@ var Parser = /*#__PURE__*/function () {
1501
1489
  }
1502
1490
  /**
1503
1491
  * Returns a list of parse nodes, determined by the parseFn.
1504
- * It can be empty only if open token is missing otherwise it will always
1505
- * return non-empty list that begins with a lex token of openKind and ends
1506
- * with a lex token of closeKind. Advances the parser to the next lex token
1507
- * after the closing token.
1492
+ * It can be empty only if open token is missing otherwise it will always return non-empty list
1493
+ * that begins with a lex token of openKind and ends with a lex token of closeKind.
1494
+ * Advances the parser to the next lex token after the closing token.
1508
1495
  */
1509
1496
  ;
1510
1497
 
@@ -1522,10 +1509,9 @@ var Parser = /*#__PURE__*/function () {
1522
1509
  return [];
1523
1510
  }
1524
1511
  /**
1525
- * Returns a non-empty list of parse nodes, determined by
1526
- * the parseFn. This list begins with a lex token of openKind
1527
- * and ends with a lex token of closeKind. Advances the parser
1528
- * to the next lex token after the closing token.
1512
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
1513
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
1514
+ * Advances the parser to the next lex token after the closing token.
1529
1515
  */
1530
1516
  ;
1531
1517
 
@@ -1537,22 +1523,41 @@ var Parser = /*#__PURE__*/function () {
1537
1523
  nodes.push(parseFn.call(this));
1538
1524
  } while (!this.expectOptionalToken(closeKind));
1539
1525
 
1526
+ return nodes;
1527
+ }
1528
+ /**
1529
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
1530
+ * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
1531
+ * Advances the parser to the next lex token after last item in the list.
1532
+ */
1533
+ ;
1534
+
1535
+ _proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {
1536
+ this.expectOptionalToken(delimiterKind);
1537
+ var nodes = [];
1538
+
1539
+ do {
1540
+ nodes.push(parseFn.call(this));
1541
+ } while (this.expectOptionalToken(delimiterKind));
1542
+
1540
1543
  return nodes;
1541
1544
  };
1542
1545
 
1543
1546
  return Parser;
1544
1547
  }();
1545
1548
  /**
1546
- * A helper function to describe a token as a string for debugging
1549
+ * A helper function to describe a token as a string for debugging.
1547
1550
  */
1548
1551
 
1549
1552
 
1553
+ exports.Parser = Parser;
1554
+
1550
1555
  function getTokenDesc(token) {
1551
1556
  var value = token.value;
1552
1557
  return getTokenKindDesc(token.kind) + (value != null ? " \"".concat(value, "\"") : '');
1553
1558
  }
1554
1559
  /**
1555
- * A helper function to describe a token kind as a string for debugging
1560
+ * A helper function to describe a token kind as a string for debugging.
1556
1561
  */
1557
1562
 
1558
1563
 
@@ -1,8 +1,4 @@
1
1
  // @flow strict
2
-
3
- import inspect from '../jsutils/inspect';
4
- import devAssert from '../jsutils/devAssert';
5
-
6
2
  import type { GraphQLError } from '../error/GraphQLError';
7
3
  import { syntaxError } from '../error/syntaxError';
8
4
 
@@ -55,8 +51,8 @@ import type {
55
51
  } from './ast';
56
52
  import { Kind } from './kinds';
57
53
  import { Location } from './ast';
58
- import { Source } from './source';
59
54
  import { TokenKind } from './tokenKind';
55
+ import { Source, isSource } from './source';
60
56
  import { DirectiveLocation } from './directiveLocation';
61
57
  import { Lexer, isPunctuatorTokenKind } from './lexer';
62
58
 
@@ -164,16 +160,23 @@ export function parseType(
164
160
  return type;
165
161
  }
166
162
 
167
- class Parser {
163
+ /**
164
+ * This class is exported only to assist people in implementing their own parsers
165
+ * without duplicating too much code and should be used only as last resort for cases
166
+ * such as experimental syntax or if certain features could not be contributed upstream.
167
+ *
168
+ * It is still part of the internal API and is versioned, so any changes to it are never
169
+ * considered breaking changes. If you still need to support multiple versions of the
170
+ * library, please use the `versionInfo` variable for version detection.
171
+ *
172
+ * @internal
173
+ */
174
+ export class Parser {
168
175
  _options: ?ParseOptions;
169
176
  _lexer: Lexer;
170
177
 
171
178
  constructor(source: string | Source, options?: ParseOptions) {
172
- const sourceObj = typeof source === 'string' ? new Source(source) : source;
173
- devAssert(
174
- sourceObj instanceof Source,
175
- `Must provide Source. Received: ${inspect(sourceObj)}.`,
176
- );
179
+ const sourceObj = isSource(source) ? source : new Source(source);
177
180
 
178
181
  this._lexer = new Lexer(sourceObj);
179
182
  this._options = options;
@@ -853,20 +856,24 @@ class Parser {
853
856
  * - ImplementsInterfaces & NamedType
854
857
  */
855
858
  parseImplementsInterfaces(): Array<NamedTypeNode> {
856
- const types = [];
857
- if (this.expectOptionalKeyword('implements')) {
859
+ if (!this.expectOptionalKeyword('implements')) {
860
+ return [];
861
+ }
862
+
863
+ if (this._options?.allowLegacySDLImplementsInterfaces === true) {
864
+ const types = [];
858
865
  // Optional leading ampersand
859
866
  this.expectOptionalToken(TokenKind.AMP);
860
867
  do {
861
868
  types.push(this.parseNamedType());
862
869
  } while (
863
870
  this.expectOptionalToken(TokenKind.AMP) ||
864
- // Legacy support for the SDL?
865
- (this._options?.allowLegacySDLImplementsInterfaces === true &&
866
- this.peek(TokenKind.NAME))
871
+ this.peek(TokenKind.NAME)
867
872
  );
873
+ return types;
868
874
  }
869
- return types;
875
+
876
+ return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
870
877
  }
871
878
 
872
879
  /**
@@ -1000,15 +1007,9 @@ class Parser {
1000
1007
  * - UnionMemberTypes | NamedType
1001
1008
  */
1002
1009
  parseUnionMemberTypes(): Array<NamedTypeNode> {
1003
- const types = [];
1004
- if (this.expectOptionalToken(TokenKind.EQUALS)) {
1005
- // Optional leading pipe
1006
- this.expectOptionalToken(TokenKind.PIPE);
1007
- do {
1008
- types.push(this.parseNamedType());
1009
- } while (this.expectOptionalToken(TokenKind.PIPE));
1010
- }
1011
- return types;
1010
+ return this.expectOptionalToken(TokenKind.EQUALS)
1011
+ ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
1012
+ : [];
1012
1013
  }
1013
1014
 
1014
1015
  /**
@@ -1344,13 +1345,7 @@ class Parser {
1344
1345
  * - DirectiveLocations | DirectiveLocation
1345
1346
  */
1346
1347
  parseDirectiveLocations(): Array<NameNode> {
1347
- // Optional leading pipe
1348
- this.expectOptionalToken(TokenKind.PIPE);
1349
- const locations = [];
1350
- do {
1351
- locations.push(this.parseDirectiveLocation());
1352
- } while (this.expectOptionalToken(TokenKind.PIPE));
1353
- return locations;
1348
+ return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
1354
1349
  }
1355
1350
 
1356
1351
  /*
@@ -1392,8 +1387,7 @@ class Parser {
1392
1387
  // Core parsing utility functions
1393
1388
 
1394
1389
  /**
1395
- * Returns a location object, used to identify the place in
1396
- * the source that created a given parsed object.
1390
+ * Returns a location object, used to identify the place in the source that created a given parsed object.
1397
1391
  */
1398
1392
  loc(startToken: Token): Location | void {
1399
1393
  if (this._options?.noLocation !== true) {
@@ -1413,8 +1407,8 @@ class Parser {
1413
1407
  }
1414
1408
 
1415
1409
  /**
1416
- * If the next token is of the given kind, return that token after advancing
1417
- * the lexer. Otherwise, do not change the parser state and throw an error.
1410
+ * If the next token is of the given kind, return that token after advancing the lexer.
1411
+ * Otherwise, do not change the parser state and throw an error.
1418
1412
  */
1419
1413
  expectToken(kind: TokenKindEnum): Token {
1420
1414
  const token = this._lexer.token;
@@ -1431,8 +1425,8 @@ class Parser {
1431
1425
  }
1432
1426
 
1433
1427
  /**
1434
- * If the next token is of the given kind, return that token after advancing
1435
- * the lexer. Otherwise, do not change the parser state and return undefined.
1428
+ * If the next token is of the given kind, return that token after advancing the lexer.
1429
+ * Otherwise, do not change the parser state and return undefined.
1436
1430
  */
1437
1431
  expectOptionalToken(kind: TokenKindEnum): ?Token {
1438
1432
  const token = this._lexer.token;
@@ -1461,8 +1455,8 @@ class Parser {
1461
1455
  }
1462
1456
 
1463
1457
  /**
1464
- * If the next token is a given keyword, return "true" after advancing
1465
- * the lexer. Otherwise, do not change the parser state and return "false".
1458
+ * If the next token is a given keyword, return "true" after advancing the lexer.
1459
+ * Otherwise, do not change the parser state and return "false".
1466
1460
  */
1467
1461
  expectOptionalKeyword(value: string): boolean {
1468
1462
  const token = this._lexer.token;
@@ -1474,8 +1468,7 @@ class Parser {
1474
1468
  }
1475
1469
 
1476
1470
  /**
1477
- * Helper function for creating an error when an unexpected lexed token
1478
- * is encountered.
1471
+ * Helper function for creating an error when an unexpected lexed token is encountered.
1479
1472
  */
1480
1473
  unexpected(atToken?: ?Token): GraphQLError {
1481
1474
  const token = atToken ?? this._lexer.token;
@@ -1487,10 +1480,9 @@ class Parser {
1487
1480
  }
1488
1481
 
1489
1482
  /**
1490
- * Returns a possibly empty list of parse nodes, determined by
1491
- * the parseFn. This list begins with a lex token of openKind
1492
- * and ends with a lex token of closeKind. Advances the parser
1493
- * to the next lex token after the closing token.
1483
+ * Returns a possibly empty list of parse nodes, determined by the parseFn.
1484
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
1485
+ * Advances the parser to the next lex token after the closing token.
1494
1486
  */
1495
1487
  any<T>(
1496
1488
  openKind: TokenKindEnum,
@@ -1507,10 +1499,9 @@ class Parser {
1507
1499
 
1508
1500
  /**
1509
1501
  * Returns a list of parse nodes, determined by the parseFn.
1510
- * It can be empty only if open token is missing otherwise it will always
1511
- * return non-empty list that begins with a lex token of openKind and ends
1512
- * with a lex token of closeKind. Advances the parser to the next lex token
1513
- * after the closing token.
1502
+ * It can be empty only if open token is missing otherwise it will always return non-empty list
1503
+ * that begins with a lex token of openKind and ends with a lex token of closeKind.
1504
+ * Advances the parser to the next lex token after the closing token.
1514
1505
  */
1515
1506
  optionalMany<T>(
1516
1507
  openKind: TokenKindEnum,
@@ -1528,10 +1519,9 @@ class Parser {
1528
1519
  }
1529
1520
 
1530
1521
  /**
1531
- * Returns a non-empty list of parse nodes, determined by
1532
- * the parseFn. This list begins with a lex token of openKind
1533
- * and ends with a lex token of closeKind. Advances the parser
1534
- * to the next lex token after the closing token.
1522
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
1523
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
1524
+ * Advances the parser to the next lex token after the closing token.
1535
1525
  */
1536
1526
  many<T>(
1537
1527
  openKind: TokenKindEnum,
@@ -1545,10 +1535,25 @@ class Parser {
1545
1535
  } while (!this.expectOptionalToken(closeKind));
1546
1536
  return nodes;
1547
1537
  }
1538
+
1539
+ /**
1540
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
1541
+ * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
1542
+ * Advances the parser to the next lex token after last item in the list.
1543
+ */
1544
+ delimitedMany<T>(delimiterKind: TokenKindEnum, parseFn: () => T): Array<T> {
1545
+ this.expectOptionalToken(delimiterKind);
1546
+
1547
+ const nodes = [];
1548
+ do {
1549
+ nodes.push(parseFn.call(this));
1550
+ } while (this.expectOptionalToken(delimiterKind));
1551
+ return nodes;
1552
+ }
1548
1553
  }
1549
1554
 
1550
1555
  /**
1551
- * A helper function to describe a token as a string for debugging
1556
+ * A helper function to describe a token as a string for debugging.
1552
1557
  */
1553
1558
  function getTokenDesc(token: Token): string {
1554
1559
  const value = token.value;
@@ -1556,7 +1561,7 @@ function getTokenDesc(token: Token): string {
1556
1561
  }
1557
1562
 
1558
1563
  /**
1559
- * A helper function to describe a token kind as a string for debugging
1564
+ * A helper function to describe a token kind as a string for debugging.
1560
1565
  */
1561
1566
  function getTokenKindDesc(kind: TokenKindEnum): string {
1562
1567
  return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;