graphql 14.0.0 → 14.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/README.md +4 -4
  2. package/error/GraphQLError.js +1 -1
  3. package/error/GraphQLError.js.flow +3 -3
  4. package/error/GraphQLError.mjs +1 -1
  5. package/error/formatError.js +1 -1
  6. package/error/formatError.mjs +1 -1
  7. package/error/index.mjs +1 -1
  8. package/error/locatedError.js +1 -1
  9. package/error/locatedError.mjs +1 -1
  10. package/error/printError.js +1 -1
  11. package/error/printError.mjs +1 -1
  12. package/error/syntaxError.js +1 -1
  13. package/error/syntaxError.mjs +1 -1
  14. package/execution/execute.js +4 -4
  15. package/execution/execute.js.flow +4 -6
  16. package/execution/execute.mjs +5 -5
  17. package/execution/index.mjs +1 -1
  18. package/execution/values.js +4 -4
  19. package/execution/values.js.flow +3 -3
  20. package/execution/values.mjs +3 -3
  21. package/graphql.js +1 -1
  22. package/graphql.mjs +1 -1
  23. package/index.js +12 -0
  24. package/index.js.flow +4 -0
  25. package/index.mjs +4 -4
  26. package/jsutils/dedent.js +2 -2
  27. package/jsutils/dedent.js.flow +1 -1
  28. package/jsutils/dedent.mjs +2 -2
  29. package/jsutils/defineToJSON.js +17 -6
  30. package/jsutils/defineToJSON.js.flow +14 -5
  31. package/jsutils/defineToJSON.mjs +14 -6
  32. package/jsutils/defineToStringTag.js +5 -5
  33. package/jsutils/defineToStringTag.js.flow +3 -3
  34. package/jsutils/defineToStringTag.mjs +4 -4
  35. package/jsutils/inspect.js +46 -12
  36. package/jsutils/inspect.js.flow +42 -15
  37. package/jsutils/inspect.mjs +45 -5
  38. package/jsutils/instanceOf.js +1 -1
  39. package/jsutils/instanceOf.mjs +1 -1
  40. package/jsutils/invariant.js +1 -1
  41. package/jsutils/invariant.mjs +1 -1
  42. package/jsutils/isInvalid.js +1 -1
  43. package/jsutils/isInvalid.mjs +1 -1
  44. package/jsutils/isNullish.js +1 -1
  45. package/jsutils/isNullish.mjs +1 -1
  46. package/jsutils/isPromise.js +1 -1
  47. package/jsutils/isPromise.mjs +1 -1
  48. package/jsutils/keyMap.js +1 -1
  49. package/jsutils/keyMap.mjs +1 -1
  50. package/jsutils/keyValMap.js +1 -1
  51. package/jsutils/keyValMap.mjs +1 -1
  52. package/jsutils/mapValue.js +54 -0
  53. package/jsutils/mapValue.js.flow +27 -0
  54. package/jsutils/mapValue.mjs +44 -0
  55. package/jsutils/memoize3.js +1 -1
  56. package/jsutils/memoize3.mjs +1 -1
  57. package/jsutils/nodejsCustomInspectSymbol.js +18 -0
  58. package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
  59. package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
  60. package/jsutils/orList.js +17 -4
  61. package/jsutils/orList.js.flow +13 -7
  62. package/jsutils/orList.mjs +14 -4
  63. package/jsutils/promiseForObject.js +1 -1
  64. package/jsutils/promiseForObject.mjs +1 -1
  65. package/jsutils/promiseReduce.js +1 -1
  66. package/jsutils/promiseReduce.mjs +1 -1
  67. package/jsutils/quotedOrList.js +1 -1
  68. package/jsutils/quotedOrList.mjs +1 -1
  69. package/jsutils/suggestionList.js +1 -1
  70. package/jsutils/suggestionList.mjs +1 -1
  71. package/language/blockStringValue.js +2 -2
  72. package/language/blockStringValue.js.flow +1 -1
  73. package/language/blockStringValue.mjs +2 -2
  74. package/language/directiveLocation.js +1 -1
  75. package/language/directiveLocation.mjs +1 -1
  76. package/language/index.mjs +1 -1
  77. package/language/kinds.js +1 -1
  78. package/language/kinds.mjs +1 -1
  79. package/language/lexer.js +29 -13
  80. package/language/lexer.js.flow +34 -20
  81. package/language/lexer.mjs +28 -13
  82. package/language/location.js +1 -1
  83. package/language/location.mjs +1 -1
  84. package/language/parser.js +31 -38
  85. package/language/parser.js.flow +32 -48
  86. package/language/parser.mjs +30 -38
  87. package/language/predicates.js +1 -1
  88. package/language/predicates.mjs +1 -1
  89. package/language/printer.js +13 -7
  90. package/language/printer.js.flow +19 -9
  91. package/language/printer.mjs +13 -7
  92. package/language/source.js +8 -7
  93. package/language/source.mjs +1 -9
  94. package/language/visitor.js +11 -20
  95. package/language/visitor.js.flow +4 -5
  96. package/language/visitor.mjs +8 -20
  97. package/package.json +10 -3
  98. package/polyfills/find.js +31 -0
  99. package/polyfills/find.js.flow +29 -0
  100. package/polyfills/find.mjs +23 -0
  101. package/{jsutils → polyfills}/isFinite.js +1 -1
  102. package/{jsutils → polyfills}/isFinite.js.flow +0 -0
  103. package/{jsutils → polyfills}/isFinite.mjs +1 -1
  104. package/{jsutils → polyfills}/isInteger.js +1 -1
  105. package/{jsutils → polyfills}/isInteger.js.flow +0 -0
  106. package/{jsutils → polyfills}/isInteger.mjs +1 -1
  107. package/polyfills/objectEntries.js +26 -0
  108. package/polyfills/objectEntries.js.flow +19 -0
  109. package/polyfills/objectEntries.mjs +18 -0
  110. package/{jsutils → polyfills}/objectValues.js +1 -1
  111. package/{jsutils → polyfills}/objectValues.js.flow +1 -1
  112. package/{jsutils → polyfills}/objectValues.mjs +1 -1
  113. package/subscription/asyncIteratorReject.mjs +1 -1
  114. package/subscription/index.mjs +1 -1
  115. package/subscription/mapAsyncIterator.mjs +1 -1
  116. package/subscription/subscribe.js +1 -1
  117. package/subscription/subscribe.js.flow +1 -1
  118. package/subscription/subscribe.mjs +2 -2
  119. package/type/definition.js +31 -130
  120. package/type/definition.js.flow +35 -47
  121. package/type/definition.mjs +30 -131
  122. package/type/directives.js +25 -29
  123. package/type/directives.js.flow +24 -20
  124. package/type/directives.mjs +22 -30
  125. package/type/index.js +12 -0
  126. package/type/index.js.flow +4 -0
  127. package/type/index.mjs +5 -3
  128. package/type/introspection.js +3 -3
  129. package/type/introspection.js.flow +1 -1
  130. package/type/introspection.mjs +2 -2
  131. package/type/scalars.js +45 -34
  132. package/type/scalars.js.flow +40 -26
  133. package/type/scalars.mjs +44 -26
  134. package/type/schema.js +82 -87
  135. package/type/schema.js.flow +17 -9
  136. package/type/schema.mjs +79 -86
  137. package/type/validate.js +168 -175
  138. package/type/validate.js.flow +8 -49
  139. package/type/validate.mjs +159 -175
  140. package/utilities/TypeInfo.js +10 -23
  141. package/utilities/TypeInfo.js.flow +1 -1
  142. package/utilities/TypeInfo.mjs +2 -24
  143. package/utilities/assertValidName.js +1 -1
  144. package/utilities/assertValidName.mjs +1 -1
  145. package/utilities/astFromValue.js +2 -2
  146. package/utilities/astFromValue.js.flow +1 -1
  147. package/utilities/astFromValue.mjs +2 -2
  148. package/utilities/buildASTSchema.js +169 -152
  149. package/utilities/buildASTSchema.js.flow +117 -113
  150. package/utilities/buildASTSchema.mjs +160 -152
  151. package/utilities/buildClientSchema.js +24 -14
  152. package/utilities/buildClientSchema.js.flow +24 -14
  153. package/utilities/buildClientSchema.mjs +23 -14
  154. package/utilities/coerceValue.js +38 -19
  155. package/utilities/coerceValue.js.flow +41 -47
  156. package/utilities/coerceValue.mjs +38 -20
  157. package/utilities/concatAST.js +1 -1
  158. package/utilities/concatAST.mjs +1 -1
  159. package/utilities/extendSchema.js +228 -312
  160. package/utilities/extendSchema.js.flow +27 -152
  161. package/utilities/extendSchema.mjs +229 -312
  162. package/utilities/findBreakingChanges.js +7 -5
  163. package/utilities/findBreakingChanges.js.flow +3 -2
  164. package/utilities/findBreakingChanges.mjs +6 -5
  165. package/utilities/findDeprecatedUsages.js +1 -1
  166. package/utilities/findDeprecatedUsages.mjs +1 -1
  167. package/utilities/getOperationAST.js +1 -1
  168. package/utilities/getOperationAST.mjs +1 -1
  169. package/utilities/getOperationRootType.js +1 -1
  170. package/utilities/getOperationRootType.mjs +1 -1
  171. package/utilities/index.mjs +1 -1
  172. package/utilities/introspectionFromSchema.js +1 -1
  173. package/utilities/introspectionFromSchema.mjs +1 -1
  174. package/utilities/introspectionQuery.js +1 -1
  175. package/utilities/introspectionQuery.mjs +1 -1
  176. package/utilities/isValidJSValue.js +1 -1
  177. package/utilities/isValidJSValue.mjs +1 -1
  178. package/utilities/isValidLiteralValue.js +1 -1
  179. package/utilities/isValidLiteralValue.mjs +1 -1
  180. package/utilities/lexicographicSortSchema.js +2 -2
  181. package/utilities/lexicographicSortSchema.js.flow +1 -1
  182. package/utilities/lexicographicSortSchema.mjs +2 -2
  183. package/utilities/schemaPrinter.js +3 -3
  184. package/utilities/schemaPrinter.js.flow +1 -1
  185. package/utilities/schemaPrinter.mjs +2 -2
  186. package/utilities/separateOperations.js +1 -1
  187. package/utilities/separateOperations.mjs +1 -1
  188. package/utilities/typeComparators.js +1 -1
  189. package/utilities/typeComparators.mjs +1 -1
  190. package/utilities/typeFromAST.js +1 -1
  191. package/utilities/typeFromAST.mjs +1 -1
  192. package/utilities/valueFromAST.js +3 -3
  193. package/utilities/valueFromAST.js.flow +1 -1
  194. package/utilities/valueFromAST.mjs +2 -2
  195. package/utilities/valueFromASTUntyped.js +1 -1
  196. package/utilities/valueFromASTUntyped.mjs +1 -1
  197. package/validation/ValidationContext.js +57 -82
  198. package/validation/ValidationContext.js.flow +52 -49
  199. package/validation/ValidationContext.mjs +52 -77
  200. package/validation/index.js.flow +1 -0
  201. package/validation/index.mjs +1 -1
  202. package/validation/rules/ExecutableDefinitions.js +1 -1
  203. package/validation/rules/ExecutableDefinitions.js.flow +1 -1
  204. package/validation/rules/ExecutableDefinitions.mjs +1 -1
  205. package/validation/rules/FieldsOnCorrectType.js +1 -1
  206. package/validation/rules/FieldsOnCorrectType.mjs +1 -1
  207. package/validation/rules/FragmentsOnCompositeTypes.js +1 -1
  208. package/validation/rules/FragmentsOnCompositeTypes.mjs +1 -1
  209. package/validation/rules/KnownArgumentNames.mjs +1 -1
  210. package/validation/rules/KnownDirectives.js +1 -1
  211. package/validation/rules/KnownDirectives.mjs +1 -1
  212. package/validation/rules/KnownFragmentNames.js +1 -1
  213. package/validation/rules/KnownFragmentNames.mjs +1 -1
  214. package/validation/rules/KnownTypeNames.js +59 -21
  215. package/validation/rules/KnownTypeNames.js.flow +54 -20
  216. package/validation/rules/KnownTypeNames.mjs +56 -21
  217. package/validation/rules/LoneAnonymousOperation.js +1 -1
  218. package/validation/rules/LoneAnonymousOperation.mjs +1 -1
  219. package/validation/rules/LoneSchemaDefinition.js +1 -1
  220. package/validation/rules/LoneSchemaDefinition.mjs +1 -1
  221. package/validation/rules/NoFragmentCycles.js +1 -1
  222. package/validation/rules/NoFragmentCycles.js.flow +2 -2
  223. package/validation/rules/NoFragmentCycles.mjs +1 -1
  224. package/validation/rules/NoUndefinedVariables.js +1 -1
  225. package/validation/rules/NoUndefinedVariables.mjs +1 -1
  226. package/validation/rules/NoUnusedFragments.js +1 -1
  227. package/validation/rules/NoUnusedFragments.js.flow +2 -2
  228. package/validation/rules/NoUnusedFragments.mjs +1 -1
  229. package/validation/rules/NoUnusedVariables.js +1 -1
  230. package/validation/rules/NoUnusedVariables.mjs +1 -1
  231. package/validation/rules/OverlappingFieldsCanBeMerged.js +57 -33
  232. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +5 -6
  233. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +48 -33
  234. package/validation/rules/PossibleFragmentSpreads.js +1 -1
  235. package/validation/rules/PossibleFragmentSpreads.mjs +1 -1
  236. package/validation/rules/PossibleTypeExtensions.js +158 -0
  237. package/validation/rules/PossibleTypeExtensions.js.flow +160 -0
  238. package/validation/rules/PossibleTypeExtensions.mjs +146 -0
  239. package/validation/rules/ProvidedRequiredArguments.mjs +1 -1
  240. package/validation/rules/ScalarLeafs.js +1 -1
  241. package/validation/rules/ScalarLeafs.mjs +1 -1
  242. package/validation/rules/SingleFieldSubscriptions.js +1 -1
  243. package/validation/rules/SingleFieldSubscriptions.mjs +1 -1
  244. package/validation/rules/UniqueArgumentNames.js +1 -1
  245. package/validation/rules/UniqueArgumentNames.mjs +1 -1
  246. package/validation/rules/UniqueDirectiveNames.js +55 -0
  247. package/validation/rules/UniqueDirectiveNames.js.flow +64 -0
  248. package/validation/rules/UniqueDirectiveNames.mjs +43 -0
  249. package/validation/rules/UniqueDirectivesPerLocation.js +1 -1
  250. package/validation/rules/UniqueDirectivesPerLocation.mjs +1 -1
  251. package/validation/rules/UniqueEnumValueNames.js +94 -0
  252. package/validation/rules/UniqueEnumValueNames.js.flow +87 -0
  253. package/validation/rules/UniqueEnumValueNames.mjs +81 -0
  254. package/validation/rules/UniqueFieldDefinitionNames.js +105 -0
  255. package/validation/rules/UniqueFieldDefinitionNames.js.flow +101 -0
  256. package/validation/rules/UniqueFieldDefinitionNames.mjs +92 -0
  257. package/validation/rules/UniqueFragmentNames.js +1 -1
  258. package/validation/rules/UniqueFragmentNames.mjs +1 -1
  259. package/validation/rules/UniqueInputFieldNames.js +1 -1
  260. package/validation/rules/UniqueInputFieldNames.mjs +1 -1
  261. package/validation/rules/UniqueOperationNames.js +1 -1
  262. package/validation/rules/UniqueOperationNames.mjs +1 -1
  263. package/validation/rules/UniqueOperationTypes.js +85 -0
  264. package/validation/rules/UniqueOperationTypes.js.flow +76 -0
  265. package/validation/rules/UniqueOperationTypes.mjs +73 -0
  266. package/validation/rules/UniqueTypeNames.js +62 -0
  267. package/validation/rules/UniqueTypeNames.js.flow +67 -0
  268. package/validation/rules/UniqueTypeNames.mjs +50 -0
  269. package/validation/rules/UniqueVariableNames.js +1 -1
  270. package/validation/rules/UniqueVariableNames.mjs +1 -1
  271. package/validation/rules/ValuesOfCorrectType.js +29 -13
  272. package/validation/rules/ValuesOfCorrectType.js.flow +4 -5
  273. package/validation/rules/ValuesOfCorrectType.mjs +28 -13
  274. package/validation/rules/VariablesAreInputTypes.js +1 -1
  275. package/validation/rules/VariablesAreInputTypes.mjs +1 -1
  276. package/validation/rules/VariablesInAllowedPosition.js +4 -4
  277. package/validation/rules/VariablesInAllowedPosition.mjs +4 -4
  278. package/validation/specifiedRules.js +14 -2
  279. package/validation/specifiedRules.js.flow +13 -0
  280. package/validation/specifiedRules.mjs +8 -2
  281. package/validation/validate.js +1 -1
  282. package/validation/validate.mjs +1 -1
  283. package/jsutils/find.js +0 -22
  284. package/jsutils/find.js.flow +0 -19
  285. package/jsutils/find.mjs +0 -15
@@ -12,6 +12,8 @@ exports.parseNamedType = parseNamedType;
12
12
 
13
13
  var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
14
14
 
15
+ var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON"));
16
+
15
17
  var _source = require("./source");
16
18
 
17
19
  var _error = require("../error");
@@ -30,7 +32,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
30
32
  * This source code is licensed under the MIT license found in the
31
33
  * LICENSE file in the root directory of this source tree.
32
34
  *
33
- * strict
35
+ *
34
36
  */
35
37
 
36
38
  /**
@@ -252,23 +254,12 @@ function parseVariableDefinitions(lexer) {
252
254
 
253
255
  function parseVariableDefinition(lexer) {
254
256
  var start = lexer.token;
255
-
256
- if (lexer.options.experimentalVariableDefinitionDirectives) {
257
- return {
258
- kind: _kinds.Kind.VARIABLE_DEFINITION,
259
- variable: parseVariable(lexer),
260
- type: (expect(lexer, _lexer.TokenKind.COLON), parseTypeReference(lexer)),
261
- defaultValue: skip(lexer, _lexer.TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined,
262
- directives: parseDirectives(lexer, true),
263
- loc: loc(lexer, start)
264
- };
265
- }
266
-
267
257
  return {
268
258
  kind: _kinds.Kind.VARIABLE_DEFINITION,
269
259
  variable: parseVariable(lexer),
270
260
  type: (expect(lexer, _lexer.TokenKind.COLON), parseTypeReference(lexer)),
271
261
  defaultValue: skip(lexer, _lexer.TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined,
262
+ directives: parseDirectives(lexer, true),
272
263
  loc: loc(lexer, start)
273
264
  };
274
265
  }
@@ -386,8 +377,9 @@ function parseConstArgument(lexer) {
386
377
  function parseFragment(lexer) {
387
378
  var start = lexer.token;
388
379
  expect(lexer, _lexer.TokenKind.SPREAD);
380
+ var hasTypeCondition = skipKeyword(lexer, 'on');
389
381
 
390
- if (peek(lexer, _lexer.TokenKind.NAME) && lexer.token.value !== 'on') {
382
+ if (!hasTypeCondition && peek(lexer, _lexer.TokenKind.NAME)) {
391
383
  return {
392
384
  kind: _kinds.Kind.FRAGMENT_SPREAD,
393
385
  name: parseFragmentName(lexer),
@@ -396,16 +388,9 @@ function parseFragment(lexer) {
396
388
  };
397
389
  }
398
390
 
399
- var typeCondition;
400
-
401
- if (lexer.token.value === 'on') {
402
- lexer.advance();
403
- typeCondition = parseNamedType(lexer);
404
- }
405
-
406
391
  return {
407
392
  kind: _kinds.Kind.INLINE_FRAGMENT,
408
- typeCondition: typeCondition,
393
+ typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
409
394
  directives: parseDirectives(lexer, false),
410
395
  selectionSet: parseSelectionSet(lexer),
411
396
  loc: loc(lexer, start)
@@ -844,9 +829,8 @@ function parseObjectTypeDefinition(lexer) {
844
829
  function parseImplementsInterfaces(lexer) {
845
830
  var types = [];
846
831
 
847
- if (lexer.token.value === 'implements') {
848
- lexer.advance(); // Optional leading ampersand
849
-
832
+ if (skipKeyword(lexer, 'implements')) {
833
+ // Optional leading ampersand
850
834
  skip(lexer, _lexer.TokenKind.AMP);
851
835
 
852
836
  do {
@@ -1417,17 +1401,16 @@ function Loc(startToken, endToken, source) {
1417
1401
  } // Print a simplified form when appearing in JSON/util.inspect.
1418
1402
 
1419
1403
 
1420
- Loc.prototype.toJSON = Loc.prototype.inspect = function toJSON() {
1404
+ (0, _defineToJSON.default)(Loc, function () {
1421
1405
  return {
1422
1406
  start: this.start,
1423
1407
  end: this.end
1424
1408
  };
1425
- };
1409
+ });
1426
1410
  /**
1427
1411
  * Determines if the next token is of a given kind
1428
1412
  */
1429
1413
 
1430
-
1431
1414
  function peek(lexer, kind) {
1432
1415
  return lexer.token.kind === kind;
1433
1416
  }
@@ -1438,13 +1421,12 @@ function peek(lexer, kind) {
1438
1421
 
1439
1422
 
1440
1423
  function skip(lexer, kind) {
1441
- var match = lexer.token.kind === kind;
1442
-
1443
- if (match) {
1424
+ if (lexer.token.kind === kind) {
1444
1425
  lexer.advance();
1426
+ return true;
1445
1427
  }
1446
1428
 
1447
- return match;
1429
+ return false;
1448
1430
  }
1449
1431
  /**
1450
1432
  * If the next token is of the given kind, return that token after advancing
@@ -1463,21 +1445,32 @@ function expect(lexer, kind) {
1463
1445
  throw (0, _error.syntaxError)(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat((0, _lexer.getTokenDesc)(token)));
1464
1446
  }
1465
1447
  /**
1466
- * If the next token is a keyword with the given value, return that token after
1467
- * advancing the lexer. Otherwise, do not change the parser state and return
1468
- * false.
1448
+ * If the next token is a keyword with the given value, return true after advancing
1449
+ * the lexer. Otherwise, do not change the parser state and return false.
1469
1450
  */
1470
1451
 
1471
1452
 
1472
- function expectKeyword(lexer, value) {
1453
+ function skipKeyword(lexer, value) {
1473
1454
  var token = lexer.token;
1474
1455
 
1475
1456
  if (token.kind === _lexer.TokenKind.NAME && token.value === value) {
1476
1457
  lexer.advance();
1477
- return token;
1458
+ return true;
1478
1459
  }
1479
1460
 
1480
- throw (0, _error.syntaxError)(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat((0, _lexer.getTokenDesc)(token)));
1461
+ return false;
1462
+ }
1463
+ /**
1464
+ * If the next token is a keyword with the given value, return that token after
1465
+ * advancing the lexer. Otherwise, do not change the parser state and throw
1466
+ * an error.
1467
+ */
1468
+
1469
+
1470
+ function expectKeyword(lexer, value) {
1471
+ if (!skipKeyword(lexer, value)) {
1472
+ throw (0, _error.syntaxError)(lexer.source, lexer.token.start, "Expected \"".concat(value, "\", found ").concat((0, _lexer.getTokenDesc)(lexer.token)));
1473
+ }
1481
1474
  }
1482
1475
  /**
1483
1476
  * Helper function for creating an error when an unexpected lexed token
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import inspect from '../jsutils/inspect';
11
+ import defineToJSON from '../jsutils/defineToJSON';
11
12
  import { Source } from './source';
12
13
  import { syntaxError } from '../error';
13
14
  import type { GraphQLError } from '../error';
@@ -115,17 +116,6 @@ export type ParseOptions = {
115
116
  * future.
116
117
  */
117
118
  experimentalFragmentVariables?: boolean,
118
-
119
- /**
120
- * EXPERIMENTAL:
121
- *
122
- * If enabled, the parser understands directives on variable definitions:
123
- *
124
- * query Foo($var: String = "abc" @variable_definition_directive) {
125
- * ...
126
- * }
127
- */
128
- experimentalVariableDefinitionDirectives?: boolean,
129
119
  };
130
120
 
131
121
  /**
@@ -341,19 +331,6 @@ function parseVariableDefinitions(
341
331
  */
342
332
  function parseVariableDefinition(lexer: Lexer<*>): VariableDefinitionNode {
343
333
  const start = lexer.token;
344
- if (lexer.options.experimentalVariableDefinitionDirectives) {
345
- return {
346
- kind: Kind.VARIABLE_DEFINITION,
347
- variable: parseVariable(lexer),
348
- type: (expect(lexer, TokenKind.COLON), parseTypeReference(lexer)),
349
- defaultValue: skip(lexer, TokenKind.EQUALS)
350
- ? parseValueLiteral(lexer, true)
351
- : undefined,
352
- directives: parseDirectives(lexer, true),
353
- loc: loc(lexer, start),
354
- };
355
- }
356
-
357
334
  return {
358
335
  kind: Kind.VARIABLE_DEFINITION,
359
336
  variable: parseVariable(lexer),
@@ -361,6 +338,7 @@ function parseVariableDefinition(lexer: Lexer<*>): VariableDefinitionNode {
361
338
  defaultValue: skip(lexer, TokenKind.EQUALS)
362
339
  ? parseValueLiteral(lexer, true)
363
340
  : undefined,
341
+ directives: parseDirectives(lexer, true),
364
342
  loc: loc(lexer, start),
365
343
  };
366
344
  }
@@ -488,7 +466,9 @@ function parseFragment(
488
466
  ): FragmentSpreadNode | InlineFragmentNode {
489
467
  const start = lexer.token;
490
468
  expect(lexer, TokenKind.SPREAD);
491
- if (peek(lexer, TokenKind.NAME) && lexer.token.value !== 'on') {
469
+
470
+ const hasTypeCondition = skipKeyword(lexer, 'on');
471
+ if (!hasTypeCondition && peek(lexer, TokenKind.NAME)) {
492
472
  return {
493
473
  kind: Kind.FRAGMENT_SPREAD,
494
474
  name: parseFragmentName(lexer),
@@ -496,14 +476,9 @@ function parseFragment(
496
476
  loc: loc(lexer, start),
497
477
  };
498
478
  }
499
- let typeCondition;
500
- if (lexer.token.value === 'on') {
501
- lexer.advance();
502
- typeCondition = parseNamedType(lexer);
503
- }
504
479
  return {
505
480
  kind: Kind.INLINE_FRAGMENT,
506
- typeCondition,
481
+ typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
507
482
  directives: parseDirectives(lexer, false),
508
483
  selectionSet: parseSelectionSet(lexer),
509
484
  loc: loc(lexer, start),
@@ -912,8 +887,7 @@ function parseObjectTypeDefinition(lexer: Lexer<*>): ObjectTypeDefinitionNode {
912
887
  */
913
888
  function parseImplementsInterfaces(lexer: Lexer<*>): Array<NamedTypeNode> {
914
889
  const types = [];
915
- if (lexer.token.value === 'implements') {
916
- lexer.advance();
890
+ if (skipKeyword(lexer, 'implements')) {
917
891
  // Optional leading ampersand
918
892
  skip(lexer, TokenKind.AMP);
919
893
  do {
@@ -1471,9 +1445,9 @@ function Loc(startToken: Token, endToken: Token, source: Source) {
1471
1445
  }
1472
1446
 
1473
1447
  // Print a simplified form when appearing in JSON/util.inspect.
1474
- Loc.prototype.toJSON = Loc.prototype.inspect = function toJSON() {
1448
+ defineToJSON(Loc, function() {
1475
1449
  return { start: this.start, end: this.end };
1476
- };
1450
+ });
1477
1451
 
1478
1452
  /**
1479
1453
  * Determines if the next token is of a given kind
@@ -1487,11 +1461,11 @@ function peek(lexer: Lexer<*>, kind: TokenKindEnum): boolean {
1487
1461
  * the lexer. Otherwise, do not change the parser state and return false.
1488
1462
  */
1489
1463
  function skip(lexer: Lexer<*>, kind: TokenKindEnum): boolean {
1490
- const match = lexer.token.kind === kind;
1491
- if (match) {
1464
+ if (lexer.token.kind === kind) {
1492
1465
  lexer.advance();
1466
+ return true;
1493
1467
  }
1494
- return match;
1468
+ return false;
1495
1469
  }
1496
1470
 
1497
1471
  /**
@@ -1512,21 +1486,31 @@ function expect(lexer: Lexer<*>, kind: TokenKindEnum): Token {
1512
1486
  }
1513
1487
 
1514
1488
  /**
1515
- * If the next token is a keyword with the given value, return that token after
1516
- * advancing the lexer. Otherwise, do not change the parser state and return
1517
- * false.
1489
+ * If the next token is a keyword with the given value, return true after advancing
1490
+ * the lexer. Otherwise, do not change the parser state and return false.
1518
1491
  */
1519
- function expectKeyword(lexer: Lexer<*>, value: string): Token {
1492
+ function skipKeyword(lexer: Lexer<*>, value: string): boolean {
1520
1493
  const token = lexer.token;
1521
1494
  if (token.kind === TokenKind.NAME && token.value === value) {
1522
1495
  lexer.advance();
1523
- return token;
1496
+ return true;
1497
+ }
1498
+ return false;
1499
+ }
1500
+
1501
+ /**
1502
+ * If the next token is a keyword with the given value, return that token after
1503
+ * advancing the lexer. Otherwise, do not change the parser state and throw
1504
+ * an error.
1505
+ */
1506
+ function expectKeyword(lexer: Lexer<*>, value: string): void {
1507
+ if (!skipKeyword(lexer, value)) {
1508
+ throw syntaxError(
1509
+ lexer.source,
1510
+ lexer.token.start,
1511
+ `Expected "${value}", found ${getTokenDesc(lexer.token)}`,
1512
+ );
1524
1513
  }
1525
- throw syntaxError(
1526
- lexer.source,
1527
- token.start,
1528
- `Expected "${value}", found ${getTokenDesc(token)}`,
1529
- );
1530
1514
  }
1531
1515
 
1532
1516
  /**
@@ -4,9 +4,10 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * strict
7
+ *
8
8
  */
9
9
  import inspect from '../jsutils/inspect';
10
+ import defineToJSON from '../jsutils/defineToJSON';
10
11
  import { Source } from './source';
11
12
  import { syntaxError } from '../error';
12
13
  import { createLexer, TokenKind, getTokenDesc } from './lexer';
@@ -232,23 +233,12 @@ function parseVariableDefinitions(lexer) {
232
233
 
233
234
  function parseVariableDefinition(lexer) {
234
235
  var start = lexer.token;
235
-
236
- if (lexer.options.experimentalVariableDefinitionDirectives) {
237
- return {
238
- kind: Kind.VARIABLE_DEFINITION,
239
- variable: parseVariable(lexer),
240
- type: (expect(lexer, TokenKind.COLON), parseTypeReference(lexer)),
241
- defaultValue: skip(lexer, TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined,
242
- directives: parseDirectives(lexer, true),
243
- loc: loc(lexer, start)
244
- };
245
- }
246
-
247
236
  return {
248
237
  kind: Kind.VARIABLE_DEFINITION,
249
238
  variable: parseVariable(lexer),
250
239
  type: (expect(lexer, TokenKind.COLON), parseTypeReference(lexer)),
251
240
  defaultValue: skip(lexer, TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined,
241
+ directives: parseDirectives(lexer, true),
252
242
  loc: loc(lexer, start)
253
243
  };
254
244
  }
@@ -366,8 +356,9 @@ function parseConstArgument(lexer) {
366
356
  function parseFragment(lexer) {
367
357
  var start = lexer.token;
368
358
  expect(lexer, TokenKind.SPREAD);
359
+ var hasTypeCondition = skipKeyword(lexer, 'on');
369
360
 
370
- if (peek(lexer, TokenKind.NAME) && lexer.token.value !== 'on') {
361
+ if (!hasTypeCondition && peek(lexer, TokenKind.NAME)) {
371
362
  return {
372
363
  kind: Kind.FRAGMENT_SPREAD,
373
364
  name: parseFragmentName(lexer),
@@ -376,16 +367,9 @@ function parseFragment(lexer) {
376
367
  };
377
368
  }
378
369
 
379
- var typeCondition;
380
-
381
- if (lexer.token.value === 'on') {
382
- lexer.advance();
383
- typeCondition = parseNamedType(lexer);
384
- }
385
-
386
370
  return {
387
371
  kind: Kind.INLINE_FRAGMENT,
388
- typeCondition: typeCondition,
372
+ typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
389
373
  directives: parseDirectives(lexer, false),
390
374
  selectionSet: parseSelectionSet(lexer),
391
375
  loc: loc(lexer, start)
@@ -822,9 +806,8 @@ function parseObjectTypeDefinition(lexer) {
822
806
  function parseImplementsInterfaces(lexer) {
823
807
  var types = [];
824
808
 
825
- if (lexer.token.value === 'implements') {
826
- lexer.advance(); // Optional leading ampersand
827
-
809
+ if (skipKeyword(lexer, 'implements')) {
810
+ // Optional leading ampersand
828
811
  skip(lexer, TokenKind.AMP);
829
812
 
830
813
  do {
@@ -1395,17 +1378,16 @@ function Loc(startToken, endToken, source) {
1395
1378
  } // Print a simplified form when appearing in JSON/util.inspect.
1396
1379
 
1397
1380
 
1398
- Loc.prototype.toJSON = Loc.prototype.inspect = function toJSON() {
1381
+ defineToJSON(Loc, function () {
1399
1382
  return {
1400
1383
  start: this.start,
1401
1384
  end: this.end
1402
1385
  };
1403
- };
1386
+ });
1404
1387
  /**
1405
1388
  * Determines if the next token is of a given kind
1406
1389
  */
1407
1390
 
1408
-
1409
1391
  function peek(lexer, kind) {
1410
1392
  return lexer.token.kind === kind;
1411
1393
  }
@@ -1416,13 +1398,12 @@ function peek(lexer, kind) {
1416
1398
 
1417
1399
 
1418
1400
  function skip(lexer, kind) {
1419
- var match = lexer.token.kind === kind;
1420
-
1421
- if (match) {
1401
+ if (lexer.token.kind === kind) {
1422
1402
  lexer.advance();
1403
+ return true;
1423
1404
  }
1424
1405
 
1425
- return match;
1406
+ return false;
1426
1407
  }
1427
1408
  /**
1428
1409
  * If the next token is of the given kind, return that token after advancing
@@ -1441,21 +1422,32 @@ function expect(lexer, kind) {
1441
1422
  throw syntaxError(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token)));
1442
1423
  }
1443
1424
  /**
1444
- * If the next token is a keyword with the given value, return that token after
1445
- * advancing the lexer. Otherwise, do not change the parser state and return
1446
- * false.
1425
+ * If the next token is a keyword with the given value, return true after advancing
1426
+ * the lexer. Otherwise, do not change the parser state and return false.
1447
1427
  */
1448
1428
 
1449
1429
 
1450
- function expectKeyword(lexer, value) {
1430
+ function skipKeyword(lexer, value) {
1451
1431
  var token = lexer.token;
1452
1432
 
1453
1433
  if (token.kind === TokenKind.NAME && token.value === value) {
1454
1434
  lexer.advance();
1455
- return token;
1435
+ return true;
1456
1436
  }
1457
1437
 
1458
- throw syntaxError(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token)));
1438
+ return false;
1439
+ }
1440
+ /**
1441
+ * If the next token is a keyword with the given value, return that token after
1442
+ * advancing the lexer. Otherwise, do not change the parser state and throw
1443
+ * an error.
1444
+ */
1445
+
1446
+
1447
+ function expectKeyword(lexer, value) {
1448
+ if (!skipKeyword(lexer, value)) {
1449
+ throw syntaxError(lexer.source, lexer.token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(lexer.token)));
1450
+ }
1459
1451
  }
1460
1452
  /**
1461
1453
  * Helper function for creating an error when an unexpected lexed token
@@ -21,7 +21,7 @@ var _kinds = require("./kinds");
21
21
  * This source code is licensed under the MIT license found in the
22
22
  * LICENSE file in the root directory of this source tree.
23
23
  *
24
- * strict
24
+ *
25
25
  */
26
26
  function isDefinitionNode(node) {
27
27
  return isExecutableDefinitionNode(node) || isTypeSystemDefinitionNode(node) || isTypeSystemExtensionNode(node);
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * strict
7
+ *
8
8
  */
9
9
  import { Kind } from './kinds';
10
10
  export function isDefinitionNode(node) {
@@ -12,6 +12,8 @@ var _visitor = require("./visitor");
12
12
  *
13
13
  * This source code is licensed under the MIT license found in the
14
14
  * LICENSE file in the root directory of this source tree.
15
+ *
16
+ *
15
17
  */
16
18
 
17
19
  /**
@@ -177,9 +179,7 @@ var printDocASTReducer = {
177
179
  args = _ref24.arguments,
178
180
  type = _ref24.type,
179
181
  directives = _ref24.directives;
180
- return name + (args.every(function (arg) {
181
- return arg.indexOf('\n') === -1;
182
- }) ? wrap('(', join(args, ', '), ')') : wrap('(\n', indent(join(args, '\n')), '\n)')) + ': ' + type + wrap(' ', join(directives, ' '));
182
+ return name + (hasMultilineItems(args) ? wrap('(\n', indent(join(args, '\n')), '\n)') : wrap('(', join(args, ', '), ')')) + ': ' + type + wrap(' ', join(directives, ' '));
183
183
  }),
184
184
  InputValueDefinition: addDescription(function (_ref25) {
185
185
  var name = _ref25.name,
@@ -221,9 +221,7 @@ var printDocASTReducer = {
221
221
  var name = _ref31.name,
222
222
  args = _ref31.arguments,
223
223
  locations = _ref31.locations;
224
- return 'directive @' + name + (args.every(function (arg) {
225
- return arg.indexOf('\n') === -1;
226
- }) ? wrap('(', join(args, ', '), ')') : wrap('(\n', indent(join(args, '\n')), '\n)')) + ' on ' + join(locations, ' | ');
224
+ return 'directive @' + name + (hasMultilineItems(args) ? wrap('(\n', indent(join(args, '\n')), '\n)') : wrap('(', join(args, ', '), ')')) + ' on ' + join(locations, ' | ');
227
225
  }),
228
226
  SchemaExtension: function SchemaExtension(_ref32) {
229
227
  var directives = _ref32.directives,
@@ -306,6 +304,14 @@ function wrap(start, maybeString, end) {
306
304
  function indent(maybeString) {
307
305
  return maybeString && ' ' + maybeString.replace(/\n/g, '\n ');
308
306
  }
307
+
308
+ function isMultiline(string) {
309
+ return string.indexOf('\n') !== -1;
310
+ }
311
+
312
+ function hasMultilineItems(maybeArray) {
313
+ return maybeArray && maybeArray.some(isMultiline);
314
+ }
309
315
  /**
310
316
  * Print a block string in the indented block form by adding a leading and
311
317
  * trailing blank line. However, if a block string starts with whitespace and is
@@ -315,5 +321,5 @@ function indent(maybeString) {
315
321
 
316
322
  function printBlockString(value, isDescription) {
317
323
  var escaped = value.replace(/"""/g, '\\"""');
318
- return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1 ? "\"\"\"".concat(escaped.replace(/"$/, '"\n'), "\"\"\"") : "\"\"\"\n".concat(isDescription ? escaped : indent(escaped), "\n\"\"\"");
324
+ return isMultiline(value) || value[0] !== ' ' && value[0] !== '\t' ? "\"\"\"\n".concat(isDescription ? escaped : indent(escaped), "\n\"\"\"") : "\"\"\"".concat(escaped.replace(/"$/, '"\n'), "\"\"\"");
319
325
  }
@@ -3,6 +3,8 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noflow
6
8
  */
7
9
 
8
10
  import { visit } from './visitor';
@@ -134,9 +136,9 @@ const printDocASTReducer = {
134
136
  FieldDefinition: addDescription(
135
137
  ({ name, arguments: args, type, directives }) =>
136
138
  name +
137
- (args.every(arg => arg.indexOf('\n') === -1)
138
- ? wrap('(', join(args, ', '), ')')
139
- : wrap('(\n', indent(join(args, '\n')), '\n)')) +
139
+ (hasMultilineItems(args)
140
+ ? wrap('(\n', indent(join(args, '\n')), '\n)')
141
+ : wrap('(', join(args, ', '), ')')) +
140
142
  ': ' +
141
143
  type +
142
144
  wrap(' ', join(directives, ' ')),
@@ -182,9 +184,9 @@ const printDocASTReducer = {
182
184
  ({ name, arguments: args, locations }) =>
183
185
  'directive @' +
184
186
  name +
185
- (args.every(arg => arg.indexOf('\n') === -1)
186
- ? wrap('(', join(args, ', '), ')')
187
- : wrap('(\n', indent(join(args, '\n')), '\n)')) +
187
+ (hasMultilineItems(args)
188
+ ? wrap('(\n', indent(join(args, '\n')), '\n)')
189
+ : wrap('(', join(args, ', '), ')')) +
188
190
  ' on ' +
189
191
  join(locations, ' | '),
190
192
  ),
@@ -262,6 +264,14 @@ function indent(maybeString) {
262
264
  return maybeString && ' ' + maybeString.replace(/\n/g, '\n ');
263
265
  }
264
266
 
267
+ function isMultiline(string) {
268
+ return string.indexOf('\n') !== -1;
269
+ }
270
+
271
+ function hasMultilineItems(maybeArray) {
272
+ return maybeArray && maybeArray.some(isMultiline);
273
+ }
274
+
265
275
  /**
266
276
  * Print a block string in the indented block form by adding a leading and
267
277
  * trailing blank line. However, if a block string starts with whitespace and is
@@ -269,7 +279,7 @@ function indent(maybeString) {
269
279
  */
270
280
  function printBlockString(value, isDescription) {
271
281
  const escaped = value.replace(/"""/g, '\\"""');
272
- return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1
273
- ? `"""${escaped.replace(/"$/, '"\n')}"""`
274
- : `"""\n${isDescription ? escaped : indent(escaped)}\n"""`;
282
+ return isMultiline(value) || (value[0] !== ' ' && value[0] !== '\t')
283
+ ? `"""\n${isDescription ? escaped : indent(escaped)}\n"""`
284
+ : `"""${escaped.replace(/"$/, '"\n')}"""`;
275
285
  }
@@ -3,6 +3,8 @@
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
6
8
  */
7
9
  import { visit } from './visitor';
8
10
  /**
@@ -168,9 +170,7 @@ var printDocASTReducer = {
168
170
  args = _ref24.arguments,
169
171
  type = _ref24.type,
170
172
  directives = _ref24.directives;
171
- return name + (args.every(function (arg) {
172
- return arg.indexOf('\n') === -1;
173
- }) ? wrap('(', join(args, ', '), ')') : wrap('(\n', indent(join(args, '\n')), '\n)')) + ': ' + type + wrap(' ', join(directives, ' '));
173
+ return name + (hasMultilineItems(args) ? wrap('(\n', indent(join(args, '\n')), '\n)') : wrap('(', join(args, ', '), ')')) + ': ' + type + wrap(' ', join(directives, ' '));
174
174
  }),
175
175
  InputValueDefinition: addDescription(function (_ref25) {
176
176
  var name = _ref25.name,
@@ -212,9 +212,7 @@ var printDocASTReducer = {
212
212
  var name = _ref31.name,
213
213
  args = _ref31.arguments,
214
214
  locations = _ref31.locations;
215
- return 'directive @' + name + (args.every(function (arg) {
216
- return arg.indexOf('\n') === -1;
217
- }) ? wrap('(', join(args, ', '), ')') : wrap('(\n', indent(join(args, '\n')), '\n)')) + ' on ' + join(locations, ' | ');
215
+ return 'directive @' + name + (hasMultilineItems(args) ? wrap('(\n', indent(join(args, '\n')), '\n)') : wrap('(', join(args, ', '), ')')) + ' on ' + join(locations, ' | ');
218
216
  }),
219
217
  SchemaExtension: function SchemaExtension(_ref32) {
220
218
  var directives = _ref32.directives,
@@ -297,6 +295,14 @@ function wrap(start, maybeString, end) {
297
295
  function indent(maybeString) {
298
296
  return maybeString && ' ' + maybeString.replace(/\n/g, '\n ');
299
297
  }
298
+
299
+ function isMultiline(string) {
300
+ return string.indexOf('\n') !== -1;
301
+ }
302
+
303
+ function hasMultilineItems(maybeArray) {
304
+ return maybeArray && maybeArray.some(isMultiline);
305
+ }
300
306
  /**
301
307
  * Print a block string in the indented block form by adding a leading and
302
308
  * trailing blank line. However, if a block string starts with whitespace and is
@@ -306,5 +312,5 @@ function indent(maybeString) {
306
312
 
307
313
  function printBlockString(value, isDescription) {
308
314
  var escaped = value.replace(/"""/g, '\\"""');
309
- return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1 ? "\"\"\"".concat(escaped.replace(/"$/, '"\n'), "\"\"\"") : "\"\"\"\n".concat(isDescription ? escaped : indent(escaped), "\n\"\"\"");
315
+ return isMultiline(value) || value[0] !== ' ' && value[0] !== '\t' ? "\"\"\"\n".concat(isDescription ? escaped : indent(escaped), "\n\"\"\"") : "\"\"\"".concat(escaped.replace(/"$/, '"\n'), "\"\"\"");
310
316
  }
@@ -11,7 +11,14 @@ var _defineToStringTag = _interopRequireDefault(require("../jsutils/defineToStri
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ /**
15
+ * Copyright (c) 2015-present, Facebook, Inc.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ *
21
+ */
15
22
 
16
23
  /**
17
24
  * A representation of source input to GraphQL.
@@ -22,12 +29,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
22
29
  * line and column in locationOffset are 1-indexed
23
30
  */
24
31
  var Source = function Source(body, name, locationOffset) {
25
- _defineProperty(this, "body", void 0);
26
-
27
- _defineProperty(this, "name", void 0);
28
-
29
- _defineProperty(this, "locationOffset", void 0);
30
-
31
32
  this.body = body;
32
33
  this.name = name || 'GraphQL request';
33
34
  this.locationOffset = locationOffset || {