graphql 15.1.0 → 15.4.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 (343) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +10 -12
  3. package/error/GraphQLError.js +5 -5
  4. package/error/GraphQLError.js.flow +5 -5
  5. package/error/GraphQLError.mjs +1 -1
  6. package/error/formatError.js +1 -1
  7. package/error/formatError.js.flow +2 -3
  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 +11 -5
  13. package/error/locatedError.mjs +6 -4
  14. package/error/syntaxError.js +1 -1
  15. package/error/syntaxError.js.flow +1 -2
  16. package/execution/execute.d.ts +24 -16
  17. package/execution/execute.js +123 -105
  18. package/execution/execute.js.flow +169 -153
  19. package/execution/execute.mjs +101 -82
  20. package/execution/index.d.ts +2 -0
  21. package/execution/index.js +9 -3
  22. package/execution/index.js.flow +12 -3
  23. package/execution/index.mjs +1 -1
  24. package/execution/values.js +11 -11
  25. package/execution/values.js.flow +10 -14
  26. package/graphql.js +5 -5
  27. package/graphql.js.flow +9 -9
  28. package/index.d.ts +19 -1
  29. package/index.js +27 -9
  30. package/index.js.flow +10 -3
  31. package/index.mjs +4 -3
  32. package/jsutils/ObjMap.js.flow +0 -1
  33. package/jsutils/Path.d.ts +6 -1
  34. package/jsutils/Path.js +3 -2
  35. package/jsutils/Path.js.flow +3 -2
  36. package/jsutils/Path.mjs +3 -2
  37. package/jsutils/PromiseOrValue.js.flow +0 -1
  38. package/jsutils/defineInspect.js +2 -2
  39. package/jsutils/defineInspect.js.flow +0 -1
  40. package/jsutils/devAssert.js.flow +0 -1
  41. package/jsutils/didYouMean.js.flow +0 -1
  42. package/jsutils/identityFunc.js.flow +0 -1
  43. package/jsutils/inspect.js +1 -2
  44. package/jsutils/inspect.js.flow +10 -8
  45. package/jsutils/inspect.mjs +1 -1
  46. package/jsutils/instanceOf.js.flow +2 -3
  47. package/jsutils/invariant.js.flow +0 -1
  48. package/jsutils/isAsyncIterable.js +19 -0
  49. package/jsutils/isAsyncIterable.js.flow +18 -0
  50. package/jsutils/isAsyncIterable.mjs +16 -0
  51. package/jsutils/isCollection.js +1 -1
  52. package/jsutils/isCollection.js.flow +0 -1
  53. package/jsutils/isObjectLike.js.flow +0 -1
  54. package/jsutils/isPromise.js.flow +0 -1
  55. package/jsutils/keyMap.js.flow +1 -2
  56. package/jsutils/keyValMap.js.flow +1 -2
  57. package/jsutils/mapValue.js +1 -1
  58. package/jsutils/mapValue.js.flow +1 -2
  59. package/jsutils/memoize3.js +2 -5
  60. package/jsutils/memoize3.js.flow +2 -5
  61. package/jsutils/memoize3.mjs +2 -5
  62. package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
  63. package/jsutils/printPathArray.js.flow +0 -1
  64. package/jsutils/promiseForObject.js.flow +1 -2
  65. package/jsutils/promiseReduce.js +1 -1
  66. package/jsutils/promiseReduce.js.flow +1 -1
  67. package/jsutils/promiseReduce.mjs +1 -1
  68. package/jsutils/suggestionList.js.flow +1 -2
  69. package/jsutils/toObjMap.js +1 -1
  70. package/jsutils/toObjMap.js.flow +5 -6
  71. package/language/ast.js +1 -1
  72. package/language/ast.js.flow +2 -3
  73. package/language/blockString.d.ts +1 -1
  74. package/language/blockString.js +53 -32
  75. package/language/blockString.js.flow +49 -34
  76. package/language/blockString.mjs +54 -33
  77. package/language/directiveLocation.js.flow +0 -1
  78. package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
  79. package/language/experimentalOnlineParser/grammar.js +987 -0
  80. package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
  81. package/language/experimentalOnlineParser/grammar.mjs +980 -0
  82. package/language/experimentalOnlineParser/index.d.ts +6 -0
  83. package/language/experimentalOnlineParser/index.js +31 -0
  84. package/language/experimentalOnlineParser/index.js.flow +7 -0
  85. package/language/experimentalOnlineParser/index.mjs +1 -0
  86. package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
  87. package/language/experimentalOnlineParser/onlineParser.js +604 -0
  88. package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
  89. package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
  90. package/language/index.js +12 -12
  91. package/language/index.js.flow +0 -1
  92. package/language/kinds.js.flow +0 -1
  93. package/language/lexer.js +242 -183
  94. package/language/lexer.js.flow +191 -186
  95. package/language/lexer.mjs +239 -180
  96. package/language/location.js.flow +1 -2
  97. package/language/parser.js +73 -68
  98. package/language/parser.js.flow +112 -106
  99. package/language/parser.mjs +66 -62
  100. package/language/predicates.js +1 -1
  101. package/language/predicates.js.flow +1 -2
  102. package/language/printLocation.js +1 -1
  103. package/language/printLocation.js.flow +4 -4
  104. package/language/printer.js +20 -13
  105. package/language/printer.js.flow +27 -25
  106. package/language/printer.mjs +18 -11
  107. package/language/source.d.ts +12 -6
  108. package/language/source.js +25 -9
  109. package/language/source.js.flow +25 -8
  110. package/language/source.mjs +19 -7
  111. package/language/tokenKind.js.flow +0 -1
  112. package/language/visitor.d.ts +3 -3
  113. package/language/visitor.js +5 -5
  114. package/language/visitor.js.flow +5 -5
  115. package/language/visitor.mjs +3 -3
  116. package/package.json +1 -1
  117. package/polyfills/arrayFrom.js +2 -2
  118. package/polyfills/arrayFrom.js.flow +1 -2
  119. package/polyfills/arrayFrom.mjs +1 -1
  120. package/polyfills/find.js +1 -1
  121. package/polyfills/find.js.flow +1 -2
  122. package/polyfills/find.mjs +1 -1
  123. package/polyfills/isFinite.js +1 -1
  124. package/polyfills/isFinite.js.flow +1 -2
  125. package/polyfills/isFinite.mjs +1 -1
  126. package/polyfills/isInteger.js +1 -1
  127. package/polyfills/isInteger.js.flow +1 -2
  128. package/polyfills/isInteger.mjs +1 -1
  129. package/polyfills/objectEntries.js +1 -1
  130. package/polyfills/objectEntries.js.flow +2 -3
  131. package/polyfills/objectEntries.mjs +1 -1
  132. package/polyfills/objectValues.js +1 -1
  133. package/polyfills/objectValues.js.flow +2 -3
  134. package/polyfills/objectValues.mjs +1 -1
  135. package/polyfills/symbols.js +3 -5
  136. package/polyfills/symbols.js.flow +9 -6
  137. package/polyfills/symbols.mjs +3 -5
  138. package/subscription/index.js +1 -1
  139. package/subscription/index.js.flow +0 -1
  140. package/subscription/mapAsyncIterator.js +2 -2
  141. package/subscription/mapAsyncIterator.js.flow +9 -10
  142. package/subscription/mapAsyncIterator.mjs +1 -1
  143. package/subscription/subscribe.js +61 -73
  144. package/subscription/subscribe.js.flow +74 -88
  145. package/subscription/subscribe.mjs +53 -65
  146. package/type/definition.d.ts +181 -31
  147. package/type/definition.js +37 -32
  148. package/type/definition.js.flow +66 -51
  149. package/type/definition.mjs +20 -18
  150. package/type/directives.d.ts +17 -3
  151. package/type/directives.js +17 -16
  152. package/type/directives.js.flow +20 -21
  153. package/type/directives.mjs +6 -5
  154. package/type/index.d.ts +12 -0
  155. package/type/index.js +6 -6
  156. package/type/index.js.flow +0 -1
  157. package/type/introspection.js +86 -68
  158. package/type/introspection.js.flow +85 -54
  159. package/type/introspection.mjs +79 -61
  160. package/type/scalars.js +9 -9
  161. package/type/scalars.js.flow +3 -3
  162. package/type/scalars.mjs +1 -1
  163. package/type/schema.d.ts +17 -4
  164. package/type/schema.js +13 -13
  165. package/type/schema.js.flow +18 -16
  166. package/type/schema.mjs +1 -1
  167. package/type/validate.js +52 -19
  168. package/type/validate.js.flow +67 -18
  169. package/type/validate.mjs +44 -10
  170. package/utilities/TypeInfo.js +7 -7
  171. package/utilities/TypeInfo.js.flow +16 -18
  172. package/utilities/TypeInfo.mjs +1 -1
  173. package/utilities/assertValidName.js +2 -2
  174. package/utilities/assertValidName.js.flow +0 -1
  175. package/utilities/astFromValue.js +10 -10
  176. package/utilities/astFromValue.js.flow +2 -3
  177. package/utilities/buildASTSchema.js +17 -27
  178. package/utilities/buildASTSchema.js.flow +11 -28
  179. package/utilities/buildASTSchema.mjs +11 -21
  180. package/utilities/buildClientSchema.js +14 -14
  181. package/utilities/buildClientSchema.js.flow +41 -29
  182. package/utilities/buildClientSchema.mjs +5 -5
  183. package/utilities/coerceInputValue.js +14 -14
  184. package/utilities/coerceInputValue.js.flow +7 -6
  185. package/utilities/coerceInputValue.mjs +2 -2
  186. package/utilities/concatAST.js +9 -8
  187. package/utilities/concatAST.js.flow +9 -9
  188. package/utilities/concatAST.mjs +9 -6
  189. package/utilities/extendSchema.js +26 -19
  190. package/utilities/extendSchema.js.flow +58 -45
  191. package/utilities/extendSchema.mjs +9 -2
  192. package/utilities/findBreakingChanges.js +9 -9
  193. package/utilities/findBreakingChanges.js.flow +12 -11
  194. package/utilities/findDeprecatedUsages.d.ts +9 -1
  195. package/utilities/findDeprecatedUsages.js +11 -27
  196. package/utilities/findDeprecatedUsages.js.flow +15 -44
  197. package/utilities/findDeprecatedUsages.mjs +11 -25
  198. package/utilities/getIntrospectionQuery.js.flow +2 -3
  199. package/utilities/getOperationAST.js +1 -1
  200. package/utilities/getOperationAST.js.flow +1 -5
  201. package/utilities/getOperationAST.mjs +1 -1
  202. package/utilities/getOperationRootType.js +1 -1
  203. package/utilities/getOperationRootType.js.flow +5 -6
  204. package/utilities/index.d.ts +4 -1
  205. package/utilities/index.js +22 -22
  206. package/utilities/index.js.flow +1 -2
  207. package/utilities/index.mjs +1 -1
  208. package/utilities/introspectionFromSchema.js +6 -8
  209. package/utilities/introspectionFromSchema.js.flow +10 -10
  210. package/utilities/introspectionFromSchema.mjs +3 -4
  211. package/utilities/lexicographicSortSchema.js +10 -8
  212. package/utilities/lexicographicSortSchema.js.flow +19 -12
  213. package/utilities/lexicographicSortSchema.mjs +3 -1
  214. package/utilities/printSchema.js +15 -16
  215. package/utilities/printSchema.js.flow +34 -25
  216. package/utilities/printSchema.mjs +6 -7
  217. package/utilities/separateOperations.js +2 -2
  218. package/utilities/separateOperations.js.flow +2 -6
  219. package/utilities/separateOperations.mjs +1 -1
  220. package/utilities/stripIgnoredCharacters.js +6 -16
  221. package/utilities/stripIgnoredCharacters.js.flow +4 -13
  222. package/utilities/stripIgnoredCharacters.mjs +3 -10
  223. package/utilities/typeComparators.js +1 -1
  224. package/utilities/typeComparators.js.flow +2 -4
  225. package/utilities/typeFromAST.js +6 -6
  226. package/utilities/typeFromAST.js.flow +11 -14
  227. package/utilities/typeFromAST.mjs +2 -2
  228. package/utilities/typedQueryDocumentNode.d.ts +20 -0
  229. package/utilities/valueFromAST.js +6 -6
  230. package/utilities/valueFromAST.js.flow +7 -5
  231. package/utilities/valueFromASTUntyped.js +4 -4
  232. package/utilities/valueFromASTUntyped.js.flow +2 -3
  233. package/validation/ValidationContext.d.ts +3 -0
  234. package/validation/ValidationContext.js +7 -3
  235. package/validation/ValidationContext.js.flow +28 -22
  236. package/validation/ValidationContext.mjs +4 -0
  237. package/validation/index.d.ts +4 -0
  238. package/validation/index.js +52 -36
  239. package/validation/index.js.flow +4 -1
  240. package/validation/index.mjs +4 -1
  241. package/validation/rules/ExecutableDefinitions.js +1 -1
  242. package/validation/rules/ExecutableDefinitions.js.flow +0 -1
  243. package/validation/rules/ExecutableDefinitionsRule.js +3 -3
  244. package/validation/rules/ExecutableDefinitionsRule.js.flow +2 -3
  245. package/validation/rules/FieldsOnCorrectTypeRule.js +5 -5
  246. package/validation/rules/FieldsOnCorrectTypeRule.js.flow +9 -8
  247. package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
  248. package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +2 -3
  249. package/validation/rules/KnownArgumentNamesRule.js +5 -5
  250. package/validation/rules/KnownArgumentNamesRule.js.flow +5 -5
  251. package/validation/rules/KnownDirectivesRule.js +6 -6
  252. package/validation/rules/KnownDirectivesRule.js.flow +10 -11
  253. package/validation/rules/KnownFragmentNamesRule.js +1 -1
  254. package/validation/rules/KnownFragmentNamesRule.js.flow +3 -3
  255. package/validation/rules/KnownTypeNamesRule.js +12 -10
  256. package/validation/rules/KnownTypeNamesRule.js.flow +14 -11
  257. package/validation/rules/KnownTypeNamesRule.mjs +6 -5
  258. package/validation/rules/LoneAnonymousOperationRule.js +2 -2
  259. package/validation/rules/LoneAnonymousOperationRule.js.flow +2 -3
  260. package/validation/rules/LoneSchemaDefinition.js +1 -1
  261. package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
  262. package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
  263. package/validation/rules/LoneSchemaDefinitionRule.js.flow +2 -3
  264. package/validation/rules/NoFragmentCyclesRule.js +1 -1
  265. package/validation/rules/NoFragmentCyclesRule.js.flow +4 -5
  266. package/validation/rules/NoUndefinedVariablesRule.js +1 -1
  267. package/validation/rules/NoUndefinedVariablesRule.js.flow +3 -3
  268. package/validation/rules/NoUnusedFragmentsRule.js +1 -1
  269. package/validation/rules/NoUnusedFragmentsRule.js.flow +3 -3
  270. package/validation/rules/NoUnusedVariablesRule.js +1 -1
  271. package/validation/rules/NoUnusedVariablesRule.js.flow +3 -3
  272. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
  273. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +29 -27
  274. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
  275. package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
  276. package/validation/rules/PossibleFragmentSpreadsRule.js.flow +7 -4
  277. package/validation/rules/PossibleTypeExtensions.js +1 -1
  278. package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
  279. package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
  280. package/validation/rules/PossibleTypeExtensionsRule.js.flow +8 -6
  281. package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
  282. package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +7 -6
  283. package/validation/rules/ScalarLeafsRule.js +3 -3
  284. package/validation/rules/ScalarLeafsRule.js.flow +3 -4
  285. package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
  286. package/validation/rules/SingleFieldSubscriptionsRule.js.flow +3 -4
  287. package/validation/rules/UniqueArgumentNamesRule.js +1 -1
  288. package/validation/rules/UniqueArgumentNamesRule.js.flow +2 -3
  289. package/validation/rules/UniqueDirectiveNames.js +1 -1
  290. package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
  291. package/validation/rules/UniqueDirectiveNamesRule.js +1 -1
  292. package/validation/rules/UniqueDirectiveNamesRule.js.flow +2 -3
  293. package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
  294. package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +4 -5
  295. package/validation/rules/UniqueEnumValueNames.js +1 -1
  296. package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
  297. package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
  298. package/validation/rules/UniqueEnumValueNamesRule.js.flow +11 -4
  299. package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
  300. package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
  301. package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
  302. package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +17 -6
  303. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
  304. package/validation/rules/UniqueFragmentNamesRule.js +1 -1
  305. package/validation/rules/UniqueFragmentNamesRule.js.flow +3 -3
  306. package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
  307. package/validation/rules/UniqueInputFieldNamesRule.js.flow +3 -3
  308. package/validation/rules/UniqueOperationNamesRule.js +1 -1
  309. package/validation/rules/UniqueOperationNamesRule.js.flow +3 -3
  310. package/validation/rules/UniqueOperationTypes.js +1 -1
  311. package/validation/rules/UniqueOperationTypes.js.flow +0 -1
  312. package/validation/rules/UniqueOperationTypesRule.js +1 -1
  313. package/validation/rules/UniqueOperationTypesRule.js.flow +10 -4
  314. package/validation/rules/UniqueTypeNames.js +1 -1
  315. package/validation/rules/UniqueTypeNames.js.flow +0 -1
  316. package/validation/rules/UniqueTypeNamesRule.js +1 -1
  317. package/validation/rules/UniqueTypeNamesRule.js.flow +3 -4
  318. package/validation/rules/UniqueVariableNamesRule.js +1 -1
  319. package/validation/rules/UniqueVariableNamesRule.js.flow +3 -4
  320. package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
  321. package/validation/rules/ValuesOfCorrectTypeRule.js.flow +3 -4
  322. package/validation/rules/VariablesAreInputTypesRule.js +4 -4
  323. package/validation/rules/VariablesAreInputTypesRule.js.flow +3 -4
  324. package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
  325. package/validation/rules/VariablesInAllowedPositionRule.js.flow +6 -6
  326. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +14 -0
  327. package/validation/rules/custom/NoDeprecatedCustomRule.js +79 -0
  328. package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +94 -0
  329. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +68 -0
  330. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +16 -0
  331. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +34 -0
  332. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +38 -0
  333. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +25 -0
  334. package/validation/specifiedRules.js +33 -33
  335. package/validation/specifiedRules.js.flow +0 -1
  336. package/validation/validate.js +7 -7
  337. package/validation/validate.js.flow +4 -9
  338. package/version.js +2 -2
  339. package/version.js.flow +2 -3
  340. package/version.mjs +2 -2
  341. package/polyfills/flatMap.js +0 -30
  342. package/polyfills/flatMap.js.flow +0 -28
  343. 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 _source = require("./source");
19
+ var _source = require("./source.js");
19
20
 
20
- var _directiveLocation = require("./directiveLocation");
21
+ var _directiveLocation = require("./directiveLocation.js");
21
22
 
22
- var _tokenKind = require("./tokenKind");
23
-
24
- var _lexer = require("./lexer");
25
-
26
- var _ast = require("./ast");
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,63 +1,60 @@
1
1
  // @flow strict
2
-
3
- import inspect from '../jsutils/inspect';
4
- import devAssert from '../jsutils/devAssert';
5
-
2
+ import type { GraphQLError } from '../error/GraphQLError';
6
3
  import { syntaxError } from '../error/syntaxError';
7
- import { type GraphQLError } from '../error/GraphQLError';
8
4
 
5
+ import type { TokenKindEnum } from './tokenKind';
6
+ import type {
7
+ Token,
8
+ NameNode,
9
+ VariableNode,
10
+ DocumentNode,
11
+ DefinitionNode,
12
+ OperationDefinitionNode,
13
+ OperationTypeNode,
14
+ VariableDefinitionNode,
15
+ SelectionSetNode,
16
+ SelectionNode,
17
+ FieldNode,
18
+ ArgumentNode,
19
+ FragmentSpreadNode,
20
+ InlineFragmentNode,
21
+ FragmentDefinitionNode,
22
+ ValueNode,
23
+ StringValueNode,
24
+ ListValueNode,
25
+ ObjectValueNode,
26
+ ObjectFieldNode,
27
+ DirectiveNode,
28
+ TypeNode,
29
+ NamedTypeNode,
30
+ TypeSystemDefinitionNode,
31
+ SchemaDefinitionNode,
32
+ OperationTypeDefinitionNode,
33
+ ScalarTypeDefinitionNode,
34
+ ObjectTypeDefinitionNode,
35
+ FieldDefinitionNode,
36
+ InputValueDefinitionNode,
37
+ InterfaceTypeDefinitionNode,
38
+ UnionTypeDefinitionNode,
39
+ EnumTypeDefinitionNode,
40
+ EnumValueDefinitionNode,
41
+ InputObjectTypeDefinitionNode,
42
+ DirectiveDefinitionNode,
43
+ TypeSystemExtensionNode,
44
+ SchemaExtensionNode,
45
+ ScalarTypeExtensionNode,
46
+ ObjectTypeExtensionNode,
47
+ InterfaceTypeExtensionNode,
48
+ UnionTypeExtensionNode,
49
+ EnumTypeExtensionNode,
50
+ InputObjectTypeExtensionNode,
51
+ } from './ast';
9
52
  import { Kind } from './kinds';
10
- import { Source } from './source';
53
+ import { Location } from './ast';
54
+ import { TokenKind } from './tokenKind';
55
+ import { Source, isSource } from './source';
11
56
  import { DirectiveLocation } from './directiveLocation';
12
- import { type TokenKindEnum, TokenKind } from './tokenKind';
13
57
  import { Lexer, isPunctuatorTokenKind } from './lexer';
14
- import {
15
- Location,
16
- type Token,
17
- type NameNode,
18
- type VariableNode,
19
- type DocumentNode,
20
- type DefinitionNode,
21
- type OperationDefinitionNode,
22
- type OperationTypeNode,
23
- type VariableDefinitionNode,
24
- type SelectionSetNode,
25
- type SelectionNode,
26
- type FieldNode,
27
- type ArgumentNode,
28
- type FragmentSpreadNode,
29
- type InlineFragmentNode,
30
- type FragmentDefinitionNode,
31
- type ValueNode,
32
- type StringValueNode,
33
- type ListValueNode,
34
- type ObjectValueNode,
35
- type ObjectFieldNode,
36
- type DirectiveNode,
37
- type TypeNode,
38
- type NamedTypeNode,
39
- type TypeSystemDefinitionNode,
40
- type SchemaDefinitionNode,
41
- type OperationTypeDefinitionNode,
42
- type ScalarTypeDefinitionNode,
43
- type ObjectTypeDefinitionNode,
44
- type FieldDefinitionNode,
45
- type InputValueDefinitionNode,
46
- type InterfaceTypeDefinitionNode,
47
- type UnionTypeDefinitionNode,
48
- type EnumTypeDefinitionNode,
49
- type EnumValueDefinitionNode,
50
- type InputObjectTypeDefinitionNode,
51
- type DirectiveDefinitionNode,
52
- type TypeSystemExtensionNode,
53
- type SchemaExtensionNode,
54
- type ScalarTypeExtensionNode,
55
- type ObjectTypeExtensionNode,
56
- type InterfaceTypeExtensionNode,
57
- type UnionTypeExtensionNode,
58
- type EnumTypeExtensionNode,
59
- type InputObjectTypeExtensionNode,
60
- } from './ast';
61
58
 
62
59
  /**
63
60
  * Configuration options to control parser behavior
@@ -163,16 +160,23 @@ export function parseType(
163
160
  return type;
164
161
  }
165
162
 
166
- 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 {
167
175
  _options: ?ParseOptions;
168
176
  _lexer: Lexer;
169
177
 
170
178
  constructor(source: string | Source, options?: ParseOptions) {
171
- const sourceObj = typeof source === 'string' ? new Source(source) : source;
172
- devAssert(
173
- sourceObj instanceof Source,
174
- `Must provide Source. Received: ${inspect(sourceObj)}.`,
175
- );
179
+ const sourceObj = isSource(source) ? source : new Source(source);
176
180
 
177
181
  this._lexer = new Lexer(sourceObj);
178
182
  this._options = options;
@@ -852,20 +856,24 @@ class Parser {
852
856
  * - ImplementsInterfaces & NamedType
853
857
  */
854
858
  parseImplementsInterfaces(): Array<NamedTypeNode> {
855
- const types = [];
856
- if (this.expectOptionalKeyword('implements')) {
859
+ if (!this.expectOptionalKeyword('implements')) {
860
+ return [];
861
+ }
862
+
863
+ if (this._options?.allowLegacySDLImplementsInterfaces === true) {
864
+ const types = [];
857
865
  // Optional leading ampersand
858
866
  this.expectOptionalToken(TokenKind.AMP);
859
867
  do {
860
868
  types.push(this.parseNamedType());
861
869
  } while (
862
870
  this.expectOptionalToken(TokenKind.AMP) ||
863
- // Legacy support for the SDL?
864
- (this._options?.allowLegacySDLImplementsInterfaces === true &&
865
- this.peek(TokenKind.NAME))
871
+ this.peek(TokenKind.NAME)
866
872
  );
873
+ return types;
867
874
  }
868
- return types;
875
+
876
+ return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
869
877
  }
870
878
 
871
879
  /**
@@ -999,15 +1007,9 @@ class Parser {
999
1007
  * - UnionMemberTypes | NamedType
1000
1008
  */
1001
1009
  parseUnionMemberTypes(): Array<NamedTypeNode> {
1002
- const types = [];
1003
- if (this.expectOptionalToken(TokenKind.EQUALS)) {
1004
- // Optional leading pipe
1005
- this.expectOptionalToken(TokenKind.PIPE);
1006
- do {
1007
- types.push(this.parseNamedType());
1008
- } while (this.expectOptionalToken(TokenKind.PIPE));
1009
- }
1010
- return types;
1010
+ return this.expectOptionalToken(TokenKind.EQUALS)
1011
+ ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
1012
+ : [];
1011
1013
  }
1012
1014
 
1013
1015
  /**
@@ -1343,13 +1345,7 @@ class Parser {
1343
1345
  * - DirectiveLocations | DirectiveLocation
1344
1346
  */
1345
1347
  parseDirectiveLocations(): Array<NameNode> {
1346
- // Optional leading pipe
1347
- this.expectOptionalToken(TokenKind.PIPE);
1348
- const locations = [];
1349
- do {
1350
- locations.push(this.parseDirectiveLocation());
1351
- } while (this.expectOptionalToken(TokenKind.PIPE));
1352
- return locations;
1348
+ return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
1353
1349
  }
1354
1350
 
1355
1351
  /*
@@ -1391,8 +1387,7 @@ class Parser {
1391
1387
  // Core parsing utility functions
1392
1388
 
1393
1389
  /**
1394
- * Returns a location object, used to identify the place in
1395
- * 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.
1396
1391
  */
1397
1392
  loc(startToken: Token): Location | void {
1398
1393
  if (this._options?.noLocation !== true) {
@@ -1412,8 +1407,8 @@ class Parser {
1412
1407
  }
1413
1408
 
1414
1409
  /**
1415
- * If the next token is of the given kind, return that token after advancing
1416
- * 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.
1417
1412
  */
1418
1413
  expectToken(kind: TokenKindEnum): Token {
1419
1414
  const token = this._lexer.token;
@@ -1430,8 +1425,8 @@ class Parser {
1430
1425
  }
1431
1426
 
1432
1427
  /**
1433
- * If the next token is of the given kind, return that token after advancing
1434
- * 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.
1435
1430
  */
1436
1431
  expectOptionalToken(kind: TokenKindEnum): ?Token {
1437
1432
  const token = this._lexer.token;
@@ -1460,8 +1455,8 @@ class Parser {
1460
1455
  }
1461
1456
 
1462
1457
  /**
1463
- * If the next token is a given keyword, return "true" after advancing
1464
- * 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".
1465
1460
  */
1466
1461
  expectOptionalKeyword(value: string): boolean {
1467
1462
  const token = this._lexer.token;
@@ -1473,8 +1468,7 @@ class Parser {
1473
1468
  }
1474
1469
 
1475
1470
  /**
1476
- * Helper function for creating an error when an unexpected lexed token
1477
- * is encountered.
1471
+ * Helper function for creating an error when an unexpected lexed token is encountered.
1478
1472
  */
1479
1473
  unexpected(atToken?: ?Token): GraphQLError {
1480
1474
  const token = atToken ?? this._lexer.token;
@@ -1486,10 +1480,9 @@ class Parser {
1486
1480
  }
1487
1481
 
1488
1482
  /**
1489
- * Returns a possibly empty list of parse nodes, determined by
1490
- * the parseFn. This list begins with a lex token of openKind
1491
- * and ends with a lex token of closeKind. Advances the parser
1492
- * 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.
1493
1486
  */
1494
1487
  any<T>(
1495
1488
  openKind: TokenKindEnum,
@@ -1506,10 +1499,9 @@ class Parser {
1506
1499
 
1507
1500
  /**
1508
1501
  * Returns a list of parse nodes, determined by the parseFn.
1509
- * It can be empty only if open token is missing otherwise it will always
1510
- * return non-empty list that begins with a lex token of openKind and ends
1511
- * with a lex token of closeKind. Advances the parser to the next lex token
1512
- * 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.
1513
1505
  */
1514
1506
  optionalMany<T>(
1515
1507
  openKind: TokenKindEnum,
@@ -1527,10 +1519,9 @@ class Parser {
1527
1519
  }
1528
1520
 
1529
1521
  /**
1530
- * Returns a non-empty list of parse nodes, determined by
1531
- * the parseFn. This list begins with a lex token of openKind
1532
- * and ends with a lex token of closeKind. Advances the parser
1533
- * 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.
1534
1525
  */
1535
1526
  many<T>(
1536
1527
  openKind: TokenKindEnum,
@@ -1544,10 +1535,25 @@ class Parser {
1544
1535
  } while (!this.expectOptionalToken(closeKind));
1545
1536
  return nodes;
1546
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
+ }
1547
1553
  }
1548
1554
 
1549
1555
  /**
1550
- * 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.
1551
1557
  */
1552
1558
  function getTokenDesc(token: Token): string {
1553
1559
  const value = token.value;
@@ -1555,7 +1561,7 @@ function getTokenDesc(token: Token): string {
1555
1561
  }
1556
1562
 
1557
1563
  /**
1558
- * 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.
1559
1565
  */
1560
1566
  function getTokenKindDesc(kind: TokenKindEnum): string {
1561
1567
  return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;