graphql 14.4.2 → 14.5.3

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/README.md +5 -10
  2. package/error/GraphQLError.d.ts +87 -0
  3. package/error/GraphQLError.js +7 -45
  4. package/error/GraphQLError.js.flow +1 -0
  5. package/error/GraphQLError.mjs +7 -45
  6. package/error/formatError.d.ts +39 -0
  7. package/error/formatError.js +5 -2
  8. package/error/formatError.js.flow +27 -3
  9. package/error/formatError.mjs +5 -2
  10. package/error/index.d.ts +4 -0
  11. package/error/locatedError.d.ts +13 -0
  12. package/error/locatedError.js.flow +2 -1
  13. package/error/locatedError.mjs +1 -1
  14. package/error/syntaxError.d.ts +12 -0
  15. package/error/syntaxError.js.flow +1 -0
  16. package/execution/execute.d.ts +190 -0
  17. package/execution/execute.js +55 -89
  18. package/execution/execute.js.flow +95 -133
  19. package/execution/execute.mjs +75 -80
  20. package/execution/index.d.ts +11 -0
  21. package/execution/index.js +8 -6
  22. package/execution/index.js.flow +3 -6
  23. package/execution/index.mjs +2 -1
  24. package/execution/values.d.ts +68 -0
  25. package/execution/values.js +119 -128
  26. package/execution/values.js.flow +150 -127
  27. package/execution/values.mjs +117 -125
  28. package/graphql.d.ts +88 -0
  29. package/graphql.js +5 -5
  30. package/graphql.js.flow +9 -5
  31. package/graphql.mjs +41 -1
  32. package/index.d.ts +446 -0
  33. package/index.js +6 -0
  34. package/index.js.flow +3 -1
  35. package/index.mjs +2 -1
  36. package/jsutils/ObjMap.js.flow +6 -0
  37. package/jsutils/Path.d.ts +14 -0
  38. package/jsutils/Path.js +33 -0
  39. package/jsutils/Path.js.flow +26 -0
  40. package/jsutils/Path.mjs +24 -0
  41. package/jsutils/PromiseOrValue.d.ts +1 -0
  42. package/jsutils/dedent.js +6 -24
  43. package/jsutils/dedent.mjs +6 -24
  44. package/jsutils/defineToStringTag.js.flow +1 -1
  45. package/jsutils/devAssert.js +14 -0
  46. package/jsutils/devAssert.js.flow +8 -0
  47. package/jsutils/devAssert.mjs +7 -0
  48. package/jsutils/inspect.js +1 -1
  49. package/jsutils/inspect.js.flow +1 -1
  50. package/jsutils/inspect.mjs +1 -1
  51. package/jsutils/invariant.js +1 -2
  52. package/jsutils/invariant.js.flow +2 -3
  53. package/jsutils/invariant.mjs +1 -2
  54. package/jsutils/mapValue.js +6 -24
  55. package/jsutils/mapValue.js.flow +2 -1
  56. package/jsutils/mapValue.mjs +6 -24
  57. package/jsutils/printPathArray.js +15 -0
  58. package/jsutils/printPathArray.js.flow +14 -0
  59. package/jsutils/printPathArray.mjs +8 -0
  60. package/jsutils/suggestionList.js +14 -34
  61. package/jsutils/suggestionList.js.flow +4 -6
  62. package/jsutils/suggestionList.mjs +14 -34
  63. package/jsutils/toObjMap.js +28 -0
  64. package/jsutils/toObjMap.js.flow +26 -0
  65. package/jsutils/toObjMap.mjs +18 -0
  66. package/language/ast.d.ts +573 -0
  67. package/language/blockString.d.ts +21 -0
  68. package/language/directiveLocation.d.ts +35 -0
  69. package/language/index.d.ts +96 -0
  70. package/language/kinds.d.ts +77 -0
  71. package/language/lexer.d.ts +60 -0
  72. package/language/lexer.js +2 -12
  73. package/language/lexer.js.flow +6 -12
  74. package/language/lexer.mjs +1 -9
  75. package/language/location.d.ts +15 -0
  76. package/language/parser.d.ts +89 -0
  77. package/language/parser.js +1329 -1302
  78. package/language/parser.js.flow +1289 -1298
  79. package/language/parser.mjs +1326 -1297
  80. package/language/predicates.d.ts +36 -0
  81. package/language/predicates.js.flow +1 -1
  82. package/language/printLocation.d.ts +16 -0
  83. package/language/printLocation.js.flow +1 -1
  84. package/language/printer.d.ts +7 -0
  85. package/language/printer.js.flow +1 -1
  86. package/language/source.d.ts +19 -0
  87. package/language/source.js +3 -3
  88. package/language/source.js.flow +3 -3
  89. package/language/source.mjs +3 -3
  90. package/language/tokenKind.d.ts +35 -0
  91. package/language/visitor.d.ts +264 -0
  92. package/language/visitor.js +2 -2
  93. package/language/visitor.js.flow +3 -1
  94. package/language/visitor.mjs +2 -2
  95. package/package.json +1 -1
  96. package/polyfills/find.js +2 -2
  97. package/polyfills/find.js.flow +1 -2
  98. package/polyfills/find.mjs +2 -2
  99. package/polyfills/flatMap.js +3 -3
  100. package/polyfills/flatMap.js.flow +2 -3
  101. package/polyfills/flatMap.mjs +3 -3
  102. package/subscription/asyncIteratorReject.d.ts +6 -0
  103. package/subscription/index.d.ts +5 -0
  104. package/subscription/mapAsyncIterator.d.ts +9 -0
  105. package/subscription/mapAsyncIterator.js.flow +1 -0
  106. package/subscription/subscribe.d.ts +86 -0
  107. package/subscription/subscribe.js +29 -10
  108. package/subscription/subscribe.js.flow +45 -24
  109. package/subscription/subscribe.mjs +27 -9
  110. package/tsutils/Maybe.d.ts +4 -0
  111. package/type/definition.d.ts +805 -0
  112. package/type/definition.js +154 -70
  113. package/type/definition.js.flow +217 -160
  114. package/type/definition.mjs +149 -66
  115. package/type/directives.d.ts +72 -0
  116. package/type/directives.js +20 -12
  117. package/type/directives.js.flow +34 -19
  118. package/type/directives.mjs +17 -10
  119. package/type/index.d.ts +155 -0
  120. package/type/index.js.flow +2 -2
  121. package/type/introspection.d.ts +40 -0
  122. package/type/introspection.js +24 -10
  123. package/type/introspection.js.flow +29 -8
  124. package/type/introspection.mjs +23 -10
  125. package/type/scalars.d.ts +11 -0
  126. package/type/scalars.js +2 -2
  127. package/type/scalars.js.flow +4 -1
  128. package/type/scalars.mjs +2 -2
  129. package/type/schema.d.ts +108 -0
  130. package/type/schema.js +74 -151
  131. package/type/schema.js.flow +75 -73
  132. package/type/schema.mjs +75 -149
  133. package/type/validate.d.ts +19 -0
  134. package/type/validate.js +227 -486
  135. package/type/validate.js.flow +13 -8
  136. package/type/validate.mjs +218 -477
  137. package/utilities/TypeInfo.d.ts +49 -0
  138. package/utilities/TypeInfo.js.flow +9 -6
  139. package/utilities/assertValidName.d.ts +15 -0
  140. package/utilities/assertValidName.js +3 -3
  141. package/utilities/assertValidName.js.flow +3 -2
  142. package/utilities/assertValidName.mjs +2 -2
  143. package/utilities/astFromValue.d.ts +25 -0
  144. package/utilities/astFromValue.js +22 -38
  145. package/utilities/astFromValue.js.flow +7 -4
  146. package/utilities/astFromValue.mjs +19 -36
  147. package/utilities/buildASTSchema.d.ts +114 -0
  148. package/utilities/buildASTSchema.js +37 -68
  149. package/utilities/buildASTSchema.js.flow +32 -30
  150. package/utilities/buildASTSchema.mjs +32 -64
  151. package/utilities/buildClientSchema.d.ts +21 -0
  152. package/utilities/buildClientSchema.js +23 -15
  153. package/utilities/buildClientSchema.js.flow +17 -16
  154. package/utilities/buildClientSchema.mjs +20 -12
  155. package/utilities/coerceInputValue.d.ts +17 -0
  156. package/utilities/coerceInputValue.js +161 -0
  157. package/utilities/coerceInputValue.js.flow +214 -0
  158. package/utilities/coerceInputValue.mjs +142 -0
  159. package/utilities/coerceValue.d.ts +23 -0
  160. package/utilities/coerceValue.js +21 -199
  161. package/utilities/coerceValue.js.flow +31 -223
  162. package/utilities/coerceValue.mjs +20 -195
  163. package/utilities/concatAST.d.ts +8 -0
  164. package/utilities/concatAST.js.flow +1 -0
  165. package/utilities/extendSchema.d.ts +45 -0
  166. package/utilities/extendSchema.js +64 -131
  167. package/utilities/extendSchema.js.flow +27 -24
  168. package/utilities/extendSchema.mjs +61 -129
  169. package/utilities/findBreakingChanges.d.ts +64 -0
  170. package/utilities/findBreakingChanges.js +194 -619
  171. package/utilities/findBreakingChanges.js.flow +8 -5
  172. package/utilities/findBreakingChanges.mjs +194 -619
  173. package/utilities/findDeprecatedUsages.d.ts +13 -0
  174. package/utilities/findDeprecatedUsages.js.flow +4 -1
  175. package/utilities/getOperationAST.d.ts +12 -0
  176. package/utilities/getOperationAST.js +13 -31
  177. package/utilities/getOperationAST.mjs +13 -31
  178. package/utilities/getOperationRootType.d.ts +14 -0
  179. package/utilities/getOperationRootType.js.flow +2 -0
  180. package/utilities/index.d.ts +127 -0
  181. package/utilities/index.js +8 -0
  182. package/utilities/index.js.flow +4 -1
  183. package/utilities/index.mjs +3 -1
  184. package/utilities/introspectionFromSchema.d.ts +16 -0
  185. package/utilities/introspectionFromSchema.js +5 -3
  186. package/utilities/introspectionFromSchema.js.flow +4 -2
  187. package/utilities/introspectionFromSchema.mjs +4 -2
  188. package/utilities/introspectionQuery.d.ts +177 -0
  189. package/utilities/isValidJSValue.d.ts +8 -0
  190. package/utilities/isValidJSValue.js +1 -1
  191. package/utilities/isValidJSValue.js.flow +3 -2
  192. package/utilities/isValidJSValue.mjs +2 -2
  193. package/utilities/isValidLiteralValue.d.ts +15 -0
  194. package/utilities/isValidLiteralValue.js +4 -4
  195. package/utilities/isValidLiteralValue.js.flow +8 -4
  196. package/utilities/isValidLiteralValue.mjs +2 -2
  197. package/utilities/lexicographicSortSchema.d.ts +6 -0
  198. package/utilities/lexicographicSortSchema.js +11 -8
  199. package/utilities/lexicographicSortSchema.js.flow +5 -3
  200. package/utilities/lexicographicSortSchema.mjs +9 -7
  201. package/utilities/schemaPrinter.d.ts +30 -0
  202. package/utilities/schemaPrinter.js +15 -32
  203. package/utilities/schemaPrinter.js.flow +14 -10
  204. package/utilities/schemaPrinter.mjs +14 -32
  205. package/utilities/separateOperations.d.ts +11 -0
  206. package/utilities/separateOperations.js +6 -6
  207. package/utilities/separateOperations.js.flow +2 -1
  208. package/utilities/separateOperations.mjs +6 -6
  209. package/utilities/stripIgnoredCharacters.d.ts +55 -0
  210. package/utilities/stripIgnoredCharacters.js.flow +1 -0
  211. package/utilities/typeComparators.d.ts +32 -0
  212. package/utilities/typeComparators.js.flow +1 -1
  213. package/utilities/typeComparators.mjs +1 -1
  214. package/utilities/typeFromAST.d.ts +29 -0
  215. package/utilities/typeFromAST.js +5 -3
  216. package/utilities/typeFromAST.js.flow +5 -3
  217. package/utilities/typeFromAST.mjs +14 -3
  218. package/utilities/valueFromAST.d.ts +29 -0
  219. package/utilities/valueFromAST.js +40 -74
  220. package/utilities/valueFromAST.js.flow +7 -4
  221. package/utilities/valueFromAST.mjs +39 -74
  222. package/utilities/valueFromASTUntyped.d.ts +23 -0
  223. package/utilities/valueFromASTUntyped.js +4 -3
  224. package/utilities/valueFromASTUntyped.js.flow +3 -2
  225. package/utilities/valueFromASTUntyped.mjs +3 -3
  226. package/validation/ValidationContext.d.ts +96 -0
  227. package/validation/ValidationContext.js +38 -86
  228. package/validation/ValidationContext.js.flow +22 -7
  229. package/validation/ValidationContext.mjs +37 -85
  230. package/validation/index.d.ts +126 -0
  231. package/validation/rules/ExecutableDefinitions.d.ts +14 -0
  232. package/validation/rules/ExecutableDefinitions.js +4 -23
  233. package/validation/rules/ExecutableDefinitions.js.flow +4 -2
  234. package/validation/rules/ExecutableDefinitions.mjs +4 -23
  235. package/validation/rules/FieldsOnCorrectType.d.ts +17 -0
  236. package/validation/rules/FieldsOnCorrectType.js +21 -57
  237. package/validation/rules/FieldsOnCorrectType.js.flow +7 -3
  238. package/validation/rules/FieldsOnCorrectType.mjs +21 -57
  239. package/validation/rules/FragmentsOnCompositeTypes.d.ts +20 -0
  240. package/validation/rules/FragmentsOnCompositeTypes.js.flow +5 -1
  241. package/validation/rules/KnownArgumentNames.d.ts +28 -0
  242. package/validation/rules/KnownArgumentNames.js +26 -79
  243. package/validation/rules/KnownArgumentNames.js.flow +10 -6
  244. package/validation/rules/KnownArgumentNames.mjs +22 -75
  245. package/validation/rules/KnownDirectives.d.ts +19 -0
  246. package/validation/rules/KnownDirectives.js +12 -48
  247. package/validation/rules/KnownDirectives.js.flow +8 -5
  248. package/validation/rules/KnownDirectives.mjs +12 -48
  249. package/validation/rules/KnownFragmentNames.d.ts +12 -0
  250. package/validation/rules/KnownFragmentNames.js.flow +2 -1
  251. package/validation/rules/KnownTypeNames.d.ts +15 -0
  252. package/validation/rules/KnownTypeNames.js +6 -24
  253. package/validation/rules/KnownTypeNames.js.flow +10 -6
  254. package/validation/rules/KnownTypeNames.mjs +6 -24
  255. package/validation/rules/LoneAnonymousOperation.d.ts +14 -0
  256. package/validation/rules/LoneAnonymousOperation.js.flow +3 -1
  257. package/validation/rules/LoneSchemaDefinition.d.ts +13 -0
  258. package/validation/rules/LoneSchemaDefinition.js.flow +2 -1
  259. package/validation/rules/NoFragmentCycles.d.ts +9 -0
  260. package/validation/rules/NoFragmentCycles.js +17 -35
  261. package/validation/rules/NoFragmentCycles.js.flow +4 -2
  262. package/validation/rules/NoFragmentCycles.mjs +17 -35
  263. package/validation/rules/NoUndefinedVariables.d.ts +16 -0
  264. package/validation/rules/NoUndefinedVariables.js +6 -24
  265. package/validation/rules/NoUndefinedVariables.js.flow +2 -1
  266. package/validation/rules/NoUndefinedVariables.mjs +6 -24
  267. package/validation/rules/NoUnusedFragments.d.ts +12 -0
  268. package/validation/rules/NoUnusedFragments.js +7 -25
  269. package/validation/rules/NoUnusedFragments.js.flow +2 -1
  270. package/validation/rules/NoUnusedFragments.mjs +7 -25
  271. package/validation/rules/NoUnusedVariables.d.ts +16 -0
  272. package/validation/rules/NoUnusedVariables.js +6 -24
  273. package/validation/rules/NoUnusedVariables.js.flow +2 -1
  274. package/validation/rules/NoUnusedVariables.mjs +6 -24
  275. package/validation/rules/OverlappingFieldsCanBeMerged.d.ts +24 -0
  276. package/validation/rules/OverlappingFieldsCanBeMerged.js +27 -46
  277. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +17 -8
  278. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +25 -44
  279. package/validation/rules/PossibleFragmentSpreads.d.ts +22 -0
  280. package/validation/rules/PossibleFragmentSpreads.js +2 -2
  281. package/validation/rules/PossibleFragmentSpreads.js.flow +8 -3
  282. package/validation/rules/PossibleFragmentSpreads.mjs +2 -2
  283. package/validation/rules/PossibleTypeExtensions.d.ts +21 -0
  284. package/validation/rules/PossibleTypeExtensions.js +4 -22
  285. package/validation/rules/PossibleTypeExtensions.js.flow +6 -2
  286. package/validation/rules/PossibleTypeExtensions.mjs +4 -22
  287. package/validation/rules/ProvidedRequiredArguments.d.ts +29 -0
  288. package/validation/rules/ProvidedRequiredArguments.js +27 -79
  289. package/validation/rules/ProvidedRequiredArguments.js.flow +12 -8
  290. package/validation/rules/ProvidedRequiredArguments.mjs +25 -77
  291. package/validation/rules/ScalarLeafs.d.ts +20 -0
  292. package/validation/rules/ScalarLeafs.js.flow +6 -2
  293. package/validation/rules/SingleFieldSubscriptions.d.ts +14 -0
  294. package/validation/rules/SingleFieldSubscriptions.js.flow +4 -2
  295. package/validation/rules/UniqueArgumentNames.d.ts +12 -0
  296. package/validation/rules/UniqueArgumentNames.js.flow +2 -1
  297. package/validation/rules/UniqueDirectiveNames.d.ts +13 -0
  298. package/validation/rules/UniqueDirectiveNames.js.flow +2 -1
  299. package/validation/rules/UniqueDirectivesPerLocation.d.ts +14 -0
  300. package/validation/rules/UniqueDirectivesPerLocation.js +15 -69
  301. package/validation/rules/UniqueDirectivesPerLocation.js.flow +7 -4
  302. package/validation/rules/UniqueDirectivesPerLocation.mjs +15 -69
  303. package/validation/rules/UniqueEnumValueNames.d.ts +19 -0
  304. package/validation/rules/UniqueEnumValueNames.js +10 -28
  305. package/validation/rules/UniqueEnumValueNames.js.flow +2 -1
  306. package/validation/rules/UniqueEnumValueNames.mjs +10 -28
  307. package/validation/rules/UniqueFieldDefinitionNames.d.ts +21 -0
  308. package/validation/rules/UniqueFieldDefinitionNames.js +9 -27
  309. package/validation/rules/UniqueFieldDefinitionNames.js.flow +2 -1
  310. package/validation/rules/UniqueFieldDefinitionNames.mjs +9 -27
  311. package/validation/rules/UniqueFragmentNames.d.ts +11 -0
  312. package/validation/rules/UniqueFragmentNames.js.flow +2 -1
  313. package/validation/rules/UniqueInputFieldNames.d.ts +14 -0
  314. package/validation/rules/UniqueInputFieldNames.js.flow +2 -1
  315. package/validation/rules/UniqueOperationNames.d.ts +11 -0
  316. package/validation/rules/UniqueOperationNames.js.flow +2 -1
  317. package/validation/rules/UniqueOperationTypes.d.ts +13 -0
  318. package/validation/rules/UniqueOperationTypes.js +11 -30
  319. package/validation/rules/UniqueOperationTypes.js.flow +2 -1
  320. package/validation/rules/UniqueOperationTypes.mjs +10 -29
  321. package/validation/rules/UniqueTypeNames.d.ts +13 -0
  322. package/validation/rules/UniqueTypeNames.js.flow +3 -1
  323. package/validation/rules/UniqueVariableNames.d.ts +11 -0
  324. package/validation/rules/UniqueVariableNames.js.flow +4 -2
  325. package/validation/rules/ValuesOfCorrectType.d.ts +34 -0
  326. package/validation/rules/ValuesOfCorrectType.js +16 -34
  327. package/validation/rules/ValuesOfCorrectType.js.flow +11 -6
  328. package/validation/rules/ValuesOfCorrectType.mjs +12 -30
  329. package/validation/rules/VariablesAreInputTypes.d.ts +15 -0
  330. package/validation/rules/VariablesAreInputTypes.js.flow +6 -2
  331. package/validation/rules/VariablesInAllowedPosition.d.ts +15 -0
  332. package/validation/rules/VariablesInAllowedPosition.js +22 -40
  333. package/validation/rules/VariablesInAllowedPosition.js.flow +8 -3
  334. package/validation/rules/VariablesInAllowedPosition.mjs +18 -36
  335. package/validation/specifiedRules.d.ts +98 -0
  336. package/validation/validate.d.ts +56 -0
  337. package/validation/validate.js +35 -7
  338. package/validation/validate.js.flow +51 -9
  339. package/validation/validate.mjs +30 -7
  340. package/version.d.ts +14 -0
  341. package/version.js +3 -3
  342. package/version.js.flow +3 -3
  343. package/version.mjs +3 -3
@@ -1,28 +1,20 @@
1
1
  import inspect from '../jsutils/inspect';
2
+ import devAssert from '../jsutils/devAssert';
2
3
  import defineToJSON from '../jsutils/defineToJSON';
3
- import { Source } from './source';
4
4
  import { syntaxError } from '../error/syntaxError';
5
- import { TokenKind } from './tokenKind';
6
- import { getTokenDesc, createLexer } from './lexer';
7
5
  import { Kind } from './kinds';
6
+ import { Source } from './source';
7
+ import { createLexer } from './lexer';
8
8
  import { DirectiveLocation } from './directiveLocation';
9
- /**
10
- * Configuration options to control parser behavior
11
- */
9
+ import { TokenKind } from './tokenKind';
12
10
 
13
11
  /**
14
12
  * Given a GraphQL source, parses it into a Document.
15
13
  * Throws GraphQLError if a syntax error is encountered.
16
14
  */
17
15
  export function parse(source, options) {
18
- var sourceObj = typeof source === 'string' ? new Source(source) : source;
19
-
20
- if (!(sourceObj instanceof Source)) {
21
- throw new TypeError("Must provide Source. Received: ".concat(inspect(sourceObj)));
22
- }
23
-
24
- var lexer = createLexer(sourceObj, options || {});
25
- return parseDocument(lexer);
16
+ var parser = new Parser(source, options);
17
+ return parser.parseDocument();
26
18
  }
27
19
  /**
28
20
  * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for
@@ -36,11 +28,10 @@ export function parse(source, options) {
36
28
  */
37
29
 
38
30
  export function parseValue(source, options) {
39
- var sourceObj = typeof source === 'string' ? new Source(source) : source;
40
- var lexer = createLexer(sourceObj, options || {});
41
- expectToken(lexer, TokenKind.SOF);
42
- var value = parseValueLiteral(lexer, false);
43
- expectToken(lexer, TokenKind.EOF);
31
+ var parser = new Parser(source, options);
32
+ parser.expectToken(TokenKind.SOF);
33
+ var value = parser.parseValueLiteral(false);
34
+ parser.expectToken(TokenKind.EOF);
44
35
  return value;
45
36
  }
46
37
  /**
@@ -55,1316 +46,1462 @@ export function parseValue(source, options) {
55
46
  */
56
47
 
57
48
  export function parseType(source, options) {
58
- var sourceObj = typeof source === 'string' ? new Source(source) : source;
59
- var lexer = createLexer(sourceObj, options || {});
60
- expectToken(lexer, TokenKind.SOF);
61
- var type = parseTypeReference(lexer);
62
- expectToken(lexer, TokenKind.EOF);
49
+ var parser = new Parser(source, options);
50
+ parser.expectToken(TokenKind.SOF);
51
+ var type = parser.parseTypeReference();
52
+ parser.expectToken(TokenKind.EOF);
63
53
  return type;
64
54
  }
65
- /**
66
- * Converts a name lex token into a name parse node.
67
- */
68
55
 
69
- function parseName(lexer) {
70
- var token = expectToken(lexer, TokenKind.NAME);
71
- return {
72
- kind: Kind.NAME,
73
- value: token.value,
74
- loc: loc(lexer, token)
75
- };
76
- } // Implements the parsing rules in the Document section.
56
+ var Parser =
57
+ /*#__PURE__*/
58
+ function () {
59
+ function Parser(source, options) {
60
+ var sourceObj = typeof source === 'string' ? new Source(source) : source;
61
+ sourceObj instanceof Source || devAssert(0, "Must provide Source. Received: ".concat(inspect(sourceObj)));
62
+ this._lexer = createLexer(sourceObj);
63
+ this._options = options || {};
64
+ }
65
+ /**
66
+ * Converts a name lex token into a name parse node.
67
+ */
77
68
 
78
- /**
79
- * Document : Definition+
80
- */
81
69
 
70
+ var _proto = Parser.prototype;
82
71
 
83
- function parseDocument(lexer) {
84
- var start = lexer.token;
85
- return {
86
- kind: Kind.DOCUMENT,
87
- definitions: many(lexer, TokenKind.SOF, parseDefinition, TokenKind.EOF),
88
- loc: loc(lexer, start)
89
- };
90
- }
91
- /**
92
- * Definition :
93
- * - ExecutableDefinition
94
- * - TypeSystemDefinition
95
- * - TypeSystemExtension
96
- */
72
+ _proto.parseName = function parseName() {
73
+ var token = this.expectToken(TokenKind.NAME);
74
+ return {
75
+ kind: Kind.NAME,
76
+ value: token.value,
77
+ loc: this.loc(token)
78
+ };
79
+ } // Implements the parsing rules in the Document section.
97
80
 
81
+ /**
82
+ * Document : Definition+
83
+ */
84
+ ;
98
85
 
99
- function parseDefinition(lexer) {
100
- if (peek(lexer, TokenKind.NAME)) {
101
- switch (lexer.token.value) {
102
- case 'query':
103
- case 'mutation':
104
- case 'subscription':
105
- case 'fragment':
106
- return parseExecutableDefinition(lexer);
107
-
108
- case 'schema':
109
- case 'scalar':
110
- case 'type':
111
- case 'interface':
112
- case 'union':
113
- case 'enum':
114
- case 'input':
115
- case 'directive':
116
- return parseTypeSystemDefinition(lexer);
117
-
118
- case 'extend':
119
- return parseTypeSystemExtension(lexer);
120
- }
121
- } else if (peek(lexer, TokenKind.BRACE_L)) {
122
- return parseExecutableDefinition(lexer);
123
- } else if (peekDescription(lexer)) {
124
- return parseTypeSystemDefinition(lexer);
86
+ _proto.parseDocument = function parseDocument() {
87
+ var start = this._lexer.token;
88
+ return {
89
+ kind: Kind.DOCUMENT,
90
+ definitions: this.many(TokenKind.SOF, this.parseDefinition, TokenKind.EOF),
91
+ loc: this.loc(start)
92
+ };
125
93
  }
94
+ /**
95
+ * Definition :
96
+ * - ExecutableDefinition
97
+ * - TypeSystemDefinition
98
+ * - TypeSystemExtension
99
+ *
100
+ * ExecutableDefinition :
101
+ * - OperationDefinition
102
+ * - FragmentDefinition
103
+ */
104
+ ;
105
+
106
+ _proto.parseDefinition = function parseDefinition() {
107
+ if (this.peek(TokenKind.NAME)) {
108
+ switch (this._lexer.token.value) {
109
+ case 'query':
110
+ case 'mutation':
111
+ case 'subscription':
112
+ return this.parseOperationDefinition();
113
+
114
+ case 'fragment':
115
+ return this.parseFragmentDefinition();
116
+
117
+ case 'schema':
118
+ case 'scalar':
119
+ case 'type':
120
+ case 'interface':
121
+ case 'union':
122
+ case 'enum':
123
+ case 'input':
124
+ case 'directive':
125
+ return this.parseTypeSystemDefinition();
126
+
127
+ case 'extend':
128
+ return this.parseTypeSystemExtension();
129
+ }
130
+ } else if (this.peek(TokenKind.BRACE_L)) {
131
+ return this.parseOperationDefinition();
132
+ } else if (this.peekDescription()) {
133
+ return this.parseTypeSystemDefinition();
134
+ }
126
135
 
127
- throw unexpected(lexer);
128
- }
129
- /**
130
- * ExecutableDefinition :
131
- * - OperationDefinition
132
- * - FragmentDefinition
133
- */
136
+ throw this.unexpected();
137
+ } // Implements the parsing rules in the Operations section.
134
138
 
139
+ /**
140
+ * OperationDefinition :
141
+ * - SelectionSet
142
+ * - OperationType Name? VariableDefinitions? Directives? SelectionSet
143
+ */
144
+ ;
135
145
 
136
- function parseExecutableDefinition(lexer) {
137
- if (peek(lexer, TokenKind.NAME)) {
138
- switch (lexer.token.value) {
139
- case 'query':
140
- case 'mutation':
141
- case 'subscription':
142
- return parseOperationDefinition(lexer);
146
+ _proto.parseOperationDefinition = function parseOperationDefinition() {
147
+ var start = this._lexer.token;
143
148
 
144
- case 'fragment':
145
- return parseFragmentDefinition(lexer);
149
+ if (this.peek(TokenKind.BRACE_L)) {
150
+ return {
151
+ kind: Kind.OPERATION_DEFINITION,
152
+ operation: 'query',
153
+ name: undefined,
154
+ variableDefinitions: [],
155
+ directives: [],
156
+ selectionSet: this.parseSelectionSet(),
157
+ loc: this.loc(start)
158
+ };
146
159
  }
147
- } else if (peek(lexer, TokenKind.BRACE_L)) {
148
- return parseOperationDefinition(lexer);
149
- }
150
160
 
151
- throw unexpected(lexer);
152
- } // Implements the parsing rules in the Operations section.
161
+ var operation = this.parseOperationType();
162
+ var name;
153
163
 
154
- /**
155
- * OperationDefinition :
156
- * - SelectionSet
157
- * - OperationType Name? VariableDefinitions? Directives? SelectionSet
158
- */
159
-
160
-
161
- function parseOperationDefinition(lexer) {
162
- var start = lexer.token;
164
+ if (this.peek(TokenKind.NAME)) {
165
+ name = this.parseName();
166
+ }
163
167
 
164
- if (peek(lexer, TokenKind.BRACE_L)) {
165
168
  return {
166
169
  kind: Kind.OPERATION_DEFINITION,
167
- operation: 'query',
168
- name: undefined,
169
- variableDefinitions: [],
170
- directives: [],
171
- selectionSet: parseSelectionSet(lexer),
172
- loc: loc(lexer, start)
170
+ operation: operation,
171
+ name: name,
172
+ variableDefinitions: this.parseVariableDefinitions(),
173
+ directives: this.parseDirectives(false),
174
+ selectionSet: this.parseSelectionSet(),
175
+ loc: this.loc(start)
173
176
  };
174
177
  }
178
+ /**
179
+ * OperationType : one of query mutation subscription
180
+ */
181
+ ;
175
182
 
176
- var operation = parseOperationType(lexer);
177
- var name;
178
-
179
- if (peek(lexer, TokenKind.NAME)) {
180
- name = parseName(lexer);
181
- }
182
-
183
- return {
184
- kind: Kind.OPERATION_DEFINITION,
185
- operation: operation,
186
- name: name,
187
- variableDefinitions: parseVariableDefinitions(lexer),
188
- directives: parseDirectives(lexer, false),
189
- selectionSet: parseSelectionSet(lexer),
190
- loc: loc(lexer, start)
191
- };
192
- }
193
- /**
194
- * OperationType : one of query mutation subscription
195
- */
196
-
183
+ _proto.parseOperationType = function parseOperationType() {
184
+ var operationToken = this.expectToken(TokenKind.NAME);
197
185
 
198
- function parseOperationType(lexer) {
199
- var operationToken = expectToken(lexer, TokenKind.NAME);
186
+ switch (operationToken.value) {
187
+ case 'query':
188
+ return 'query';
200
189
 
201
- switch (operationToken.value) {
202
- case 'query':
203
- return 'query';
190
+ case 'mutation':
191
+ return 'mutation';
204
192
 
205
- case 'mutation':
206
- return 'mutation';
193
+ case 'subscription':
194
+ return 'subscription';
195
+ }
207
196
 
208
- case 'subscription':
209
- return 'subscription';
197
+ throw this.unexpected(operationToken);
210
198
  }
199
+ /**
200
+ * VariableDefinitions : ( VariableDefinition+ )
201
+ */
202
+ ;
211
203
 
212
- throw unexpected(lexer, operationToken);
213
- }
214
- /**
215
- * VariableDefinitions : ( VariableDefinition+ )
216
- */
217
-
204
+ _proto.parseVariableDefinitions = function parseVariableDefinitions() {
205
+ return this.optionalMany(TokenKind.PAREN_L, this.parseVariableDefinition, TokenKind.PAREN_R);
206
+ }
207
+ /**
208
+ * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
209
+ */
210
+ ;
218
211
 
219
- function parseVariableDefinitions(lexer) {
220
- return peek(lexer, TokenKind.PAREN_L) ? many(lexer, TokenKind.PAREN_L, parseVariableDefinition, TokenKind.PAREN_R) : [];
221
- }
222
- /**
223
- * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
224
- */
212
+ _proto.parseVariableDefinition = function parseVariableDefinition() {
213
+ var start = this._lexer.token;
214
+ return {
215
+ kind: Kind.VARIABLE_DEFINITION,
216
+ variable: this.parseVariable(),
217
+ type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
218
+ defaultValue: this.expectOptionalToken(TokenKind.EQUALS) ? this.parseValueLiteral(true) : undefined,
219
+ directives: this.parseDirectives(true),
220
+ loc: this.loc(start)
221
+ };
222
+ }
223
+ /**
224
+ * Variable : $ Name
225
+ */
226
+ ;
227
+
228
+ _proto.parseVariable = function parseVariable() {
229
+ var start = this._lexer.token;
230
+ this.expectToken(TokenKind.DOLLAR);
231
+ return {
232
+ kind: Kind.VARIABLE,
233
+ name: this.parseName(),
234
+ loc: this.loc(start)
235
+ };
236
+ }
237
+ /**
238
+ * SelectionSet : { Selection+ }
239
+ */
240
+ ;
225
241
 
242
+ _proto.parseSelectionSet = function parseSelectionSet() {
243
+ var start = this._lexer.token;
244
+ return {
245
+ kind: Kind.SELECTION_SET,
246
+ selections: this.many(TokenKind.BRACE_L, this.parseSelection, TokenKind.BRACE_R),
247
+ loc: this.loc(start)
248
+ };
249
+ }
250
+ /**
251
+ * Selection :
252
+ * - Field
253
+ * - FragmentSpread
254
+ * - InlineFragment
255
+ */
256
+ ;
257
+
258
+ _proto.parseSelection = function parseSelection() {
259
+ return this.peek(TokenKind.SPREAD) ? this.parseFragment() : this.parseField();
260
+ }
261
+ /**
262
+ * Field : Alias? Name Arguments? Directives? SelectionSet?
263
+ *
264
+ * Alias : Name :
265
+ */
266
+ ;
267
+
268
+ _proto.parseField = function parseField() {
269
+ var start = this._lexer.token;
270
+ var nameOrAlias = this.parseName();
271
+ var alias;
272
+ var name;
273
+
274
+ if (this.expectOptionalToken(TokenKind.COLON)) {
275
+ alias = nameOrAlias;
276
+ name = this.parseName();
277
+ } else {
278
+ name = nameOrAlias;
279
+ }
226
280
 
227
- function parseVariableDefinition(lexer) {
228
- var start = lexer.token;
229
- return {
230
- kind: Kind.VARIABLE_DEFINITION,
231
- variable: parseVariable(lexer),
232
- type: (expectToken(lexer, TokenKind.COLON), parseTypeReference(lexer)),
233
- defaultValue: expectOptionalToken(lexer, TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined,
234
- directives: parseDirectives(lexer, true),
235
- loc: loc(lexer, start)
281
+ return {
282
+ kind: Kind.FIELD,
283
+ alias: alias,
284
+ name: name,
285
+ arguments: this.parseArguments(false),
286
+ directives: this.parseDirectives(false),
287
+ selectionSet: this.peek(TokenKind.BRACE_L) ? this.parseSelectionSet() : undefined,
288
+ loc: this.loc(start)
289
+ };
290
+ }
291
+ /**
292
+ * Arguments[Const] : ( Argument[?Const]+ )
293
+ */
294
+ ;
295
+
296
+ _proto.parseArguments = function parseArguments(isConst) {
297
+ var item = isConst ? this.parseConstArgument : this.parseArgument;
298
+ return this.optionalMany(TokenKind.PAREN_L, item, TokenKind.PAREN_R);
299
+ }
300
+ /**
301
+ * Argument[Const] : Name : Value[?Const]
302
+ */
303
+ ;
304
+
305
+ _proto.parseArgument = function parseArgument() {
306
+ var start = this._lexer.token;
307
+ var name = this.parseName();
308
+ this.expectToken(TokenKind.COLON);
309
+ return {
310
+ kind: Kind.ARGUMENT,
311
+ name: name,
312
+ value: this.parseValueLiteral(false),
313
+ loc: this.loc(start)
314
+ };
236
315
  };
237
- }
238
- /**
239
- * Variable : $ Name
240
- */
241
316
 
317
+ _proto.parseConstArgument = function parseConstArgument() {
318
+ var start = this._lexer.token;
319
+ return {
320
+ kind: Kind.ARGUMENT,
321
+ name: this.parseName(),
322
+ value: (this.expectToken(TokenKind.COLON), this.parseValueLiteral(true)),
323
+ loc: this.loc(start)
324
+ };
325
+ } // Implements the parsing rules in the Fragments section.
326
+
327
+ /**
328
+ * Corresponds to both FragmentSpread and InlineFragment in the spec.
329
+ *
330
+ * FragmentSpread : ... FragmentName Directives?
331
+ *
332
+ * InlineFragment : ... TypeCondition? Directives? SelectionSet
333
+ */
334
+ ;
335
+
336
+ _proto.parseFragment = function parseFragment() {
337
+ var start = this._lexer.token;
338
+ this.expectToken(TokenKind.SPREAD);
339
+ var hasTypeCondition = this.expectOptionalKeyword('on');
340
+
341
+ if (!hasTypeCondition && this.peek(TokenKind.NAME)) {
342
+ return {
343
+ kind: Kind.FRAGMENT_SPREAD,
344
+ name: this.parseFragmentName(),
345
+ directives: this.parseDirectives(false),
346
+ loc: this.loc(start)
347
+ };
348
+ }
242
349
 
243
- function parseVariable(lexer) {
244
- var start = lexer.token;
245
- expectToken(lexer, TokenKind.DOLLAR);
246
- return {
247
- kind: Kind.VARIABLE,
248
- name: parseName(lexer),
249
- loc: loc(lexer, start)
250
- };
251
- }
252
- /**
253
- * SelectionSet : { Selection+ }
254
- */
350
+ return {
351
+ kind: Kind.INLINE_FRAGMENT,
352
+ typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
353
+ directives: this.parseDirectives(false),
354
+ selectionSet: this.parseSelectionSet(),
355
+ loc: this.loc(start)
356
+ };
357
+ }
358
+ /**
359
+ * FragmentDefinition :
360
+ * - fragment FragmentName on TypeCondition Directives? SelectionSet
361
+ *
362
+ * TypeCondition : NamedType
363
+ */
364
+ ;
365
+
366
+ _proto.parseFragmentDefinition = function parseFragmentDefinition() {
367
+ var start = this._lexer.token;
368
+ this.expectKeyword('fragment'); // Experimental support for defining variables within fragments changes
369
+ // the grammar of FragmentDefinition:
370
+ // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
371
+
372
+ if (this._options.experimentalFragmentVariables) {
373
+ return {
374
+ kind: Kind.FRAGMENT_DEFINITION,
375
+ name: this.parseFragmentName(),
376
+ variableDefinitions: this.parseVariableDefinitions(),
377
+ typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
378
+ directives: this.parseDirectives(false),
379
+ selectionSet: this.parseSelectionSet(),
380
+ loc: this.loc(start)
381
+ };
382
+ }
255
383
 
384
+ return {
385
+ kind: Kind.FRAGMENT_DEFINITION,
386
+ name: this.parseFragmentName(),
387
+ typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
388
+ directives: this.parseDirectives(false),
389
+ selectionSet: this.parseSelectionSet(),
390
+ loc: this.loc(start)
391
+ };
392
+ }
393
+ /**
394
+ * FragmentName : Name but not `on`
395
+ */
396
+ ;
397
+
398
+ _proto.parseFragmentName = function parseFragmentName() {
399
+ if (this._lexer.token.value === 'on') {
400
+ throw this.unexpected();
401
+ }
256
402
 
257
- function parseSelectionSet(lexer) {
258
- var start = lexer.token;
259
- return {
260
- kind: Kind.SELECTION_SET,
261
- selections: many(lexer, TokenKind.BRACE_L, parseSelection, TokenKind.BRACE_R),
262
- loc: loc(lexer, start)
263
- };
264
- }
265
- /**
266
- * Selection :
267
- * - Field
268
- * - FragmentSpread
269
- * - InlineFragment
270
- */
403
+ return this.parseName();
404
+ } // Implements the parsing rules in the Values section.
405
+
406
+ /**
407
+ * Value[Const] :
408
+ * - [~Const] Variable
409
+ * - IntValue
410
+ * - FloatValue
411
+ * - StringValue
412
+ * - BooleanValue
413
+ * - NullValue
414
+ * - EnumValue
415
+ * - ListValue[?Const]
416
+ * - ObjectValue[?Const]
417
+ *
418
+ * BooleanValue : one of `true` `false`
419
+ *
420
+ * NullValue : `null`
421
+ *
422
+ * EnumValue : Name but not `true`, `false` or `null`
423
+ */
424
+ ;
425
+
426
+ _proto.parseValueLiteral = function parseValueLiteral(isConst) {
427
+ var token = this._lexer.token;
428
+
429
+ switch (token.kind) {
430
+ case TokenKind.BRACKET_L:
431
+ return this.parseList(isConst);
432
+
433
+ case TokenKind.BRACE_L:
434
+ return this.parseObject(isConst);
435
+
436
+ case TokenKind.INT:
437
+ this._lexer.advance();
271
438
 
439
+ return {
440
+ kind: Kind.INT,
441
+ value: token.value,
442
+ loc: this.loc(token)
443
+ };
272
444
 
273
- function parseSelection(lexer) {
274
- return peek(lexer, TokenKind.SPREAD) ? parseFragment(lexer) : parseField(lexer);
275
- }
276
- /**
277
- * Field : Alias? Name Arguments? Directives? SelectionSet?
278
- *
279
- * Alias : Name :
280
- */
445
+ case TokenKind.FLOAT:
446
+ this._lexer.advance();
281
447
 
448
+ return {
449
+ kind: Kind.FLOAT,
450
+ value: token.value,
451
+ loc: this.loc(token)
452
+ };
282
453
 
283
- function parseField(lexer) {
284
- var start = lexer.token;
285
- var nameOrAlias = parseName(lexer);
286
- var alias;
287
- var name;
454
+ case TokenKind.STRING:
455
+ case TokenKind.BLOCK_STRING:
456
+ return this.parseStringLiteral();
288
457
 
289
- if (expectOptionalToken(lexer, TokenKind.COLON)) {
290
- alias = nameOrAlias;
291
- name = parseName(lexer);
292
- } else {
293
- name = nameOrAlias;
294
- }
458
+ case TokenKind.NAME:
459
+ if (token.value === 'true' || token.value === 'false') {
460
+ this._lexer.advance();
295
461
 
296
- return {
297
- kind: Kind.FIELD,
298
- alias: alias,
299
- name: name,
300
- arguments: parseArguments(lexer, false),
301
- directives: parseDirectives(lexer, false),
302
- selectionSet: peek(lexer, TokenKind.BRACE_L) ? parseSelectionSet(lexer) : undefined,
303
- loc: loc(lexer, start)
304
- };
305
- }
306
- /**
307
- * Arguments[Const] : ( Argument[?Const]+ )
308
- */
462
+ return {
463
+ kind: Kind.BOOLEAN,
464
+ value: token.value === 'true',
465
+ loc: this.loc(token)
466
+ };
467
+ } else if (token.value === 'null') {
468
+ this._lexer.advance();
309
469
 
470
+ return {
471
+ kind: Kind.NULL,
472
+ loc: this.loc(token)
473
+ };
474
+ }
310
475
 
311
- function parseArguments(lexer, isConst) {
312
- var item = isConst ? parseConstArgument : parseArgument;
313
- return peek(lexer, TokenKind.PAREN_L) ? many(lexer, TokenKind.PAREN_L, item, TokenKind.PAREN_R) : [];
314
- }
315
- /**
316
- * Argument[Const] : Name : Value[?Const]
317
- */
476
+ this._lexer.advance();
318
477
 
478
+ return {
479
+ kind: Kind.ENUM,
480
+ value: token.value,
481
+ loc: this.loc(token)
482
+ };
319
483
 
320
- function parseArgument(lexer) {
321
- var start = lexer.token;
322
- var name = parseName(lexer);
323
- expectToken(lexer, TokenKind.COLON);
324
- return {
325
- kind: Kind.ARGUMENT,
326
- name: name,
327
- value: parseValueLiteral(lexer, false),
328
- loc: loc(lexer, start)
329
- };
330
- }
484
+ case TokenKind.DOLLAR:
485
+ if (!isConst) {
486
+ return this.parseVariable();
487
+ }
331
488
 
332
- function parseConstArgument(lexer) {
333
- var start = lexer.token;
334
- return {
335
- kind: Kind.ARGUMENT,
336
- name: parseName(lexer),
337
- value: (expectToken(lexer, TokenKind.COLON), parseConstValue(lexer)),
338
- loc: loc(lexer, start)
339
- };
340
- } // Implements the parsing rules in the Fragments section.
489
+ break;
490
+ }
341
491
 
342
- /**
343
- * Corresponds to both FragmentSpread and InlineFragment in the spec.
344
- *
345
- * FragmentSpread : ... FragmentName Directives?
346
- *
347
- * InlineFragment : ... TypeCondition? Directives? SelectionSet
348
- */
492
+ throw this.unexpected();
493
+ };
349
494
 
495
+ _proto.parseStringLiteral = function parseStringLiteral() {
496
+ var token = this._lexer.token;
350
497
 
351
- function parseFragment(lexer) {
352
- var start = lexer.token;
353
- expectToken(lexer, TokenKind.SPREAD);
354
- var hasTypeCondition = expectOptionalKeyword(lexer, 'on');
498
+ this._lexer.advance();
355
499
 
356
- if (!hasTypeCondition && peek(lexer, TokenKind.NAME)) {
357
500
  return {
358
- kind: Kind.FRAGMENT_SPREAD,
359
- name: parseFragmentName(lexer),
360
- directives: parseDirectives(lexer, false),
361
- loc: loc(lexer, start)
501
+ kind: Kind.STRING,
502
+ value: token.value,
503
+ block: token.kind === TokenKind.BLOCK_STRING,
504
+ loc: this.loc(token)
362
505
  };
363
506
  }
507
+ /**
508
+ * ListValue[Const] :
509
+ * - [ ]
510
+ * - [ Value[?Const]+ ]
511
+ */
512
+ ;
364
513
 
365
- return {
366
- kind: Kind.INLINE_FRAGMENT,
367
- typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
368
- directives: parseDirectives(lexer, false),
369
- selectionSet: parseSelectionSet(lexer),
370
- loc: loc(lexer, start)
371
- };
372
- }
373
- /**
374
- * FragmentDefinition :
375
- * - fragment FragmentName on TypeCondition Directives? SelectionSet
376
- *
377
- * TypeCondition : NamedType
378
- */
514
+ _proto.parseList = function parseList(isConst) {
515
+ var _this = this;
379
516
 
517
+ var start = this._lexer.token;
380
518
 
381
- function parseFragmentDefinition(lexer) {
382
- var start = lexer.token;
383
- expectKeyword(lexer, 'fragment'); // Experimental support for defining variables within fragments changes
384
- // the grammar of FragmentDefinition:
385
- // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
519
+ var item = function item() {
520
+ return _this.parseValueLiteral(isConst);
521
+ };
386
522
 
387
- if (lexer.options.experimentalFragmentVariables) {
388
523
  return {
389
- kind: Kind.FRAGMENT_DEFINITION,
390
- name: parseFragmentName(lexer),
391
- variableDefinitions: parseVariableDefinitions(lexer),
392
- typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)),
393
- directives: parseDirectives(lexer, false),
394
- selectionSet: parseSelectionSet(lexer),
395
- loc: loc(lexer, start)
524
+ kind: Kind.LIST,
525
+ values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),
526
+ loc: this.loc(start)
396
527
  };
397
528
  }
529
+ /**
530
+ * ObjectValue[Const] :
531
+ * - { }
532
+ * - { ObjectField[?Const]+ }
533
+ */
534
+ ;
398
535
 
399
- return {
400
- kind: Kind.FRAGMENT_DEFINITION,
401
- name: parseFragmentName(lexer),
402
- typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)),
403
- directives: parseDirectives(lexer, false),
404
- selectionSet: parseSelectionSet(lexer),
405
- loc: loc(lexer, start)
406
- };
407
- }
408
- /**
409
- * FragmentName : Name but not `on`
410
- */
411
-
412
-
413
- function parseFragmentName(lexer) {
414
- if (lexer.token.value === 'on') {
415
- throw unexpected(lexer);
416
- }
536
+ _proto.parseObject = function parseObject(isConst) {
537
+ var _this2 = this;
417
538
 
418
- return parseName(lexer);
419
- } // Implements the parsing rules in the Values section.
539
+ var start = this._lexer.token;
420
540
 
421
- /**
422
- * Value[Const] :
423
- * - [~Const] Variable
424
- * - IntValue
425
- * - FloatValue
426
- * - StringValue
427
- * - BooleanValue
428
- * - NullValue
429
- * - EnumValue
430
- * - ListValue[?Const]
431
- * - ObjectValue[?Const]
432
- *
433
- * BooleanValue : one of `true` `false`
434
- *
435
- * NullValue : `null`
436
- *
437
- * EnumValue : Name but not `true`, `false` or `null`
438
- */
541
+ var item = function item() {
542
+ return _this2.parseObjectField(isConst);
543
+ };
439
544
 
545
+ return {
546
+ kind: Kind.OBJECT,
547
+ fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R),
548
+ loc: this.loc(start)
549
+ };
550
+ }
551
+ /**
552
+ * ObjectField[Const] : Name : Value[?Const]
553
+ */
554
+ ;
555
+
556
+ _proto.parseObjectField = function parseObjectField(isConst) {
557
+ var start = this._lexer.token;
558
+ var name = this.parseName();
559
+ this.expectToken(TokenKind.COLON);
560
+ return {
561
+ kind: Kind.OBJECT_FIELD,
562
+ name: name,
563
+ value: this.parseValueLiteral(isConst),
564
+ loc: this.loc(start)
565
+ };
566
+ } // Implements the parsing rules in the Directives section.
440
567
 
441
- function parseValueLiteral(lexer, isConst) {
442
- var token = lexer.token;
568
+ /**
569
+ * Directives[Const] : Directive[?Const]+
570
+ */
571
+ ;
443
572
 
444
- switch (token.kind) {
445
- case TokenKind.BRACKET_L:
446
- return parseList(lexer, isConst);
573
+ _proto.parseDirectives = function parseDirectives(isConst) {
574
+ var directives = [];
447
575
 
448
- case TokenKind.BRACE_L:
449
- return parseObject(lexer, isConst);
576
+ while (this.peek(TokenKind.AT)) {
577
+ directives.push(this.parseDirective(isConst));
578
+ }
450
579
 
451
- case TokenKind.INT:
452
- lexer.advance();
453
- return {
454
- kind: Kind.INT,
455
- value: token.value,
456
- loc: loc(lexer, token)
580
+ return directives;
581
+ }
582
+ /**
583
+ * Directive[Const] : @ Name Arguments[?Const]?
584
+ */
585
+ ;
586
+
587
+ _proto.parseDirective = function parseDirective(isConst) {
588
+ var start = this._lexer.token;
589
+ this.expectToken(TokenKind.AT);
590
+ return {
591
+ kind: Kind.DIRECTIVE,
592
+ name: this.parseName(),
593
+ arguments: this.parseArguments(isConst),
594
+ loc: this.loc(start)
595
+ };
596
+ } // Implements the parsing rules in the Types section.
597
+
598
+ /**
599
+ * Type :
600
+ * - NamedType
601
+ * - ListType
602
+ * - NonNullType
603
+ */
604
+ ;
605
+
606
+ _proto.parseTypeReference = function parseTypeReference() {
607
+ var start = this._lexer.token;
608
+ var type;
609
+
610
+ if (this.expectOptionalToken(TokenKind.BRACKET_L)) {
611
+ type = this.parseTypeReference();
612
+ this.expectToken(TokenKind.BRACKET_R);
613
+ type = {
614
+ kind: Kind.LIST_TYPE,
615
+ type: type,
616
+ loc: this.loc(start)
457
617
  };
618
+ } else {
619
+ type = this.parseNamedType();
620
+ }
458
621
 
459
- case TokenKind.FLOAT:
460
- lexer.advance();
622
+ if (this.expectOptionalToken(TokenKind.BANG)) {
461
623
  return {
462
- kind: Kind.FLOAT,
463
- value: token.value,
464
- loc: loc(lexer, token)
624
+ kind: Kind.NON_NULL_TYPE,
625
+ type: type,
626
+ loc: this.loc(start)
465
627
  };
628
+ }
466
629
 
467
- case TokenKind.STRING:
468
- case TokenKind.BLOCK_STRING:
469
- return parseStringLiteral(lexer);
630
+ return type;
631
+ }
632
+ /**
633
+ * NamedType : Name
634
+ */
635
+ ;
470
636
 
471
- case TokenKind.NAME:
472
- if (token.value === 'true' || token.value === 'false') {
473
- lexer.advance();
474
- return {
475
- kind: Kind.BOOLEAN,
476
- value: token.value === 'true',
477
- loc: loc(lexer, token)
478
- };
479
- } else if (token.value === 'null') {
480
- lexer.advance();
481
- return {
482
- kind: Kind.NULL,
483
- loc: loc(lexer, token)
484
- };
637
+ _proto.parseNamedType = function parseNamedType() {
638
+ var start = this._lexer.token;
639
+ return {
640
+ kind: Kind.NAMED_TYPE,
641
+ name: this.parseName(),
642
+ loc: this.loc(start)
643
+ };
644
+ } // Implements the parsing rules in the Type Definition section.
645
+
646
+ /**
647
+ * TypeSystemDefinition :
648
+ * - SchemaDefinition
649
+ * - TypeDefinition
650
+ * - DirectiveDefinition
651
+ *
652
+ * TypeDefinition :
653
+ * - ScalarTypeDefinition
654
+ * - ObjectTypeDefinition
655
+ * - InterfaceTypeDefinition
656
+ * - UnionTypeDefinition
657
+ * - EnumTypeDefinition
658
+ * - InputObjectTypeDefinition
659
+ */
660
+ ;
661
+
662
+ _proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
663
+ // Many definitions begin with a description and require a lookahead.
664
+ var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
665
+
666
+ if (keywordToken.kind === TokenKind.NAME) {
667
+ switch (keywordToken.value) {
668
+ case 'schema':
669
+ return this.parseSchemaDefinition();
670
+
671
+ case 'scalar':
672
+ return this.parseScalarTypeDefinition();
673
+
674
+ case 'type':
675
+ return this.parseObjectTypeDefinition();
676
+
677
+ case 'interface':
678
+ return this.parseInterfaceTypeDefinition();
679
+
680
+ case 'union':
681
+ return this.parseUnionTypeDefinition();
682
+
683
+ case 'enum':
684
+ return this.parseEnumTypeDefinition();
685
+
686
+ case 'input':
687
+ return this.parseInputObjectTypeDefinition();
688
+
689
+ case 'directive':
690
+ return this.parseDirectiveDefinition();
485
691
  }
692
+ }
486
693
 
487
- lexer.advance();
488
- return {
489
- kind: Kind.ENUM,
490
- value: token.value,
491
- loc: loc(lexer, token)
492
- };
694
+ throw this.unexpected(keywordToken);
695
+ };
493
696
 
494
- case TokenKind.DOLLAR:
495
- if (!isConst) {
496
- return parseVariable(lexer);
497
- }
697
+ _proto.peekDescription = function peekDescription() {
698
+ return this.peek(TokenKind.STRING) || this.peek(TokenKind.BLOCK_STRING);
699
+ }
700
+ /**
701
+ * Description : StringValue
702
+ */
703
+ ;
704
+
705
+ _proto.parseDescription = function parseDescription() {
706
+ if (this.peekDescription()) {
707
+ return this.parseStringLiteral();
708
+ }
709
+ }
710
+ /**
711
+ * SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ }
712
+ */
713
+ ;
714
+
715
+ _proto.parseSchemaDefinition = function parseSchemaDefinition() {
716
+ var start = this._lexer.token;
717
+ this.expectKeyword('schema');
718
+ var directives = this.parseDirectives(true);
719
+ var operationTypes = this.many(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);
720
+ return {
721
+ kind: Kind.SCHEMA_DEFINITION,
722
+ directives: directives,
723
+ operationTypes: operationTypes,
724
+ loc: this.loc(start)
725
+ };
726
+ }
727
+ /**
728
+ * OperationTypeDefinition : OperationType : NamedType
729
+ */
730
+ ;
731
+
732
+ _proto.parseOperationTypeDefinition = function parseOperationTypeDefinition() {
733
+ var start = this._lexer.token;
734
+ var operation = this.parseOperationType();
735
+ this.expectToken(TokenKind.COLON);
736
+ var type = this.parseNamedType();
737
+ return {
738
+ kind: Kind.OPERATION_TYPE_DEFINITION,
739
+ operation: operation,
740
+ type: type,
741
+ loc: this.loc(start)
742
+ };
743
+ }
744
+ /**
745
+ * ScalarTypeDefinition : Description? scalar Name Directives[Const]?
746
+ */
747
+ ;
748
+
749
+ _proto.parseScalarTypeDefinition = function parseScalarTypeDefinition() {
750
+ var start = this._lexer.token;
751
+ var description = this.parseDescription();
752
+ this.expectKeyword('scalar');
753
+ var name = this.parseName();
754
+ var directives = this.parseDirectives(true);
755
+ return {
756
+ kind: Kind.SCALAR_TYPE_DEFINITION,
757
+ description: description,
758
+ name: name,
759
+ directives: directives,
760
+ loc: this.loc(start)
761
+ };
762
+ }
763
+ /**
764
+ * ObjectTypeDefinition :
765
+ * Description?
766
+ * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
767
+ */
768
+ ;
769
+
770
+ _proto.parseObjectTypeDefinition = function parseObjectTypeDefinition() {
771
+ var start = this._lexer.token;
772
+ var description = this.parseDescription();
773
+ this.expectKeyword('type');
774
+ var name = this.parseName();
775
+ var interfaces = this.parseImplementsInterfaces();
776
+ var directives = this.parseDirectives(true);
777
+ var fields = this.parseFieldsDefinition();
778
+ return {
779
+ kind: Kind.OBJECT_TYPE_DEFINITION,
780
+ description: description,
781
+ name: name,
782
+ interfaces: interfaces,
783
+ directives: directives,
784
+ fields: fields,
785
+ loc: this.loc(start)
786
+ };
787
+ }
788
+ /**
789
+ * ImplementsInterfaces :
790
+ * - implements `&`? NamedType
791
+ * - ImplementsInterfaces & NamedType
792
+ */
793
+ ;
794
+
795
+ _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
796
+ var types = [];
797
+
798
+ if (this.expectOptionalKeyword('implements')) {
799
+ // Optional leading ampersand
800
+ this.expectOptionalToken(TokenKind.AMP);
801
+
802
+ do {
803
+ types.push(this.parseNamedType());
804
+ } while (this.expectOptionalToken(TokenKind.AMP) || // Legacy support for the SDL?
805
+ this._options.allowLegacySDLImplementsInterfaces && this.peek(TokenKind.NAME));
806
+ }
498
807
 
499
- break;
808
+ return types;
500
809
  }
810
+ /**
811
+ * FieldsDefinition : { FieldDefinition+ }
812
+ */
813
+ ;
501
814
 
502
- throw unexpected(lexer);
503
- }
815
+ _proto.parseFieldsDefinition = function parseFieldsDefinition() {
816
+ // Legacy support for the SDL?
817
+ if (this._options.allowLegacySDLEmptyFields && this.peek(TokenKind.BRACE_L) && this._lexer.lookahead().kind === TokenKind.BRACE_R) {
818
+ this._lexer.advance();
504
819
 
505
- function parseStringLiteral(lexer) {
506
- var token = lexer.token;
507
- lexer.advance();
508
- return {
509
- kind: Kind.STRING,
510
- value: token.value,
511
- block: token.kind === TokenKind.BLOCK_STRING,
512
- loc: loc(lexer, token)
513
- };
514
- }
820
+ this._lexer.advance();
515
821
 
516
- export function parseConstValue(lexer) {
517
- return parseValueLiteral(lexer, true);
518
- }
822
+ return [];
823
+ }
519
824
 
520
- function parseValueValue(lexer) {
521
- return parseValueLiteral(lexer, false);
522
- }
523
- /**
524
- * ListValue[Const] :
525
- * - [ ]
526
- * - [ Value[?Const]+ ]
527
- */
825
+ return this.optionalMany(TokenKind.BRACE_L, this.parseFieldDefinition, TokenKind.BRACE_R);
826
+ }
827
+ /**
828
+ * FieldDefinition :
829
+ * - Description? Name ArgumentsDefinition? : Type Directives[Const]?
830
+ */
831
+ ;
832
+
833
+ _proto.parseFieldDefinition = function parseFieldDefinition() {
834
+ var start = this._lexer.token;
835
+ var description = this.parseDescription();
836
+ var name = this.parseName();
837
+ var args = this.parseArgumentDefs();
838
+ this.expectToken(TokenKind.COLON);
839
+ var type = this.parseTypeReference();
840
+ var directives = this.parseDirectives(true);
841
+ return {
842
+ kind: Kind.FIELD_DEFINITION,
843
+ description: description,
844
+ name: name,
845
+ arguments: args,
846
+ type: type,
847
+ directives: directives,
848
+ loc: this.loc(start)
849
+ };
850
+ }
851
+ /**
852
+ * ArgumentsDefinition : ( InputValueDefinition+ )
853
+ */
854
+ ;
528
855
 
856
+ _proto.parseArgumentDefs = function parseArgumentDefs() {
857
+ return this.optionalMany(TokenKind.PAREN_L, this.parseInputValueDef, TokenKind.PAREN_R);
858
+ }
859
+ /**
860
+ * InputValueDefinition :
861
+ * - Description? Name : Type DefaultValue? Directives[Const]?
862
+ */
863
+ ;
864
+
865
+ _proto.parseInputValueDef = function parseInputValueDef() {
866
+ var start = this._lexer.token;
867
+ var description = this.parseDescription();
868
+ var name = this.parseName();
869
+ this.expectToken(TokenKind.COLON);
870
+ var type = this.parseTypeReference();
871
+ var defaultValue;
872
+
873
+ if (this.expectOptionalToken(TokenKind.EQUALS)) {
874
+ defaultValue = this.parseValueLiteral(true);
875
+ }
529
876
 
530
- function parseList(lexer, isConst) {
531
- var start = lexer.token;
532
- var item = isConst ? parseConstValue : parseValueValue;
533
- return {
534
- kind: Kind.LIST,
535
- values: any(lexer, TokenKind.BRACKET_L, item, TokenKind.BRACKET_R),
536
- loc: loc(lexer, start)
537
- };
538
- }
539
- /**
540
- * ObjectValue[Const] :
541
- * - { }
542
- * - { ObjectField[?Const]+ }
543
- */
877
+ var directives = this.parseDirectives(true);
878
+ return {
879
+ kind: Kind.INPUT_VALUE_DEFINITION,
880
+ description: description,
881
+ name: name,
882
+ type: type,
883
+ defaultValue: defaultValue,
884
+ directives: directives,
885
+ loc: this.loc(start)
886
+ };
887
+ }
888
+ /**
889
+ * InterfaceTypeDefinition :
890
+ * - Description? interface Name Directives[Const]? FieldsDefinition?
891
+ */
892
+ ;
893
+
894
+ _proto.parseInterfaceTypeDefinition = function parseInterfaceTypeDefinition() {
895
+ var start = this._lexer.token;
896
+ var description = this.parseDescription();
897
+ this.expectKeyword('interface');
898
+ var name = this.parseName();
899
+ var directives = this.parseDirectives(true);
900
+ var fields = this.parseFieldsDefinition();
901
+ return {
902
+ kind: Kind.INTERFACE_TYPE_DEFINITION,
903
+ description: description,
904
+ name: name,
905
+ directives: directives,
906
+ fields: fields,
907
+ loc: this.loc(start)
908
+ };
909
+ }
910
+ /**
911
+ * UnionTypeDefinition :
912
+ * - Description? union Name Directives[Const]? UnionMemberTypes?
913
+ */
914
+ ;
915
+
916
+ _proto.parseUnionTypeDefinition = function parseUnionTypeDefinition() {
917
+ var start = this._lexer.token;
918
+ var description = this.parseDescription();
919
+ this.expectKeyword('union');
920
+ var name = this.parseName();
921
+ var directives = this.parseDirectives(true);
922
+ var types = this.parseUnionMemberTypes();
923
+ return {
924
+ kind: Kind.UNION_TYPE_DEFINITION,
925
+ description: description,
926
+ name: name,
927
+ directives: directives,
928
+ types: types,
929
+ loc: this.loc(start)
930
+ };
931
+ }
932
+ /**
933
+ * UnionMemberTypes :
934
+ * - = `|`? NamedType
935
+ * - UnionMemberTypes | NamedType
936
+ */
937
+ ;
938
+
939
+ _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
940
+ var types = [];
941
+
942
+ if (this.expectOptionalToken(TokenKind.EQUALS)) {
943
+ // Optional leading pipe
944
+ this.expectOptionalToken(TokenKind.PIPE);
945
+
946
+ do {
947
+ types.push(this.parseNamedType());
948
+ } while (this.expectOptionalToken(TokenKind.PIPE));
949
+ }
544
950
 
951
+ return types;
952
+ }
953
+ /**
954
+ * EnumTypeDefinition :
955
+ * - Description? enum Name Directives[Const]? EnumValuesDefinition?
956
+ */
957
+ ;
958
+
959
+ _proto.parseEnumTypeDefinition = function parseEnumTypeDefinition() {
960
+ var start = this._lexer.token;
961
+ var description = this.parseDescription();
962
+ this.expectKeyword('enum');
963
+ var name = this.parseName();
964
+ var directives = this.parseDirectives(true);
965
+ var values = this.parseEnumValuesDefinition();
966
+ return {
967
+ kind: Kind.ENUM_TYPE_DEFINITION,
968
+ description: description,
969
+ name: name,
970
+ directives: directives,
971
+ values: values,
972
+ loc: this.loc(start)
973
+ };
974
+ }
975
+ /**
976
+ * EnumValuesDefinition : { EnumValueDefinition+ }
977
+ */
978
+ ;
545
979
 
546
- function parseObject(lexer, isConst) {
547
- var start = lexer.token;
980
+ _proto.parseEnumValuesDefinition = function parseEnumValuesDefinition() {
981
+ return this.optionalMany(TokenKind.BRACE_L, this.parseEnumValueDefinition, TokenKind.BRACE_R);
982
+ }
983
+ /**
984
+ * EnumValueDefinition : Description? EnumValue Directives[Const]?
985
+ *
986
+ * EnumValue : Name
987
+ */
988
+ ;
989
+
990
+ _proto.parseEnumValueDefinition = function parseEnumValueDefinition() {
991
+ var start = this._lexer.token;
992
+ var description = this.parseDescription();
993
+ var name = this.parseName();
994
+ var directives = this.parseDirectives(true);
995
+ return {
996
+ kind: Kind.ENUM_VALUE_DEFINITION,
997
+ description: description,
998
+ name: name,
999
+ directives: directives,
1000
+ loc: this.loc(start)
1001
+ };
1002
+ }
1003
+ /**
1004
+ * InputObjectTypeDefinition :
1005
+ * - Description? input Name Directives[Const]? InputFieldsDefinition?
1006
+ */
1007
+ ;
1008
+
1009
+ _proto.parseInputObjectTypeDefinition = function parseInputObjectTypeDefinition() {
1010
+ var start = this._lexer.token;
1011
+ var description = this.parseDescription();
1012
+ this.expectKeyword('input');
1013
+ var name = this.parseName();
1014
+ var directives = this.parseDirectives(true);
1015
+ var fields = this.parseInputFieldsDefinition();
1016
+ return {
1017
+ kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
1018
+ description: description,
1019
+ name: name,
1020
+ directives: directives,
1021
+ fields: fields,
1022
+ loc: this.loc(start)
1023
+ };
1024
+ }
1025
+ /**
1026
+ * InputFieldsDefinition : { InputValueDefinition+ }
1027
+ */
1028
+ ;
548
1029
 
549
- var item = function item() {
550
- return parseObjectField(lexer, isConst);
551
- };
1030
+ _proto.parseInputFieldsDefinition = function parseInputFieldsDefinition() {
1031
+ return this.optionalMany(TokenKind.BRACE_L, this.parseInputValueDef, TokenKind.BRACE_R);
1032
+ }
1033
+ /**
1034
+ * TypeSystemExtension :
1035
+ * - SchemaExtension
1036
+ * - TypeExtension
1037
+ *
1038
+ * TypeExtension :
1039
+ * - ScalarTypeExtension
1040
+ * - ObjectTypeExtension
1041
+ * - InterfaceTypeExtension
1042
+ * - UnionTypeExtension
1043
+ * - EnumTypeExtension
1044
+ * - InputObjectTypeDefinition
1045
+ */
1046
+ ;
1047
+
1048
+ _proto.parseTypeSystemExtension = function parseTypeSystemExtension() {
1049
+ var keywordToken = this._lexer.lookahead();
1050
+
1051
+ if (keywordToken.kind === TokenKind.NAME) {
1052
+ switch (keywordToken.value) {
1053
+ case 'schema':
1054
+ return this.parseSchemaExtension();
1055
+
1056
+ case 'scalar':
1057
+ return this.parseScalarTypeExtension();
1058
+
1059
+ case 'type':
1060
+ return this.parseObjectTypeExtension();
1061
+
1062
+ case 'interface':
1063
+ return this.parseInterfaceTypeExtension();
1064
+
1065
+ case 'union':
1066
+ return this.parseUnionTypeExtension();
1067
+
1068
+ case 'enum':
1069
+ return this.parseEnumTypeExtension();
1070
+
1071
+ case 'input':
1072
+ return this.parseInputObjectTypeExtension();
1073
+ }
1074
+ }
552
1075
 
553
- return {
554
- kind: Kind.OBJECT,
555
- fields: any(lexer, TokenKind.BRACE_L, item, TokenKind.BRACE_R),
556
- loc: loc(lexer, start)
557
- };
558
- }
559
- /**
560
- * ObjectField[Const] : Name : Value[?Const]
561
- */
562
-
563
-
564
- function parseObjectField(lexer, isConst) {
565
- var start = lexer.token;
566
- var name = parseName(lexer);
567
- expectToken(lexer, TokenKind.COLON);
568
- return {
569
- kind: Kind.OBJECT_FIELD,
570
- name: name,
571
- value: parseValueLiteral(lexer, isConst),
572
- loc: loc(lexer, start)
573
- };
574
- } // Implements the parsing rules in the Directives section.
575
-
576
- /**
577
- * Directives[Const] : Directive[?Const]+
578
- */
579
-
580
-
581
- function parseDirectives(lexer, isConst) {
582
- var directives = [];
583
-
584
- while (peek(lexer, TokenKind.AT)) {
585
- directives.push(parseDirective(lexer, isConst));
1076
+ throw this.unexpected(keywordToken);
586
1077
  }
1078
+ /**
1079
+ * SchemaExtension :
1080
+ * - extend schema Directives[Const]? { OperationTypeDefinition+ }
1081
+ * - extend schema Directives[Const]
1082
+ */
1083
+ ;
1084
+
1085
+ _proto.parseSchemaExtension = function parseSchemaExtension() {
1086
+ var start = this._lexer.token;
1087
+ this.expectKeyword('extend');
1088
+ this.expectKeyword('schema');
1089
+ var directives = this.parseDirectives(true);
1090
+ var operationTypes = this.optionalMany(TokenKind.BRACE_L, this.parseOperationTypeDefinition, TokenKind.BRACE_R);
1091
+
1092
+ if (directives.length === 0 && operationTypes.length === 0) {
1093
+ throw this.unexpected();
1094
+ }
587
1095
 
588
- return directives;
589
- }
590
- /**
591
- * Directive[Const] : @ Name Arguments[?Const]?
592
- */
593
-
594
-
595
- function parseDirective(lexer, isConst) {
596
- var start = lexer.token;
597
- expectToken(lexer, TokenKind.AT);
598
- return {
599
- kind: Kind.DIRECTIVE,
600
- name: parseName(lexer),
601
- arguments: parseArguments(lexer, isConst),
602
- loc: loc(lexer, start)
603
- };
604
- } // Implements the parsing rules in the Types section.
605
-
606
- /**
607
- * Type :
608
- * - NamedType
609
- * - ListType
610
- * - NonNullType
611
- */
612
-
613
-
614
- export function parseTypeReference(lexer) {
615
- var start = lexer.token;
616
- var type;
617
-
618
- if (expectOptionalToken(lexer, TokenKind.BRACKET_L)) {
619
- type = parseTypeReference(lexer);
620
- expectToken(lexer, TokenKind.BRACKET_R);
621
- type = {
622
- kind: Kind.LIST_TYPE,
623
- type: type,
624
- loc: loc(lexer, start)
1096
+ return {
1097
+ kind: Kind.SCHEMA_EXTENSION,
1098
+ directives: directives,
1099
+ operationTypes: operationTypes,
1100
+ loc: this.loc(start)
625
1101
  };
626
- } else {
627
- type = parseNamedType(lexer);
628
1102
  }
1103
+ /**
1104
+ * ScalarTypeExtension :
1105
+ * - extend scalar Name Directives[Const]
1106
+ */
1107
+ ;
1108
+
1109
+ _proto.parseScalarTypeExtension = function parseScalarTypeExtension() {
1110
+ var start = this._lexer.token;
1111
+ this.expectKeyword('extend');
1112
+ this.expectKeyword('scalar');
1113
+ var name = this.parseName();
1114
+ var directives = this.parseDirectives(true);
1115
+
1116
+ if (directives.length === 0) {
1117
+ throw this.unexpected();
1118
+ }
629
1119
 
630
- if (expectOptionalToken(lexer, TokenKind.BANG)) {
631
1120
  return {
632
- kind: Kind.NON_NULL_TYPE,
633
- type: type,
634
- loc: loc(lexer, start)
1121
+ kind: Kind.SCALAR_TYPE_EXTENSION,
1122
+ name: name,
1123
+ directives: directives,
1124
+ loc: this.loc(start)
635
1125
  };
636
1126
  }
637
-
638
- return type;
639
- }
640
- /**
641
- * NamedType : Name
642
- */
643
-
644
- export function parseNamedType(lexer) {
645
- var start = lexer.token;
646
- return {
647
- kind: Kind.NAMED_TYPE,
648
- name: parseName(lexer),
649
- loc: loc(lexer, start)
650
- };
651
- } // Implements the parsing rules in the Type Definition section.
652
-
653
- /**
654
- * TypeSystemDefinition :
655
- * - SchemaDefinition
656
- * - TypeDefinition
657
- * - DirectiveDefinition
658
- *
659
- * TypeDefinition :
660
- * - ScalarTypeDefinition
661
- * - ObjectTypeDefinition
662
- * - InterfaceTypeDefinition
663
- * - UnionTypeDefinition
664
- * - EnumTypeDefinition
665
- * - InputObjectTypeDefinition
666
- */
667
-
668
- function parseTypeSystemDefinition(lexer) {
669
- // Many definitions begin with a description and require a lookahead.
670
- var keywordToken = peekDescription(lexer) ? lexer.lookahead() : lexer.token;
671
-
672
- if (keywordToken.kind === TokenKind.NAME) {
673
- switch (keywordToken.value) {
674
- case 'schema':
675
- return parseSchemaDefinition(lexer);
676
-
677
- case 'scalar':
678
- return parseScalarTypeDefinition(lexer);
679
-
680
- case 'type':
681
- return parseObjectTypeDefinition(lexer);
682
-
683
- case 'interface':
684
- return parseInterfaceTypeDefinition(lexer);
685
-
686
- case 'union':
687
- return parseUnionTypeDefinition(lexer);
688
-
689
- case 'enum':
690
- return parseEnumTypeDefinition(lexer);
691
-
692
- case 'input':
693
- return parseInputObjectTypeDefinition(lexer);
694
-
695
- case 'directive':
696
- return parseDirectiveDefinition(lexer);
1127
+ /**
1128
+ * ObjectTypeExtension :
1129
+ * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
1130
+ * - extend type Name ImplementsInterfaces? Directives[Const]
1131
+ * - extend type Name ImplementsInterfaces
1132
+ */
1133
+ ;
1134
+
1135
+ _proto.parseObjectTypeExtension = function parseObjectTypeExtension() {
1136
+ var start = this._lexer.token;
1137
+ this.expectKeyword('extend');
1138
+ this.expectKeyword('type');
1139
+ var name = this.parseName();
1140
+ var interfaces = this.parseImplementsInterfaces();
1141
+ var directives = this.parseDirectives(true);
1142
+ var fields = this.parseFieldsDefinition();
1143
+
1144
+ if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
1145
+ throw this.unexpected();
697
1146
  }
698
- }
699
-
700
- throw unexpected(lexer, keywordToken);
701
- }
702
1147
 
703
- function peekDescription(lexer) {
704
- return peek(lexer, TokenKind.STRING) || peek(lexer, TokenKind.BLOCK_STRING);
705
- }
706
- /**
707
- * Description : StringValue
708
- */
709
-
710
-
711
- function parseDescription(lexer) {
712
- if (peekDescription(lexer)) {
713
- return parseStringLiteral(lexer);
1148
+ return {
1149
+ kind: Kind.OBJECT_TYPE_EXTENSION,
1150
+ name: name,
1151
+ interfaces: interfaces,
1152
+ directives: directives,
1153
+ fields: fields,
1154
+ loc: this.loc(start)
1155
+ };
714
1156
  }
715
- }
716
- /**
717
- * SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ }
718
- */
719
-
720
-
721
- function parseSchemaDefinition(lexer) {
722
- var start = lexer.token;
723
- expectKeyword(lexer, 'schema');
724
- var directives = parseDirectives(lexer, true);
725
- var operationTypes = many(lexer, TokenKind.BRACE_L, parseOperationTypeDefinition, TokenKind.BRACE_R);
726
- return {
727
- kind: Kind.SCHEMA_DEFINITION,
728
- directives: directives,
729
- operationTypes: operationTypes,
730
- loc: loc(lexer, start)
731
- };
732
- }
733
- /**
734
- * OperationTypeDefinition : OperationType : NamedType
735
- */
736
-
737
-
738
- function parseOperationTypeDefinition(lexer) {
739
- var start = lexer.token;
740
- var operation = parseOperationType(lexer);
741
- expectToken(lexer, TokenKind.COLON);
742
- var type = parseNamedType(lexer);
743
- return {
744
- kind: Kind.OPERATION_TYPE_DEFINITION,
745
- operation: operation,
746
- type: type,
747
- loc: loc(lexer, start)
748
- };
749
- }
750
- /**
751
- * ScalarTypeDefinition : Description? scalar Name Directives[Const]?
752
- */
753
-
754
-
755
- function parseScalarTypeDefinition(lexer) {
756
- var start = lexer.token;
757
- var description = parseDescription(lexer);
758
- expectKeyword(lexer, 'scalar');
759
- var name = parseName(lexer);
760
- var directives = parseDirectives(lexer, true);
761
- return {
762
- kind: Kind.SCALAR_TYPE_DEFINITION,
763
- description: description,
764
- name: name,
765
- directives: directives,
766
- loc: loc(lexer, start)
767
- };
768
- }
769
- /**
770
- * ObjectTypeDefinition :
771
- * Description?
772
- * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
773
- */
774
-
775
-
776
- function parseObjectTypeDefinition(lexer) {
777
- var start = lexer.token;
778
- var description = parseDescription(lexer);
779
- expectKeyword(lexer, 'type');
780
- var name = parseName(lexer);
781
- var interfaces = parseImplementsInterfaces(lexer);
782
- var directives = parseDirectives(lexer, true);
783
- var fields = parseFieldsDefinition(lexer);
784
- return {
785
- kind: Kind.OBJECT_TYPE_DEFINITION,
786
- description: description,
787
- name: name,
788
- interfaces: interfaces,
789
- directives: directives,
790
- fields: fields,
791
- loc: loc(lexer, start)
792
- };
793
- }
794
- /**
795
- * ImplementsInterfaces :
796
- * - implements `&`? NamedType
797
- * - ImplementsInterfaces & NamedType
798
- */
799
-
800
-
801
- function parseImplementsInterfaces(lexer) {
802
- var types = [];
803
-
804
- if (expectOptionalKeyword(lexer, 'implements')) {
805
- // Optional leading ampersand
806
- expectOptionalToken(lexer, TokenKind.AMP);
1157
+ /**
1158
+ * InterfaceTypeExtension :
1159
+ * - extend interface Name Directives[Const]? FieldsDefinition
1160
+ * - extend interface Name Directives[Const]
1161
+ */
1162
+ ;
1163
+
1164
+ _proto.parseInterfaceTypeExtension = function parseInterfaceTypeExtension() {
1165
+ var start = this._lexer.token;
1166
+ this.expectKeyword('extend');
1167
+ this.expectKeyword('interface');
1168
+ var name = this.parseName();
1169
+ var directives = this.parseDirectives(true);
1170
+ var fields = this.parseFieldsDefinition();
1171
+
1172
+ if (directives.length === 0 && fields.length === 0) {
1173
+ throw this.unexpected();
1174
+ }
807
1175
 
808
- do {
809
- types.push(parseNamedType(lexer));
810
- } while (expectOptionalToken(lexer, TokenKind.AMP) || // Legacy support for the SDL?
811
- lexer.options.allowLegacySDLImplementsInterfaces && peek(lexer, TokenKind.NAME));
1176
+ return {
1177
+ kind: Kind.INTERFACE_TYPE_EXTENSION,
1178
+ name: name,
1179
+ directives: directives,
1180
+ fields: fields,
1181
+ loc: this.loc(start)
1182
+ };
812
1183
  }
1184
+ /**
1185
+ * UnionTypeExtension :
1186
+ * - extend union Name Directives[Const]? UnionMemberTypes
1187
+ * - extend union Name Directives[Const]
1188
+ */
1189
+ ;
1190
+
1191
+ _proto.parseUnionTypeExtension = function parseUnionTypeExtension() {
1192
+ var start = this._lexer.token;
1193
+ this.expectKeyword('extend');
1194
+ this.expectKeyword('union');
1195
+ var name = this.parseName();
1196
+ var directives = this.parseDirectives(true);
1197
+ var types = this.parseUnionMemberTypes();
1198
+
1199
+ if (directives.length === 0 && types.length === 0) {
1200
+ throw this.unexpected();
1201
+ }
813
1202
 
814
- return types;
815
- }
816
- /**
817
- * FieldsDefinition : { FieldDefinition+ }
818
- */
819
-
820
-
821
- function parseFieldsDefinition(lexer) {
822
- // Legacy support for the SDL?
823
- if (lexer.options.allowLegacySDLEmptyFields && peek(lexer, TokenKind.BRACE_L) && lexer.lookahead().kind === TokenKind.BRACE_R) {
824
- lexer.advance();
825
- lexer.advance();
826
- return [];
1203
+ return {
1204
+ kind: Kind.UNION_TYPE_EXTENSION,
1205
+ name: name,
1206
+ directives: directives,
1207
+ types: types,
1208
+ loc: this.loc(start)
1209
+ };
827
1210
  }
1211
+ /**
1212
+ * EnumTypeExtension :
1213
+ * - extend enum Name Directives[Const]? EnumValuesDefinition
1214
+ * - extend enum Name Directives[Const]
1215
+ */
1216
+ ;
1217
+
1218
+ _proto.parseEnumTypeExtension = function parseEnumTypeExtension() {
1219
+ var start = this._lexer.token;
1220
+ this.expectKeyword('extend');
1221
+ this.expectKeyword('enum');
1222
+ var name = this.parseName();
1223
+ var directives = this.parseDirectives(true);
1224
+ var values = this.parseEnumValuesDefinition();
1225
+
1226
+ if (directives.length === 0 && values.length === 0) {
1227
+ throw this.unexpected();
1228
+ }
828
1229
 
829
- return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseFieldDefinition, TokenKind.BRACE_R) : [];
830
- }
831
- /**
832
- * FieldDefinition :
833
- * - Description? Name ArgumentsDefinition? : Type Directives[Const]?
834
- */
835
-
836
-
837
- function parseFieldDefinition(lexer) {
838
- var start = lexer.token;
839
- var description = parseDescription(lexer);
840
- var name = parseName(lexer);
841
- var args = parseArgumentDefs(lexer);
842
- expectToken(lexer, TokenKind.COLON);
843
- var type = parseTypeReference(lexer);
844
- var directives = parseDirectives(lexer, true);
845
- return {
846
- kind: Kind.FIELD_DEFINITION,
847
- description: description,
848
- name: name,
849
- arguments: args,
850
- type: type,
851
- directives: directives,
852
- loc: loc(lexer, start)
853
- };
854
- }
855
- /**
856
- * ArgumentsDefinition : ( InputValueDefinition+ )
857
- */
858
-
859
-
860
- function parseArgumentDefs(lexer) {
861
- if (!peek(lexer, TokenKind.PAREN_L)) {
862
- return [];
1230
+ return {
1231
+ kind: Kind.ENUM_TYPE_EXTENSION,
1232
+ name: name,
1233
+ directives: directives,
1234
+ values: values,
1235
+ loc: this.loc(start)
1236
+ };
863
1237
  }
1238
+ /**
1239
+ * InputObjectTypeExtension :
1240
+ * - extend input Name Directives[Const]? InputFieldsDefinition
1241
+ * - extend input Name Directives[Const]
1242
+ */
1243
+ ;
1244
+
1245
+ _proto.parseInputObjectTypeExtension = function parseInputObjectTypeExtension() {
1246
+ var start = this._lexer.token;
1247
+ this.expectKeyword('extend');
1248
+ this.expectKeyword('input');
1249
+ var name = this.parseName();
1250
+ var directives = this.parseDirectives(true);
1251
+ var fields = this.parseInputFieldsDefinition();
1252
+
1253
+ if (directives.length === 0 && fields.length === 0) {
1254
+ throw this.unexpected();
1255
+ }
864
1256
 
865
- return many(lexer, TokenKind.PAREN_L, parseInputValueDef, TokenKind.PAREN_R);
866
- }
867
- /**
868
- * InputValueDefinition :
869
- * - Description? Name : Type DefaultValue? Directives[Const]?
870
- */
871
-
872
-
873
- function parseInputValueDef(lexer) {
874
- var start = lexer.token;
875
- var description = parseDescription(lexer);
876
- var name = parseName(lexer);
877
- expectToken(lexer, TokenKind.COLON);
878
- var type = parseTypeReference(lexer);
879
- var defaultValue;
880
-
881
- if (expectOptionalToken(lexer, TokenKind.EQUALS)) {
882
- defaultValue = parseConstValue(lexer);
1257
+ return {
1258
+ kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,
1259
+ name: name,
1260
+ directives: directives,
1261
+ fields: fields,
1262
+ loc: this.loc(start)
1263
+ };
883
1264
  }
884
-
885
- var directives = parseDirectives(lexer, true);
886
- return {
887
- kind: Kind.INPUT_VALUE_DEFINITION,
888
- description: description,
889
- name: name,
890
- type: type,
891
- defaultValue: defaultValue,
892
- directives: directives,
893
- loc: loc(lexer, start)
894
- };
895
- }
896
- /**
897
- * InterfaceTypeDefinition :
898
- * - Description? interface Name Directives[Const]? FieldsDefinition?
899
- */
900
-
901
-
902
- function parseInterfaceTypeDefinition(lexer) {
903
- var start = lexer.token;
904
- var description = parseDescription(lexer);
905
- expectKeyword(lexer, 'interface');
906
- var name = parseName(lexer);
907
- var directives = parseDirectives(lexer, true);
908
- var fields = parseFieldsDefinition(lexer);
909
- return {
910
- kind: Kind.INTERFACE_TYPE_DEFINITION,
911
- description: description,
912
- name: name,
913
- directives: directives,
914
- fields: fields,
915
- loc: loc(lexer, start)
916
- };
917
- }
918
- /**
919
- * UnionTypeDefinition :
920
- * - Description? union Name Directives[Const]? UnionMemberTypes?
921
- */
922
-
923
-
924
- function parseUnionTypeDefinition(lexer) {
925
- var start = lexer.token;
926
- var description = parseDescription(lexer);
927
- expectKeyword(lexer, 'union');
928
- var name = parseName(lexer);
929
- var directives = parseDirectives(lexer, true);
930
- var types = parseUnionMemberTypes(lexer);
931
- return {
932
- kind: Kind.UNION_TYPE_DEFINITION,
933
- description: description,
934
- name: name,
935
- directives: directives,
936
- types: types,
937
- loc: loc(lexer, start)
938
- };
939
- }
940
- /**
941
- * UnionMemberTypes :
942
- * - = `|`? NamedType
943
- * - UnionMemberTypes | NamedType
944
- */
945
-
946
-
947
- function parseUnionMemberTypes(lexer) {
948
- var types = [];
949
-
950
- if (expectOptionalToken(lexer, TokenKind.EQUALS)) {
1265
+ /**
1266
+ * DirectiveDefinition :
1267
+ * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
1268
+ */
1269
+ ;
1270
+
1271
+ _proto.parseDirectiveDefinition = function parseDirectiveDefinition() {
1272
+ var start = this._lexer.token;
1273
+ var description = this.parseDescription();
1274
+ this.expectKeyword('directive');
1275
+ this.expectToken(TokenKind.AT);
1276
+ var name = this.parseName();
1277
+ var args = this.parseArgumentDefs();
1278
+ var repeatable = this.expectOptionalKeyword('repeatable');
1279
+ this.expectKeyword('on');
1280
+ var locations = this.parseDirectiveLocations();
1281
+ return {
1282
+ kind: Kind.DIRECTIVE_DEFINITION,
1283
+ description: description,
1284
+ name: name,
1285
+ arguments: args,
1286
+ repeatable: repeatable,
1287
+ locations: locations,
1288
+ loc: this.loc(start)
1289
+ };
1290
+ }
1291
+ /**
1292
+ * DirectiveLocations :
1293
+ * - `|`? DirectiveLocation
1294
+ * - DirectiveLocations | DirectiveLocation
1295
+ */
1296
+ ;
1297
+
1298
+ _proto.parseDirectiveLocations = function parseDirectiveLocations() {
951
1299
  // Optional leading pipe
952
- expectOptionalToken(lexer, TokenKind.PIPE);
1300
+ this.expectOptionalToken(TokenKind.PIPE);
1301
+ var locations = [];
953
1302
 
954
1303
  do {
955
- types.push(parseNamedType(lexer));
956
- } while (expectOptionalToken(lexer, TokenKind.PIPE));
957
- }
958
-
959
- return types;
960
- }
961
- /**
962
- * EnumTypeDefinition :
963
- * - Description? enum Name Directives[Const]? EnumValuesDefinition?
964
- */
965
-
966
-
967
- function parseEnumTypeDefinition(lexer) {
968
- var start = lexer.token;
969
- var description = parseDescription(lexer);
970
- expectKeyword(lexer, 'enum');
971
- var name = parseName(lexer);
972
- var directives = parseDirectives(lexer, true);
973
- var values = parseEnumValuesDefinition(lexer);
974
- return {
975
- kind: Kind.ENUM_TYPE_DEFINITION,
976
- description: description,
977
- name: name,
978
- directives: directives,
979
- values: values,
980
- loc: loc(lexer, start)
981
- };
982
- }
983
- /**
984
- * EnumValuesDefinition : { EnumValueDefinition+ }
985
- */
986
-
987
-
988
- function parseEnumValuesDefinition(lexer) {
989
- return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseEnumValueDefinition, TokenKind.BRACE_R) : [];
990
- }
991
- /**
992
- * EnumValueDefinition : Description? EnumValue Directives[Const]?
993
- *
994
- * EnumValue : Name
995
- */
996
-
997
-
998
- function parseEnumValueDefinition(lexer) {
999
- var start = lexer.token;
1000
- var description = parseDescription(lexer);
1001
- var name = parseName(lexer);
1002
- var directives = parseDirectives(lexer, true);
1003
- return {
1004
- kind: Kind.ENUM_VALUE_DEFINITION,
1005
- description: description,
1006
- name: name,
1007
- directives: directives,
1008
- loc: loc(lexer, start)
1009
- };
1010
- }
1011
- /**
1012
- * InputObjectTypeDefinition :
1013
- * - Description? input Name Directives[Const]? InputFieldsDefinition?
1014
- */
1015
-
1016
-
1017
- function parseInputObjectTypeDefinition(lexer) {
1018
- var start = lexer.token;
1019
- var description = parseDescription(lexer);
1020
- expectKeyword(lexer, 'input');
1021
- var name = parseName(lexer);
1022
- var directives = parseDirectives(lexer, true);
1023
- var fields = parseInputFieldsDefinition(lexer);
1024
- return {
1025
- kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
1026
- description: description,
1027
- name: name,
1028
- directives: directives,
1029
- fields: fields,
1030
- loc: loc(lexer, start)
1031
- };
1032
- }
1033
- /**
1034
- * InputFieldsDefinition : { InputValueDefinition+ }
1035
- */
1036
-
1304
+ locations.push(this.parseDirectiveLocation());
1305
+ } while (this.expectOptionalToken(TokenKind.PIPE));
1037
1306
 
1038
- function parseInputFieldsDefinition(lexer) {
1039
- return peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseInputValueDef, TokenKind.BRACE_R) : [];
1040
- }
1041
- /**
1042
- * TypeSystemExtension :
1043
- * - SchemaExtension
1044
- * - TypeExtension
1045
- *
1046
- * TypeExtension :
1047
- * - ScalarTypeExtension
1048
- * - ObjectTypeExtension
1049
- * - InterfaceTypeExtension
1050
- * - UnionTypeExtension
1051
- * - EnumTypeExtension
1052
- * - InputObjectTypeDefinition
1053
- */
1054
-
1055
-
1056
- function parseTypeSystemExtension(lexer) {
1057
- var keywordToken = lexer.lookahead();
1058
-
1059
- if (keywordToken.kind === TokenKind.NAME) {
1060
- switch (keywordToken.value) {
1061
- case 'schema':
1062
- return parseSchemaExtension(lexer);
1063
-
1064
- case 'scalar':
1065
- return parseScalarTypeExtension(lexer);
1066
-
1067
- case 'type':
1068
- return parseObjectTypeExtension(lexer);
1069
-
1070
- case 'interface':
1071
- return parseInterfaceTypeExtension(lexer);
1307
+ return locations;
1308
+ }
1309
+ /*
1310
+ * DirectiveLocation :
1311
+ * - ExecutableDirectiveLocation
1312
+ * - TypeSystemDirectiveLocation
1313
+ *
1314
+ * ExecutableDirectiveLocation : one of
1315
+ * `QUERY`
1316
+ * `MUTATION`
1317
+ * `SUBSCRIPTION`
1318
+ * `FIELD`
1319
+ * `FRAGMENT_DEFINITION`
1320
+ * `FRAGMENT_SPREAD`
1321
+ * `INLINE_FRAGMENT`
1322
+ *
1323
+ * TypeSystemDirectiveLocation : one of
1324
+ * `SCHEMA`
1325
+ * `SCALAR`
1326
+ * `OBJECT`
1327
+ * `FIELD_DEFINITION`
1328
+ * `ARGUMENT_DEFINITION`
1329
+ * `INTERFACE`
1330
+ * `UNION`
1331
+ * `ENUM`
1332
+ * `ENUM_VALUE`
1333
+ * `INPUT_OBJECT`
1334
+ * `INPUT_FIELD_DEFINITION`
1335
+ */
1336
+ ;
1337
+
1338
+ _proto.parseDirectiveLocation = function parseDirectiveLocation() {
1339
+ var start = this._lexer.token;
1340
+ var name = this.parseName();
1341
+
1342
+ if (DirectiveLocation[name.value] !== undefined) {
1343
+ return name;
1344
+ }
1072
1345
 
1073
- case 'union':
1074
- return parseUnionTypeExtension(lexer);
1346
+ throw this.unexpected(start);
1347
+ } // Core parsing utility functions
1075
1348
 
1076
- case 'enum':
1077
- return parseEnumTypeExtension(lexer);
1349
+ /**
1350
+ * Returns a location object, used to identify the place in
1351
+ * the source that created a given parsed object.
1352
+ */
1353
+ ;
1078
1354
 
1079
- case 'input':
1080
- return parseInputObjectTypeExtension(lexer);
1355
+ _proto.loc = function loc(startToken) {
1356
+ if (!this._options.noLocation) {
1357
+ return new Loc(startToken, this._lexer.lastToken, this._lexer.source);
1081
1358
  }
1082
1359
  }
1360
+ /**
1361
+ * Determines if the next token is of a given kind
1362
+ */
1363
+ ;
1083
1364
 
1084
- throw unexpected(lexer, keywordToken);
1085
- }
1086
- /**
1087
- * SchemaExtension :
1088
- * - extend schema Directives[Const]? { OperationTypeDefinition+ }
1089
- * - extend schema Directives[Const]
1090
- */
1091
-
1092
-
1093
- function parseSchemaExtension(lexer) {
1094
- var start = lexer.token;
1095
- expectKeyword(lexer, 'extend');
1096
- expectKeyword(lexer, 'schema');
1097
- var directives = parseDirectives(lexer, true);
1098
- var operationTypes = peek(lexer, TokenKind.BRACE_L) ? many(lexer, TokenKind.BRACE_L, parseOperationTypeDefinition, TokenKind.BRACE_R) : [];
1099
-
1100
- if (directives.length === 0 && operationTypes.length === 0) {
1101
- throw unexpected(lexer);
1365
+ _proto.peek = function peek(kind) {
1366
+ return this._lexer.token.kind === kind;
1102
1367
  }
1368
+ /**
1369
+ * If the next token is of the given kind, return that token after advancing
1370
+ * the lexer. Otherwise, do not change the parser state and throw an error.
1371
+ */
1372
+ ;
1103
1373
 
1104
- return {
1105
- kind: Kind.SCHEMA_EXTENSION,
1106
- directives: directives,
1107
- operationTypes: operationTypes,
1108
- loc: loc(lexer, start)
1109
- };
1110
- }
1111
- /**
1112
- * ScalarTypeExtension :
1113
- * - extend scalar Name Directives[Const]
1114
- */
1374
+ _proto.expectToken = function expectToken(kind) {
1375
+ var token = this._lexer.token;
1115
1376
 
1377
+ if (token.kind === kind) {
1378
+ this._lexer.advance();
1116
1379
 
1117
- function parseScalarTypeExtension(lexer) {
1118
- var start = lexer.token;
1119
- expectKeyword(lexer, 'extend');
1120
- expectKeyword(lexer, 'scalar');
1121
- var name = parseName(lexer);
1122
- var directives = parseDirectives(lexer, true);
1380
+ return token;
1381
+ }
1123
1382
 
1124
- if (directives.length === 0) {
1125
- throw unexpected(lexer);
1383
+ throw syntaxError(this._lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token)));
1126
1384
  }
1385
+ /**
1386
+ * If the next token is of the given kind, return that token after advancing
1387
+ * the lexer. Otherwise, do not change the parser state and return undefined.
1388
+ */
1389
+ ;
1127
1390
 
1128
- return {
1129
- kind: Kind.SCALAR_TYPE_EXTENSION,
1130
- name: name,
1131
- directives: directives,
1132
- loc: loc(lexer, start)
1133
- };
1134
- }
1135
- /**
1136
- * ObjectTypeExtension :
1137
- * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
1138
- * - extend type Name ImplementsInterfaces? Directives[Const]
1139
- * - extend type Name ImplementsInterfaces
1140
- */
1391
+ _proto.expectOptionalToken = function expectOptionalToken(kind) {
1392
+ var token = this._lexer.token;
1141
1393
 
1394
+ if (token.kind === kind) {
1395
+ this._lexer.advance();
1142
1396
 
1143
- function parseObjectTypeExtension(lexer) {
1144
- var start = lexer.token;
1145
- expectKeyword(lexer, 'extend');
1146
- expectKeyword(lexer, 'type');
1147
- var name = parseName(lexer);
1148
- var interfaces = parseImplementsInterfaces(lexer);
1149
- var directives = parseDirectives(lexer, true);
1150
- var fields = parseFieldsDefinition(lexer);
1397
+ return token;
1398
+ }
1151
1399
 
1152
- if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
1153
- throw unexpected(lexer);
1400
+ return undefined;
1154
1401
  }
1155
-
1156
- return {
1157
- kind: Kind.OBJECT_TYPE_EXTENSION,
1158
- name: name,
1159
- interfaces: interfaces,
1160
- directives: directives,
1161
- fields: fields,
1162
- loc: loc(lexer, start)
1163
- };
1164
- }
1165
- /**
1166
- * InterfaceTypeExtension :
1167
- * - extend interface Name Directives[Const]? FieldsDefinition
1168
- * - extend interface Name Directives[Const]
1169
- */
1170
-
1171
-
1172
- function parseInterfaceTypeExtension(lexer) {
1173
- var start = lexer.token;
1174
- expectKeyword(lexer, 'extend');
1175
- expectKeyword(lexer, 'interface');
1176
- var name = parseName(lexer);
1177
- var directives = parseDirectives(lexer, true);
1178
- var fields = parseFieldsDefinition(lexer);
1179
-
1180
- if (directives.length === 0 && fields.length === 0) {
1181
- throw unexpected(lexer);
1402
+ /**
1403
+ * If the next token is a given keyword, advance the lexer.
1404
+ * Otherwise, do not change the parser state and throw an error.
1405
+ */
1406
+ ;
1407
+
1408
+ _proto.expectKeyword = function expectKeyword(value) {
1409
+ var token = this._lexer.token;
1410
+
1411
+ if (token.kind === TokenKind.NAME && token.value === value) {
1412
+ this._lexer.advance();
1413
+ } else {
1414
+ throw syntaxError(this._lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token)));
1415
+ }
1182
1416
  }
1417
+ /**
1418
+ * If the next token is a given keyword, return "true" after advancing
1419
+ * the lexer. Otherwise, do not change the parser state and return "false".
1420
+ */
1421
+ ;
1183
1422
 
1184
- return {
1185
- kind: Kind.INTERFACE_TYPE_EXTENSION,
1186
- name: name,
1187
- directives: directives,
1188
- fields: fields,
1189
- loc: loc(lexer, start)
1190
- };
1191
- }
1192
- /**
1193
- * UnionTypeExtension :
1194
- * - extend union Name Directives[Const]? UnionMemberTypes
1195
- * - extend union Name Directives[Const]
1196
- */
1423
+ _proto.expectOptionalKeyword = function expectOptionalKeyword(value) {
1424
+ var token = this._lexer.token;
1197
1425
 
1426
+ if (token.kind === TokenKind.NAME && token.value === value) {
1427
+ this._lexer.advance();
1198
1428
 
1199
- function parseUnionTypeExtension(lexer) {
1200
- var start = lexer.token;
1201
- expectKeyword(lexer, 'extend');
1202
- expectKeyword(lexer, 'union');
1203
- var name = parseName(lexer);
1204
- var directives = parseDirectives(lexer, true);
1205
- var types = parseUnionMemberTypes(lexer);
1429
+ return true;
1430
+ }
1206
1431
 
1207
- if (directives.length === 0 && types.length === 0) {
1208
- throw unexpected(lexer);
1432
+ return false;
1209
1433
  }
1210
-
1211
- return {
1212
- kind: Kind.UNION_TYPE_EXTENSION,
1213
- name: name,
1214
- directives: directives,
1215
- types: types,
1216
- loc: loc(lexer, start)
1217
- };
1218
- }
1219
- /**
1220
- * EnumTypeExtension :
1221
- * - extend enum Name Directives[Const]? EnumValuesDefinition
1222
- * - extend enum Name Directives[Const]
1223
- */
1224
-
1225
-
1226
- function parseEnumTypeExtension(lexer) {
1227
- var start = lexer.token;
1228
- expectKeyword(lexer, 'extend');
1229
- expectKeyword(lexer, 'enum');
1230
- var name = parseName(lexer);
1231
- var directives = parseDirectives(lexer, true);
1232
- var values = parseEnumValuesDefinition(lexer);
1233
-
1234
- if (directives.length === 0 && values.length === 0) {
1235
- throw unexpected(lexer);
1434
+ /**
1435
+ * Helper function for creating an error when an unexpected lexed token
1436
+ * is encountered.
1437
+ */
1438
+ ;
1439
+
1440
+ _proto.unexpected = function unexpected(atToken) {
1441
+ var token = atToken || this._lexer.token;
1442
+ return syntaxError(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token)));
1236
1443
  }
1444
+ /**
1445
+ * Returns a possibly empty list of parse nodes, determined by
1446
+ * the parseFn. This list begins with a lex token of openKind
1447
+ * and ends with a lex token of closeKind. Advances the parser
1448
+ * to the next lex token after the closing token.
1449
+ */
1450
+ ;
1451
+
1452
+ _proto.any = function any(openKind, parseFn, closeKind) {
1453
+ this.expectToken(openKind);
1454
+ var nodes = [];
1455
+
1456
+ while (!this.expectOptionalToken(closeKind)) {
1457
+ nodes.push(parseFn.call(this));
1458
+ }
1237
1459
 
1238
- return {
1239
- kind: Kind.ENUM_TYPE_EXTENSION,
1240
- name: name,
1241
- directives: directives,
1242
- values: values,
1243
- loc: loc(lexer, start)
1244
- };
1245
- }
1246
- /**
1247
- * InputObjectTypeExtension :
1248
- * - extend input Name Directives[Const]? InputFieldsDefinition
1249
- * - extend input Name Directives[Const]
1250
- */
1251
-
1252
-
1253
- function parseInputObjectTypeExtension(lexer) {
1254
- var start = lexer.token;
1255
- expectKeyword(lexer, 'extend');
1256
- expectKeyword(lexer, 'input');
1257
- var name = parseName(lexer);
1258
- var directives = parseDirectives(lexer, true);
1259
- var fields = parseInputFieldsDefinition(lexer);
1260
-
1261
- if (directives.length === 0 && fields.length === 0) {
1262
- throw unexpected(lexer);
1460
+ return nodes;
1263
1461
  }
1462
+ /**
1463
+ * Returns a list of parse nodes, determined by the parseFn.
1464
+ * It can be empty only if open token is missing otherwise it will always
1465
+ * return non-empty list that begins with a lex token of openKind and ends
1466
+ * with a lex token of closeKind. Advances the parser to the next lex token
1467
+ * after the closing token.
1468
+ */
1469
+ ;
1470
+
1471
+ _proto.optionalMany = function optionalMany(openKind, parseFn, closeKind) {
1472
+ if (this.expectOptionalToken(openKind)) {
1473
+ var nodes = [];
1474
+
1475
+ do {
1476
+ nodes.push(parseFn.call(this));
1477
+ } while (!this.expectOptionalToken(closeKind));
1478
+
1479
+ return nodes;
1480
+ }
1264
1481
 
1265
- return {
1266
- kind: Kind.INPUT_OBJECT_TYPE_EXTENSION,
1267
- name: name,
1268
- directives: directives,
1269
- fields: fields,
1270
- loc: loc(lexer, start)
1271
- };
1272
- }
1273
- /**
1274
- * DirectiveDefinition :
1275
- * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
1276
- */
1277
-
1278
-
1279
- function parseDirectiveDefinition(lexer) {
1280
- var start = lexer.token;
1281
- var description = parseDescription(lexer);
1282
- expectKeyword(lexer, 'directive');
1283
- expectToken(lexer, TokenKind.AT);
1284
- var name = parseName(lexer);
1285
- var args = parseArgumentDefs(lexer);
1286
- var repeatable = expectOptionalKeyword(lexer, 'repeatable');
1287
- expectKeyword(lexer, 'on');
1288
- var locations = parseDirectiveLocations(lexer);
1289
- return {
1290
- kind: Kind.DIRECTIVE_DEFINITION,
1291
- description: description,
1292
- name: name,
1293
- arguments: args,
1294
- repeatable: repeatable,
1295
- locations: locations,
1296
- loc: loc(lexer, start)
1297
- };
1298
- }
1299
- /**
1300
- * DirectiveLocations :
1301
- * - `|`? DirectiveLocation
1302
- * - DirectiveLocations | DirectiveLocation
1303
- */
1304
-
1305
-
1306
- function parseDirectiveLocations(lexer) {
1307
- // Optional leading pipe
1308
- expectOptionalToken(lexer, TokenKind.PIPE);
1309
- var locations = [];
1310
-
1311
- do {
1312
- locations.push(parseDirectiveLocation(lexer));
1313
- } while (expectOptionalToken(lexer, TokenKind.PIPE));
1314
-
1315
- return locations;
1316
- }
1317
- /*
1318
- * DirectiveLocation :
1319
- * - ExecutableDirectiveLocation
1320
- * - TypeSystemDirectiveLocation
1321
- *
1322
- * ExecutableDirectiveLocation : one of
1323
- * `QUERY`
1324
- * `MUTATION`
1325
- * `SUBSCRIPTION`
1326
- * `FIELD`
1327
- * `FRAGMENT_DEFINITION`
1328
- * `FRAGMENT_SPREAD`
1329
- * `INLINE_FRAGMENT`
1330
- *
1331
- * TypeSystemDirectiveLocation : one of
1332
- * `SCHEMA`
1333
- * `SCALAR`
1334
- * `OBJECT`
1335
- * `FIELD_DEFINITION`
1336
- * `ARGUMENT_DEFINITION`
1337
- * `INTERFACE`
1338
- * `UNION`
1339
- * `ENUM`
1340
- * `ENUM_VALUE`
1341
- * `INPUT_OBJECT`
1342
- * `INPUT_FIELD_DEFINITION`
1343
- */
1344
-
1345
-
1346
- function parseDirectiveLocation(lexer) {
1347
- var start = lexer.token;
1348
- var name = parseName(lexer);
1349
-
1350
- if (DirectiveLocation[name.value] !== undefined) {
1351
- return name;
1482
+ return [];
1352
1483
  }
1484
+ /**
1485
+ * Returns a non-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.
1489
+ */
1490
+ ;
1491
+
1492
+ _proto.many = function many(openKind, parseFn, closeKind) {
1493
+ this.expectToken(openKind);
1494
+ var nodes = [];
1353
1495
 
1354
- throw unexpected(lexer, start);
1355
- } // Core parsing utility functions
1356
-
1357
- /**
1358
- * Returns a location object, used to identify the place in
1359
- * the source that created a given parsed object.
1360
- */
1496
+ do {
1497
+ nodes.push(parseFn.call(this));
1498
+ } while (!this.expectOptionalToken(closeKind));
1361
1499
 
1500
+ return nodes;
1501
+ };
1362
1502
 
1363
- function loc(lexer, startToken) {
1364
- if (!lexer.options.noLocation) {
1365
- return new Loc(startToken, lexer.lastToken, lexer.source);
1366
- }
1367
- }
1503
+ return Parser;
1504
+ }();
1368
1505
 
1369
1506
  function Loc(startToken, endToken, source) {
1370
1507
  this.start = startToken.start;
@@ -1382,118 +1519,10 @@ defineToJSON(Loc, function () {
1382
1519
  };
1383
1520
  });
1384
1521
  /**
1385
- * Determines if the next token is of a given kind
1522
+ * A helper function to describe a token as a string for debugging
1386
1523
  */
1387
1524
 
1388
- function peek(lexer, kind) {
1389
- return lexer.token.kind === kind;
1390
- }
1391
- /**
1392
- * If the next token is of the given kind, return that token after advancing
1393
- * the lexer. Otherwise, do not change the parser state and throw an error.
1394
- */
1395
-
1396
-
1397
- function expectToken(lexer, kind) {
1398
- var token = lexer.token;
1399
-
1400
- if (token.kind === kind) {
1401
- lexer.advance();
1402
- return token;
1403
- }
1404
-
1405
- throw syntaxError(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token)));
1406
- }
1407
- /**
1408
- * If the next token is of the given kind, return that token after advancing
1409
- * the lexer. Otherwise, do not change the parser state and return undefined.
1410
- */
1411
-
1412
-
1413
- function expectOptionalToken(lexer, kind) {
1414
- var token = lexer.token;
1415
-
1416
- if (token.kind === kind) {
1417
- lexer.advance();
1418
- return token;
1419
- }
1420
-
1421
- return undefined;
1422
- }
1423
- /**
1424
- * If the next token is a given keyword, advance the lexer.
1425
- * Otherwise, do not change the parser state and throw an error.
1426
- */
1427
-
1428
-
1429
- function expectKeyword(lexer, value) {
1430
- var token = lexer.token;
1431
-
1432
- if (token.kind === TokenKind.NAME && token.value === value) {
1433
- lexer.advance();
1434
- } else {
1435
- throw syntaxError(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token)));
1436
- }
1437
- }
1438
- /**
1439
- * If the next token is a given keyword, return "true" after advancing
1440
- * the lexer. Otherwise, do not change the parser state and return "false".
1441
- */
1442
-
1443
-
1444
- function expectOptionalKeyword(lexer, value) {
1445
- var token = lexer.token;
1446
-
1447
- if (token.kind === TokenKind.NAME && token.value === value) {
1448
- lexer.advance();
1449
- return true;
1450
- }
1451
-
1452
- return false;
1453
- }
1454
- /**
1455
- * Helper function for creating an error when an unexpected lexed token
1456
- * is encountered.
1457
- */
1458
-
1459
-
1460
- function unexpected(lexer, atToken) {
1461
- var token = atToken || lexer.token;
1462
- return syntaxError(lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token)));
1463
- }
1464
- /**
1465
- * Returns a possibly empty list of parse nodes, determined by
1466
- * the parseFn. This list begins with a lex token of openKind
1467
- * and ends with a lex token of closeKind. Advances the parser
1468
- * to the next lex token after the closing token.
1469
- */
1470
-
1471
-
1472
- function any(lexer, openKind, parseFn, closeKind) {
1473
- expectToken(lexer, openKind);
1474
- var nodes = [];
1475
-
1476
- while (!expectOptionalToken(lexer, closeKind)) {
1477
- nodes.push(parseFn(lexer));
1478
- }
1479
-
1480
- return nodes;
1481
- }
1482
- /**
1483
- * Returns a non-empty list of parse nodes, determined by
1484
- * the parseFn. This list begins with a lex token of openKind
1485
- * and ends with a lex token of closeKind. Advances the parser
1486
- * to the next lex token after the closing token.
1487
- */
1488
-
1489
-
1490
- function many(lexer, openKind, parseFn, closeKind) {
1491
- expectToken(lexer, openKind);
1492
- var nodes = [parseFn(lexer)];
1493
-
1494
- while (!expectOptionalToken(lexer, closeKind)) {
1495
- nodes.push(parseFn(lexer));
1496
- }
1497
-
1498
- return nodes;
1525
+ function getTokenDesc(token) {
1526
+ var value = token.value;
1527
+ return value ? "".concat(token.kind, " \"").concat(value, "\"") : token.kind;
1499
1528
  }