graphql 14.0.2 → 14.2.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 (361) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -5
  3. package/codecov.yml +14 -0
  4. package/error/GraphQLError.js +2 -2
  5. package/error/GraphQLError.js.flow +4 -4
  6. package/error/GraphQLError.mjs +2 -2
  7. package/error/formatError.js +2 -2
  8. package/error/formatError.js.flow +1 -1
  9. package/error/formatError.mjs +2 -2
  10. package/error/index.js.flow +1 -1
  11. package/error/index.mjs +2 -2
  12. package/error/locatedError.js +2 -2
  13. package/error/locatedError.js.flow +1 -1
  14. package/error/locatedError.mjs +2 -2
  15. package/error/printError.js +2 -2
  16. package/error/printError.js.flow +1 -1
  17. package/error/printError.mjs +2 -2
  18. package/error/syntaxError.js +2 -2
  19. package/error/syntaxError.js.flow +1 -1
  20. package/error/syntaxError.mjs +2 -2
  21. package/execution/execute.js +20 -11
  22. package/execution/execute.js.flow +41 -27
  23. package/execution/execute.mjs +19 -13
  24. package/execution/index.js +6 -0
  25. package/execution/index.js.flow +7 -2
  26. package/execution/index.mjs +3 -3
  27. package/execution/values.js +10 -10
  28. package/execution/values.js.flow +8 -8
  29. package/execution/values.mjs +9 -9
  30. package/graphql.js +8 -8
  31. package/graphql.js.flow +18 -4
  32. package/graphql.mjs +8 -8
  33. package/index.js +18 -0
  34. package/index.js.flow +4 -1
  35. package/index.mjs +4 -4
  36. package/jsutils/ObjMap.js.flow +1 -1
  37. package/jsutils/{MaybePromise.js → PromiseOrValue.js} +0 -0
  38. package/jsutils/{MaybePromise.js.flow → PromiseOrValue.js.flow} +2 -2
  39. package/jsutils/{MaybePromise.mjs → PromiseOrValue.mjs} +0 -0
  40. package/jsutils/dedent.js +2 -2
  41. package/jsutils/dedent.js.flow +1 -1
  42. package/jsutils/dedent.mjs +2 -2
  43. package/jsutils/defineToJSON.js +18 -7
  44. package/jsutils/defineToJSON.js.flow +15 -6
  45. package/jsutils/defineToJSON.mjs +15 -7
  46. package/jsutils/defineToStringTag.js +6 -6
  47. package/jsutils/defineToStringTag.js.flow +4 -4
  48. package/jsutils/defineToStringTag.mjs +5 -5
  49. package/jsutils/inspect.js +109 -23
  50. package/jsutils/inspect.js.flow +112 -14
  51. package/jsutils/inspect.mjs +108 -17
  52. package/jsutils/instanceOf.js +2 -2
  53. package/jsutils/instanceOf.js.flow +1 -1
  54. package/jsutils/instanceOf.mjs +2 -2
  55. package/jsutils/invariant.js +2 -2
  56. package/jsutils/invariant.js.flow +1 -1
  57. package/jsutils/invariant.mjs +2 -2
  58. package/jsutils/isInvalid.js +2 -2
  59. package/jsutils/isInvalid.js.flow +1 -1
  60. package/jsutils/isInvalid.mjs +2 -2
  61. package/jsutils/isNullish.js +2 -2
  62. package/jsutils/isNullish.js.flow +1 -1
  63. package/jsutils/isNullish.mjs +2 -2
  64. package/jsutils/isPromise.js +2 -2
  65. package/jsutils/isPromise.js.flow +1 -1
  66. package/jsutils/isPromise.mjs +2 -2
  67. package/jsutils/keyMap.js +2 -2
  68. package/jsutils/keyMap.js.flow +1 -1
  69. package/jsutils/keyMap.mjs +2 -2
  70. package/jsutils/keyValMap.js +2 -2
  71. package/jsutils/keyValMap.js.flow +1 -1
  72. package/jsutils/keyValMap.mjs +2 -2
  73. package/jsutils/mapValue.js +54 -0
  74. package/jsutils/mapValue.js.flow +27 -0
  75. package/jsutils/mapValue.mjs +44 -0
  76. package/jsutils/memoize3.js +2 -2
  77. package/jsutils/memoize3.js.flow +1 -1
  78. package/jsutils/memoize3.mjs +2 -2
  79. package/jsutils/nodejsCustomInspectSymbol.js +18 -0
  80. package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
  81. package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
  82. package/jsutils/orList.js +18 -5
  83. package/jsutils/orList.js.flow +14 -8
  84. package/jsutils/orList.mjs +15 -5
  85. package/jsutils/promiseForObject.js +2 -2
  86. package/jsutils/promiseForObject.js.flow +1 -1
  87. package/jsutils/promiseForObject.mjs +2 -2
  88. package/jsutils/promiseReduce.js +2 -2
  89. package/jsutils/promiseReduce.js.flow +5 -5
  90. package/jsutils/promiseReduce.mjs +2 -2
  91. package/jsutils/quotedOrList.js +2 -2
  92. package/jsutils/quotedOrList.js.flow +1 -1
  93. package/jsutils/quotedOrList.mjs +2 -2
  94. package/jsutils/suggestionList.js +2 -2
  95. package/jsutils/suggestionList.js.flow +1 -1
  96. package/jsutils/suggestionList.mjs +2 -2
  97. package/language/ast.js.flow +1 -1
  98. package/language/{blockStringValue.mjs → blockString.js} +39 -3
  99. package/language/{blockStringValue.js.flow → blockString.js.flow} +31 -2
  100. package/language/{blockStringValue.js → blockString.mjs} +31 -10
  101. package/language/directiveLocation.js +2 -2
  102. package/language/directiveLocation.js.flow +1 -1
  103. package/language/directiveLocation.mjs +2 -2
  104. package/language/index.js.flow +1 -1
  105. package/language/index.mjs +2 -2
  106. package/language/kinds.js +2 -2
  107. package/language/kinds.js.flow +1 -1
  108. package/language/kinds.mjs +2 -2
  109. package/language/lexer.js +60 -46
  110. package/language/lexer.js.flow +71 -69
  111. package/language/lexer.mjs +58 -45
  112. package/language/location.js +2 -2
  113. package/language/location.js.flow +1 -1
  114. package/language/location.mjs +2 -2
  115. package/language/parser.js +84 -83
  116. package/language/parser.js.flow +85 -94
  117. package/language/parser.mjs +83 -83
  118. package/language/predicates.js +2 -2
  119. package/language/predicates.js.flow +1 -1
  120. package/language/predicates.mjs +2 -2
  121. package/language/printer.js +15 -17
  122. package/language/printer.js.flow +21 -20
  123. package/language/printer.mjs +14 -17
  124. package/language/source.js +8 -7
  125. package/language/source.js.flow +1 -1
  126. package/language/source.mjs +2 -10
  127. package/language/visitor.js +7 -6
  128. package/language/visitor.js.flow +3 -5
  129. package/language/visitor.mjs +7 -6
  130. package/package.json +5 -2
  131. package/polyfills/find.js +31 -0
  132. package/polyfills/find.js.flow +29 -0
  133. package/polyfills/find.mjs +23 -0
  134. package/polyfills/flatMap.js +38 -0
  135. package/polyfills/flatMap.js.flow +34 -0
  136. package/polyfills/flatMap.mjs +30 -0
  137. package/{jsutils → polyfills}/isFinite.js +2 -2
  138. package/{jsutils → polyfills}/isFinite.js.flow +1 -1
  139. package/{jsutils → polyfills}/isFinite.mjs +2 -2
  140. package/{jsutils → polyfills}/isInteger.js +2 -2
  141. package/{jsutils → polyfills}/isInteger.js.flow +1 -1
  142. package/{jsutils → polyfills}/isInteger.mjs +2 -2
  143. package/polyfills/objectEntries.js +26 -0
  144. package/polyfills/objectEntries.js.flow +19 -0
  145. package/polyfills/objectEntries.mjs +18 -0
  146. package/{jsutils → polyfills}/objectValues.js +2 -2
  147. package/{jsutils → polyfills}/objectValues.js.flow +2 -2
  148. package/{jsutils → polyfills}/objectValues.mjs +2 -2
  149. package/subscription/asyncIteratorReject.js.flow +1 -1
  150. package/subscription/asyncIteratorReject.mjs +2 -2
  151. package/subscription/index.js.flow +1 -1
  152. package/subscription/index.mjs +2 -2
  153. package/subscription/mapAsyncIterator.js.flow +5 -5
  154. package/subscription/mapAsyncIterator.mjs +2 -2
  155. package/subscription/subscribe.js +2 -2
  156. package/subscription/subscribe.js.flow +1 -1
  157. package/subscription/subscribe.mjs +2 -2
  158. package/type/definition.js +161 -138
  159. package/type/definition.js.flow +193 -57
  160. package/type/definition.mjs +158 -140
  161. package/type/directives.js +35 -29
  162. package/type/directives.js.flow +39 -21
  163. package/type/directives.mjs +34 -31
  164. package/type/index.js +12 -0
  165. package/type/index.js.flow +5 -1
  166. package/type/index.mjs +6 -4
  167. package/type/introspection.js +11 -7
  168. package/type/introspection.js.flow +11 -8
  169. package/type/introspection.mjs +11 -7
  170. package/type/scalars.js +45 -34
  171. package/type/scalars.js.flow +41 -27
  172. package/type/scalars.mjs +45 -27
  173. package/type/schema.js +134 -88
  174. package/type/schema.js.flow +77 -11
  175. package/type/schema.mjs +132 -88
  176. package/type/validate.js +152 -187
  177. package/type/validate.js.flow +12 -61
  178. package/type/validate.mjs +143 -188
  179. package/utilities/TypeInfo.js +10 -23
  180. package/utilities/TypeInfo.js.flow +2 -2
  181. package/utilities/TypeInfo.mjs +3 -25
  182. package/utilities/assertValidName.js +2 -2
  183. package/utilities/assertValidName.js.flow +1 -1
  184. package/utilities/assertValidName.mjs +2 -2
  185. package/utilities/astFromValue.js +7 -6
  186. package/utilities/astFromValue.js.flow +7 -6
  187. package/utilities/astFromValue.mjs +9 -8
  188. package/utilities/buildASTSchema.js +213 -197
  189. package/utilities/buildASTSchema.js.flow +163 -173
  190. package/utilities/buildASTSchema.mjs +203 -198
  191. package/utilities/buildClientSchema.js +39 -47
  192. package/utilities/buildClientSchema.js.flow +49 -58
  193. package/utilities/buildClientSchema.mjs +38 -46
  194. package/utilities/coerceValue.js +41 -21
  195. package/utilities/coerceValue.js.flow +44 -49
  196. package/utilities/coerceValue.mjs +42 -23
  197. package/utilities/concatAST.js +9 -13
  198. package/utilities/concatAST.js.flow +3 -9
  199. package/utilities/concatAST.mjs +6 -13
  200. package/utilities/extendSchema.js +256 -630
  201. package/utilities/extendSchema.js.flow +190 -426
  202. package/utilities/extendSchema.mjs +256 -631
  203. package/utilities/findBreakingChanges.js +8 -6
  204. package/utilities/findBreakingChanges.js.flow +4 -3
  205. package/utilities/findBreakingChanges.mjs +7 -6
  206. package/utilities/findDeprecatedUsages.js +4 -4
  207. package/utilities/findDeprecatedUsages.js.flow +3 -3
  208. package/utilities/findDeprecatedUsages.mjs +4 -4
  209. package/utilities/getOperationAST.js +2 -2
  210. package/utilities/getOperationAST.js.flow +1 -1
  211. package/utilities/getOperationAST.mjs +2 -2
  212. package/utilities/getOperationRootType.js +6 -6
  213. package/utilities/getOperationRootType.js.flow +9 -7
  214. package/utilities/getOperationRootType.mjs +6 -6
  215. package/utilities/index.js.flow +1 -1
  216. package/utilities/index.mjs +2 -2
  217. package/utilities/introspectionFromSchema.js +2 -2
  218. package/utilities/introspectionFromSchema.js.flow +1 -1
  219. package/utilities/introspectionFromSchema.mjs +2 -2
  220. package/utilities/introspectionQuery.js +2 -2
  221. package/utilities/introspectionQuery.js.flow +1 -1
  222. package/utilities/introspectionQuery.mjs +2 -2
  223. package/utilities/isValidJSValue.js +4 -2
  224. package/utilities/isValidJSValue.js.flow +2 -1
  225. package/utilities/isValidJSValue.mjs +4 -2
  226. package/utilities/isValidLiteralValue.js +2 -2
  227. package/utilities/isValidLiteralValue.js.flow +1 -1
  228. package/utilities/isValidLiteralValue.mjs +2 -2
  229. package/utilities/lexicographicSortSchema.js +86 -124
  230. package/utilities/lexicographicSortSchema.js.flow +68 -96
  231. package/utilities/lexicographicSortSchema.mjs +86 -124
  232. package/utilities/schemaPrinter.js +47 -73
  233. package/utilities/schemaPrinter.js.flow +62 -111
  234. package/utilities/schemaPrinter.mjs +46 -73
  235. package/utilities/separateOperations.js +11 -10
  236. package/utilities/separateOperations.js.flow +1 -1
  237. package/utilities/separateOperations.mjs +11 -10
  238. package/utilities/typeComparators.js +2 -2
  239. package/utilities/typeComparators.js.flow +1 -1
  240. package/utilities/typeComparators.mjs +2 -2
  241. package/utilities/typeFromAST.js +9 -4
  242. package/utilities/typeFromAST.js.flow +5 -2
  243. package/utilities/typeFromAST.mjs +6 -4
  244. package/utilities/valueFromAST.js +9 -6
  245. package/utilities/valueFromAST.js.flow +5 -3
  246. package/utilities/valueFromAST.mjs +7 -5
  247. package/utilities/valueFromASTUntyped.js +7 -4
  248. package/utilities/valueFromASTUntyped.js.flow +5 -2
  249. package/utilities/valueFromASTUntyped.mjs +6 -4
  250. package/validation/ValidationContext.js +57 -82
  251. package/validation/ValidationContext.js.flow +53 -50
  252. package/validation/ValidationContext.mjs +53 -78
  253. package/validation/index.js.flow +1 -1
  254. package/validation/index.mjs +2 -2
  255. package/validation/rules/ExecutableDefinitions.js +3 -3
  256. package/validation/rules/ExecutableDefinitions.js.flow +3 -3
  257. package/validation/rules/ExecutableDefinitions.mjs +3 -3
  258. package/validation/rules/FieldsOnCorrectType.js +3 -3
  259. package/validation/rules/FieldsOnCorrectType.js.flow +2 -2
  260. package/validation/rules/FieldsOnCorrectType.mjs +3 -3
  261. package/validation/rules/FragmentsOnCompositeTypes.js +4 -4
  262. package/validation/rules/FragmentsOnCompositeTypes.js.flow +3 -3
  263. package/validation/rules/FragmentsOnCompositeTypes.mjs +4 -4
  264. package/validation/rules/KnownArgumentNames.js.flow +1 -1
  265. package/validation/rules/KnownArgumentNames.mjs +2 -2
  266. package/validation/rules/KnownDirectives.js +4 -4
  267. package/validation/rules/KnownDirectives.js.flow +5 -4
  268. package/validation/rules/KnownDirectives.mjs +4 -4
  269. package/validation/rules/KnownFragmentNames.js +3 -3
  270. package/validation/rules/KnownFragmentNames.js.flow +2 -2
  271. package/validation/rules/KnownFragmentNames.mjs +3 -3
  272. package/validation/rules/KnownTypeNames.js +60 -22
  273. package/validation/rules/KnownTypeNames.js.flow +55 -21
  274. package/validation/rules/KnownTypeNames.mjs +57 -22
  275. package/validation/rules/LoneAnonymousOperation.js +3 -3
  276. package/validation/rules/LoneAnonymousOperation.js.flow +2 -2
  277. package/validation/rules/LoneAnonymousOperation.mjs +3 -3
  278. package/validation/rules/LoneSchemaDefinition.js +2 -2
  279. package/validation/rules/LoneSchemaDefinition.js.flow +1 -1
  280. package/validation/rules/LoneSchemaDefinition.mjs +2 -2
  281. package/validation/rules/NoFragmentCycles.js +2 -2
  282. package/validation/rules/NoFragmentCycles.js.flow +3 -3
  283. package/validation/rules/NoFragmentCycles.mjs +2 -2
  284. package/validation/rules/NoUndefinedVariables.js +2 -2
  285. package/validation/rules/NoUndefinedVariables.js.flow +1 -1
  286. package/validation/rules/NoUndefinedVariables.mjs +2 -2
  287. package/validation/rules/NoUnusedFragments.js +10 -7
  288. package/validation/rules/NoUnusedFragments.js.flow +4 -4
  289. package/validation/rules/NoUnusedFragments.mjs +10 -7
  290. package/validation/rules/NoUnusedVariables.js +7 -5
  291. package/validation/rules/NoUnusedVariables.js.flow +4 -3
  292. package/validation/rules/NoUnusedVariables.mjs +7 -5
  293. package/validation/rules/OverlappingFieldsCanBeMerged.js +58 -33
  294. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +4 -4
  295. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +50 -34
  296. package/validation/rules/PossibleFragmentSpreads.js +4 -4
  297. package/validation/rules/PossibleFragmentSpreads.js.flow +3 -3
  298. package/validation/rules/PossibleFragmentSpreads.mjs +4 -4
  299. package/validation/rules/PossibleTypeExtensions.js +158 -0
  300. package/validation/rules/PossibleTypeExtensions.js.flow +160 -0
  301. package/validation/rules/PossibleTypeExtensions.mjs +146 -0
  302. package/validation/rules/ProvidedRequiredArguments.js +3 -3
  303. package/validation/rules/ProvidedRequiredArguments.js.flow +4 -4
  304. package/validation/rules/ProvidedRequiredArguments.mjs +5 -5
  305. package/validation/rules/ScalarLeafs.js +4 -4
  306. package/validation/rules/ScalarLeafs.js.flow +3 -3
  307. package/validation/rules/ScalarLeafs.mjs +4 -4
  308. package/validation/rules/SingleFieldSubscriptions.js +2 -2
  309. package/validation/rules/SingleFieldSubscriptions.js.flow +1 -1
  310. package/validation/rules/SingleFieldSubscriptions.mjs +2 -2
  311. package/validation/rules/UniqueArgumentNames.js +2 -2
  312. package/validation/rules/UniqueArgumentNames.js.flow +1 -1
  313. package/validation/rules/UniqueArgumentNames.mjs +2 -2
  314. package/validation/rules/UniqueDirectiveNames.js +55 -0
  315. package/validation/rules/UniqueDirectiveNames.js.flow +64 -0
  316. package/validation/rules/UniqueDirectiveNames.mjs +43 -0
  317. package/validation/rules/UniqueDirectivesPerLocation.js +2 -2
  318. package/validation/rules/UniqueDirectivesPerLocation.js.flow +1 -1
  319. package/validation/rules/UniqueDirectivesPerLocation.mjs +2 -2
  320. package/validation/rules/UniqueEnumValueNames.js +90 -0
  321. package/validation/rules/UniqueEnumValueNames.js.flow +85 -0
  322. package/validation/rules/UniqueEnumValueNames.mjs +77 -0
  323. package/validation/rules/UniqueFieldDefinitionNames.js +101 -0
  324. package/validation/rules/UniqueFieldDefinitionNames.js.flow +99 -0
  325. package/validation/rules/UniqueFieldDefinitionNames.mjs +88 -0
  326. package/validation/rules/UniqueFragmentNames.js +2 -2
  327. package/validation/rules/UniqueFragmentNames.js.flow +1 -1
  328. package/validation/rules/UniqueFragmentNames.mjs +2 -2
  329. package/validation/rules/UniqueInputFieldNames.js +2 -4
  330. package/validation/rules/UniqueInputFieldNames.js.flow +1 -2
  331. package/validation/rules/UniqueInputFieldNames.mjs +2 -4
  332. package/validation/rules/UniqueOperationNames.js +2 -2
  333. package/validation/rules/UniqueOperationNames.js.flow +1 -1
  334. package/validation/rules/UniqueOperationNames.mjs +2 -2
  335. package/validation/rules/UniqueOperationTypes.js +85 -0
  336. package/validation/rules/UniqueOperationTypes.js.flow +76 -0
  337. package/validation/rules/UniqueOperationTypes.mjs +73 -0
  338. package/validation/rules/UniqueTypeNames.js +62 -0
  339. package/validation/rules/UniqueTypeNames.js.flow +67 -0
  340. package/validation/rules/UniqueTypeNames.mjs +50 -0
  341. package/validation/rules/UniqueVariableNames.js +2 -2
  342. package/validation/rules/UniqueVariableNames.js.flow +1 -1
  343. package/validation/rules/UniqueVariableNames.mjs +2 -2
  344. package/validation/rules/ValuesOfCorrectType.js +30 -14
  345. package/validation/rules/ValuesOfCorrectType.js.flow +5 -6
  346. package/validation/rules/ValuesOfCorrectType.mjs +29 -14
  347. package/validation/rules/VariablesAreInputTypes.js +3 -3
  348. package/validation/rules/VariablesAreInputTypes.js.flow +2 -2
  349. package/validation/rules/VariablesAreInputTypes.mjs +3 -3
  350. package/validation/rules/VariablesInAllowedPosition.js +5 -5
  351. package/validation/rules/VariablesInAllowedPosition.js.flow +1 -1
  352. package/validation/rules/VariablesInAllowedPosition.mjs +5 -5
  353. package/validation/specifiedRules.js +15 -3
  354. package/validation/specifiedRules.js.flow +14 -1
  355. package/validation/specifiedRules.mjs +9 -3
  356. package/validation/validate.js +2 -2
  357. package/validation/validate.js.flow +1 -1
  358. package/validation/validate.mjs +2 -2
  359. package/jsutils/find.js +0 -22
  360. package/jsutils/find.js.flow +0 -19
  361. package/jsutils/find.mjs +0 -15
@@ -5,20 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.extendSchema = extendSchema;
7
7
 
8
+ var _flatMap = _interopRequireDefault(require("../polyfills/flatMap"));
9
+
10
+ var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
11
+
12
+ var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
13
+
8
14
  var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
9
15
 
10
- var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
16
+ var _mapValue = _interopRequireDefault(require("../jsutils/mapValue"));
11
17
 
12
18
  var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap"));
13
19
 
14
- var _objectValues = _interopRequireDefault(require("../jsutils/objectValues"));
15
-
16
20
  var _buildASTSchema = require("./buildASTSchema");
17
21
 
18
22
  var _validate = require("../validation/validate");
19
23
 
20
- var _GraphQLError = require("../error/GraphQLError");
21
-
22
24
  var _schema = require("../type/schema");
23
25
 
24
26
  var _introspection = require("../type/introspection");
@@ -58,7 +60,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
58
60
  *
59
61
  */
60
62
  function extendSchema(schema, documentAST, options) {
61
- !(0, _schema.isSchema)(schema) ? (0, _invariant.default)(0, 'Must provide valid GraphQLSchema') : void 0;
63
+ (0, _schema.assertSchema)(schema);
62
64
  !(documentAST && documentAST.kind === _kinds.Kind.DOCUMENT) ? (0, _invariant.default)(0, 'Must provide valid Document AST') : void 0;
63
65
 
64
66
  if (!options || !(options.assumeValid || options.assumeValidSDL)) {
@@ -66,729 +68,353 @@ function extendSchema(schema, documentAST, options) {
66
68
  } // Collect the type definitions and extensions found in the document.
67
69
 
68
70
 
69
- var typeDefinitionMap = Object.create(null);
70
- var typeExtensionsMap = Object.create(null); // New directives and types are separate because a directives and types can
71
+ var typeDefs = [];
72
+ var typeExtsMap = Object.create(null); // New directives and types are separate because a directives and types can
71
73
  // have the same name. For example, a type named "skip".
72
74
 
73
- var directiveDefinitions = [];
75
+ var directiveDefs = [];
74
76
  var schemaDef; // Schema extensions are collected which may add additional operation types.
75
77
 
76
- var schemaExtensions = [];
77
-
78
- for (var i = 0; i < documentAST.definitions.length; i++) {
79
- var def = documentAST.definitions[i];
80
-
81
- if (def.kind === _kinds.Kind.SCHEMA_DEFINITION) {
82
- schemaDef = def;
83
- } else if (def.kind === _kinds.Kind.SCHEMA_EXTENSION) {
84
- schemaExtensions.push(def);
85
- } else if ((0, _predicates.isTypeDefinitionNode)(def)) {
86
- // Sanity check that none of the defined types conflict with the
87
- // schema's existing types.
88
- var typeName = def.name.value;
89
-
90
- if (schema.getType(typeName)) {
91
- throw new _GraphQLError.GraphQLError("Type \"".concat(typeName, "\" already exists in the schema. It cannot also ") + 'be defined in this type definition.', [def]);
78
+ var schemaExts = [];
79
+ var _iteratorNormalCompletion = true;
80
+ var _didIteratorError = false;
81
+ var _iteratorError = undefined;
82
+
83
+ try {
84
+ for (var _iterator = documentAST.definitions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
85
+ var def = _step.value;
86
+
87
+ if (def.kind === _kinds.Kind.SCHEMA_DEFINITION) {
88
+ schemaDef = def;
89
+ } else if (def.kind === _kinds.Kind.SCHEMA_EXTENSION) {
90
+ schemaExts.push(def);
91
+ } else if ((0, _predicates.isTypeDefinitionNode)(def)) {
92
+ typeDefs.push(def);
93
+ } else if ((0, _predicates.isTypeExtensionNode)(def)) {
94
+ var extendedTypeName = def.name.value;
95
+ var existingTypeExts = typeExtsMap[extendedTypeName];
96
+ typeExtsMap[extendedTypeName] = existingTypeExts ? existingTypeExts.concat([def]) : [def];
97
+ } else if (def.kind === _kinds.Kind.DIRECTIVE_DEFINITION) {
98
+ directiveDefs.push(def);
92
99
  }
100
+ } // If this document contains no new types, extensions, or directives then
101
+ // return the same unmodified GraphQLSchema instance.
93
102
 
94
- typeDefinitionMap[typeName] = def;
95
- } else if ((0, _predicates.isTypeExtensionNode)(def)) {
96
- // Sanity check that this type extension exists within the
97
- // schema's existing types.
98
- var extendedTypeName = def.name.value;
99
- var existingType = schema.getType(extendedTypeName);
100
-
101
- if (!existingType) {
102
- throw new _GraphQLError.GraphQLError("Cannot extend type \"".concat(extendedTypeName, "\" because it does not ") + 'exist in the existing schema.', [def]);
103
+ } catch (err) {
104
+ _didIteratorError = true;
105
+ _iteratorError = err;
106
+ } finally {
107
+ try {
108
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
109
+ _iterator.return();
103
110
  }
104
-
105
- checkExtensionNode(existingType, def);
106
- var existingTypeExtensions = typeExtensionsMap[extendedTypeName];
107
- typeExtensionsMap[extendedTypeName] = existingTypeExtensions ? existingTypeExtensions.concat([def]) : [def];
108
- } else if (def.kind === _kinds.Kind.DIRECTIVE_DEFINITION) {
109
- var directiveName = def.name.value;
110
- var existingDirective = schema.getDirective(directiveName);
111
-
112
- if (existingDirective) {
113
- throw new _GraphQLError.GraphQLError("Directive \"".concat(directiveName, "\" already exists in the schema. It ") + 'cannot be redefined.', [def]);
111
+ } finally {
112
+ if (_didIteratorError) {
113
+ throw _iteratorError;
114
114
  }
115
-
116
- directiveDefinitions.push(def);
117
115
  }
118
- } // If this document contains no new types, extensions, or directives then
119
- // return the same unmodified GraphQLSchema instance.
120
-
116
+ }
121
117
 
122
- if (Object.keys(typeExtensionsMap).length === 0 && Object.keys(typeDefinitionMap).length === 0 && directiveDefinitions.length === 0 && schemaExtensions.length === 0 && !schemaDef) {
118
+ if (Object.keys(typeExtsMap).length === 0 && typeDefs.length === 0 && directiveDefs.length === 0 && schemaExts.length === 0 && !schemaDef) {
123
119
  return schema;
124
120
  }
125
121
 
126
- var astBuilder = new _buildASTSchema.ASTDefinitionBuilder(typeDefinitionMap, options, function (typeRef) {
127
- var typeName = typeRef.name.value;
128
- var existingType = schema.getType(typeName);
129
-
130
- if (existingType) {
131
- return extendNamedType(existingType);
132
- }
133
-
134
- throw new _GraphQLError.GraphQLError("Unknown type: \"".concat(typeName, "\". Ensure that this type exists ") + 'either in the original schema, or is added in a type definition.', [typeRef]);
122
+ var schemaConfig = schema.toConfig();
123
+ var astBuilder = new _buildASTSchema.ASTDefinitionBuilder(options, function (typeName) {
124
+ var type = typeMap[typeName];
125
+ !type ? (0, _invariant.default)(0, "Unknown type: \"".concat(typeName, "\".")) : void 0;
126
+ return type;
127
+ });
128
+ var typeMap = (0, _keyValMap.default)(typeDefs, function (node) {
129
+ return node.name.value;
130
+ }, function (node) {
131
+ return astBuilder.buildType(node);
135
132
  });
136
- var extendTypeCache = Object.create(null); // Get the extended root operation types.
133
+ var _iteratorNormalCompletion2 = true;
134
+ var _didIteratorError2 = false;
135
+ var _iteratorError2 = undefined;
136
+
137
+ try {
138
+ for (var _iterator2 = schemaConfig.types[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
139
+ var existingType = _step2.value;
140
+ typeMap[existingType.name] = extendNamedType(existingType);
141
+ } // Get the extended root operation types.
142
+
143
+ } catch (err) {
144
+ _didIteratorError2 = true;
145
+ _iteratorError2 = err;
146
+ } finally {
147
+ try {
148
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
149
+ _iterator2.return();
150
+ }
151
+ } finally {
152
+ if (_didIteratorError2) {
153
+ throw _iteratorError2;
154
+ }
155
+ }
156
+ }
137
157
 
138
158
  var operationTypes = {
139
- query: extendMaybeNamedType(schema.getQueryType()),
140
- mutation: extendMaybeNamedType(schema.getMutationType()),
141
- subscription: extendMaybeNamedType(schema.getSubscriptionType())
159
+ query: schemaConfig.query && schemaConfig.query.name,
160
+ mutation: schemaConfig.mutation && schemaConfig.mutation.name,
161
+ subscription: schemaConfig.subscription && schemaConfig.subscription.name
142
162
  };
143
163
 
144
164
  if (schemaDef) {
145
- var _iteratorNormalCompletion = true;
146
- var _didIteratorError = false;
147
- var _iteratorError = undefined;
165
+ var _iteratorNormalCompletion3 = true;
166
+ var _didIteratorError3 = false;
167
+ var _iteratorError3 = undefined;
148
168
 
149
169
  try {
150
- for (var _iterator = schemaDef.operationTypes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
151
- var _ref2 = _step.value;
152
- var operation = _ref2.operation,
153
- type = _ref2.type;
154
-
155
- if (operationTypes[operation]) {
156
- throw new Error("Must provide only one ".concat(operation, " type in schema."));
157
- } // Note: While this could make early assertions to get the correctly
158
- // typed values, that would throw immediately while type system
159
- // validation with validateSchema() will produce more actionable results.
160
-
161
-
162
- operationTypes[operation] = astBuilder.buildType(type);
170
+ for (var _iterator3 = schemaDef.operationTypes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
171
+ var _ref2 = _step3.value;
172
+ var operation = _ref2.operation;
173
+ var type = _ref2.type;
174
+ operationTypes[operation] = type.name.value;
163
175
  }
164
176
  } catch (err) {
165
- _didIteratorError = true;
166
- _iteratorError = err;
177
+ _didIteratorError3 = true;
178
+ _iteratorError3 = err;
167
179
  } finally {
168
180
  try {
169
- if (!_iteratorNormalCompletion && _iterator.return != null) {
170
- _iterator.return();
181
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
182
+ _iterator3.return();
171
183
  }
172
184
  } finally {
173
- if (_didIteratorError) {
174
- throw _iteratorError;
185
+ if (_didIteratorError3) {
186
+ throw _iteratorError3;
175
187
  }
176
188
  }
177
189
  }
178
190
  } // Then, incorporate schema definition and all schema extensions.
179
191
 
180
192
 
181
- for (var _i = 0; _i < schemaExtensions.length; _i++) {
182
- var schemaExtension = schemaExtensions[_i];
193
+ var _arr = schemaExts;
183
194
 
184
- if (schemaExtension.operationTypes) {
185
- var _iteratorNormalCompletion12 = true;
186
- var _didIteratorError12 = false;
187
- var _iteratorError12 = undefined;
188
-
189
- try {
190
- for (var _iterator12 = schemaExtension.operationTypes[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
191
- var _ref4 = _step12.value;
192
- var operation = _ref4.operation,
193
- type = _ref4.type;
194
-
195
- if (operationTypes[operation]) {
196
- throw new Error("Must provide only one ".concat(operation, " type in schema."));
197
- } // Note: While this could make early assertions to get the correctly
198
- // typed values, that would throw immediately while type system
199
- // validation with validateSchema() will produce more actionable results.
195
+ for (var _i = 0; _i < _arr.length; _i++) {
196
+ var schemaExt = _arr[_i];
200
197
 
198
+ if (schemaExt.operationTypes) {
199
+ var _iteratorNormalCompletion4 = true;
200
+ var _didIteratorError4 = false;
201
+ var _iteratorError4 = undefined;
201
202
 
202
- operationTypes[operation] = astBuilder.buildType(type);
203
+ try {
204
+ for (var _iterator4 = schemaExt.operationTypes[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
205
+ var _ref4 = _step4.value;
206
+ var _operation = _ref4.operation;
207
+ var _type = _ref4.type;
208
+ operationTypes[_operation] = _type.name.value;
203
209
  }
204
210
  } catch (err) {
205
- _didIteratorError12 = true;
206
- _iteratorError12 = err;
211
+ _didIteratorError4 = true;
212
+ _iteratorError4 = err;
207
213
  } finally {
208
214
  try {
209
- if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
210
- _iterator12.return();
215
+ if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
216
+ _iterator4.return();
211
217
  }
212
218
  } finally {
213
- if (_didIteratorError12) {
214
- throw _iteratorError12;
219
+ if (_didIteratorError4) {
220
+ throw _iteratorError4;
215
221
  }
216
222
  }
217
223
  }
218
224
  }
219
- }
220
-
221
- var schemaExtensionASTNodes = schemaExtensions ? schema.extensionASTNodes ? schema.extensionASTNodes.concat(schemaExtensions) : schemaExtensions : schema.extensionASTNodes;
222
- var types = (0, _objectValues.default)(schema.getTypeMap()).map(function (type) {
223
- return extendNamedType(type);
224
- }).concat((0, _objectValues.default)(typeDefinitionMap).map(function (type) {
225
- return astBuilder.buildType(type);
226
- })); // Support both original legacy names and extended legacy names.
225
+ } // Support both original legacy names and extended legacy names.
227
226
 
228
- var allowedLegacyNames = schema.__allowedLegacyNames.concat(options && options.allowedLegacyNames || []); // Then produce and return a Schema with these types.
229
227
 
228
+ var allowedLegacyNames = schemaConfig.allowedLegacyNames.concat(options && options.allowedLegacyNames || []); // Then produce and return a Schema with these types.
230
229
 
231
- return new _schema.GraphQLSchema(_objectSpread({}, operationTypes, {
232
- types: types,
230
+ return new _schema.GraphQLSchema({
231
+ // Note: While this could make early assertions to get the correctly
232
+ // typed values, that would throw immediately while type system
233
+ // validation with validateSchema() will produce more actionable results.
234
+ query: getMaybeTypeByName(operationTypes.query),
235
+ mutation: getMaybeTypeByName(operationTypes.mutation),
236
+ subscription: getMaybeTypeByName(operationTypes.subscription),
237
+ types: (0, _objectValues.default)(typeMap),
233
238
  directives: getMergedDirectives(),
234
- astNode: schema.astNode,
235
- extensionASTNodes: schemaExtensionASTNodes,
239
+ astNode: schemaDef || schemaConfig.astNode,
240
+ extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExts),
236
241
  allowedLegacyNames: allowedLegacyNames
237
- })); // Below are functions used for producing this schema that have closed over
242
+ }); // Below are functions used for producing this schema that have closed over
238
243
  // this scope and have access to the schema, cache, and newly defined types.
239
244
 
245
+ function replaceType(type) {
246
+ if ((0, _definition.isListType)(type)) {
247
+ return new _definition.GraphQLList(replaceType(type.ofType));
248
+ } else if ((0, _definition.isNonNullType)(type)) {
249
+ return new _definition.GraphQLNonNull(replaceType(type.ofType));
250
+ }
251
+
252
+ return replaceNamedType(type);
253
+ }
254
+
255
+ function replaceNamedType(type) {
256
+ return typeMap[type.name];
257
+ }
258
+
259
+ function getMaybeTypeByName(typeName) {
260
+ return typeName ? typeMap[typeName] : null;
261
+ }
262
+
240
263
  function getMergedDirectives() {
241
264
  var existingDirectives = schema.getDirectives().map(extendDirective);
242
265
  !existingDirectives ? (0, _invariant.default)(0, 'schema must have default directives') : void 0;
243
- return existingDirectives.concat(directiveDefinitions.map(function (node) {
266
+ return existingDirectives.concat(directiveDefs.map(function (node) {
244
267
  return astBuilder.buildDirective(node);
245
268
  }));
246
269
  }
247
270
 
248
- function extendMaybeNamedType(type) {
249
- return type ? extendNamedType(type) : null;
250
- }
251
-
252
271
  function extendNamedType(type) {
253
272
  if ((0, _introspection.isIntrospectionType)(type) || (0, _scalars.isSpecifiedScalarType)(type)) {
254
273
  // Builtin types are not extended.
255
274
  return type;
256
- }
257
-
258
- var name = type.name;
259
-
260
- if (!extendTypeCache[name]) {
261
- if ((0, _definition.isScalarType)(type)) {
262
- extendTypeCache[name] = extendScalarType(type);
263
- } else if ((0, _definition.isObjectType)(type)) {
264
- extendTypeCache[name] = extendObjectType(type);
265
- } else if ((0, _definition.isInterfaceType)(type)) {
266
- extendTypeCache[name] = extendInterfaceType(type);
267
- } else if ((0, _definition.isUnionType)(type)) {
268
- extendTypeCache[name] = extendUnionType(type);
269
- } else if ((0, _definition.isEnumType)(type)) {
270
- extendTypeCache[name] = extendEnumType(type);
271
- } else if ((0, _definition.isInputObjectType)(type)) {
272
- extendTypeCache[name] = extendInputObjectType(type);
273
- }
274
- }
275
-
276
- return extendTypeCache[name];
275
+ } else if ((0, _definition.isScalarType)(type)) {
276
+ return extendScalarType(type);
277
+ } else if ((0, _definition.isObjectType)(type)) {
278
+ return extendObjectType(type);
279
+ } else if ((0, _definition.isInterfaceType)(type)) {
280
+ return extendInterfaceType(type);
281
+ } else if ((0, _definition.isUnionType)(type)) {
282
+ return extendUnionType(type);
283
+ } else if ((0, _definition.isEnumType)(type)) {
284
+ return extendEnumType(type);
285
+ } else if ((0, _definition.isInputObjectType)(type)) {
286
+ return extendInputObjectType(type);
287
+ } // Not reachable. All possible types have been considered.
288
+
289
+ /* istanbul ignore next */
290
+
291
+
292
+ throw new Error("Unexpected type: \"".concat((0, _inspect.default)(type), "\"."));
277
293
  }
278
294
 
279
295
  function extendDirective(directive) {
280
- return new _directives.GraphQLDirective({
281
- name: directive.name,
282
- description: directive.description,
283
- locations: directive.locations,
284
- args: extendArgs(directive.args),
285
- astNode: directive.astNode
286
- });
296
+ var config = directive.toConfig();
297
+ return new _directives.GraphQLDirective(_objectSpread({}, config, {
298
+ args: (0, _mapValue.default)(config.args, extendArg)
299
+ }));
287
300
  }
288
301
 
289
302
  function extendInputObjectType(type) {
290
- var name = type.name;
291
- var extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : typeExtensionsMap[name] : type.extensionASTNodes;
292
- return new _definition.GraphQLInputObjectType({
293
- name: name,
294
- description: type.description,
303
+ var config = type.toConfig();
304
+ var extensions = typeExtsMap[config.name] || [];
305
+ var fieldNodes = (0, _flatMap.default)(extensions, function (node) {
306
+ return node.fields || [];
307
+ });
308
+ return new _definition.GraphQLInputObjectType(_objectSpread({}, config, {
295
309
  fields: function fields() {
296
- return extendInputFieldMap(type);
310
+ return _objectSpread({}, (0, _mapValue.default)(config.fields, function (field) {
311
+ return _objectSpread({}, field, {
312
+ type: replaceType(field.type)
313
+ });
314
+ }), (0, _keyValMap.default)(fieldNodes, function (field) {
315
+ return field.name.value;
316
+ }, function (field) {
317
+ return astBuilder.buildInputField(field);
318
+ }));
297
319
  },
298
- astNode: type.astNode,
299
- extensionASTNodes: extensionASTNodes
300
- });
301
- }
302
-
303
- function extendInputFieldMap(type) {
304
- var newFieldMap = Object.create(null);
305
- var oldFieldMap = type.getFields();
306
-
307
- var _arr = Object.keys(oldFieldMap);
308
-
309
- for (var _i2 = 0; _i2 < _arr.length; _i2++) {
310
- var _fieldName = _arr[_i2];
311
- var _field = oldFieldMap[_fieldName];
312
- newFieldMap[_fieldName] = {
313
- description: _field.description,
314
- type: extendType(_field.type),
315
- defaultValue: _field.defaultValue,
316
- astNode: _field.astNode
317
- };
318
- } // If there are any extensions to the fields, apply those here.
319
-
320
-
321
- var extensions = typeExtensionsMap[type.name];
322
-
323
- if (extensions) {
324
- var _iteratorNormalCompletion2 = true;
325
- var _didIteratorError2 = false;
326
- var _iteratorError2 = undefined;
327
-
328
- try {
329
- for (var _iterator2 = extensions[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
330
- var extension = _step2.value;
331
- var _iteratorNormalCompletion3 = true;
332
- var _didIteratorError3 = false;
333
- var _iteratorError3 = undefined;
334
-
335
- try {
336
- for (var _iterator3 = extension.fields[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
337
- var field = _step3.value;
338
- var fieldName = field.name.value;
339
-
340
- if (oldFieldMap[fieldName]) {
341
- throw new _GraphQLError.GraphQLError("Field \"".concat(type.name, ".").concat(fieldName, "\" already exists in the ") + 'schema. It cannot also be defined in this type extension.', [field]);
342
- }
343
-
344
- newFieldMap[fieldName] = astBuilder.buildInputField(field);
345
- }
346
- } catch (err) {
347
- _didIteratorError3 = true;
348
- _iteratorError3 = err;
349
- } finally {
350
- try {
351
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
352
- _iterator3.return();
353
- }
354
- } finally {
355
- if (_didIteratorError3) {
356
- throw _iteratorError3;
357
- }
358
- }
359
- }
360
- }
361
- } catch (err) {
362
- _didIteratorError2 = true;
363
- _iteratorError2 = err;
364
- } finally {
365
- try {
366
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
367
- _iterator2.return();
368
- }
369
- } finally {
370
- if (_didIteratorError2) {
371
- throw _iteratorError2;
372
- }
373
- }
374
- }
375
- }
376
-
377
- return newFieldMap;
320
+ extensionASTNodes: config.extensionASTNodes.concat(extensions)
321
+ }));
378
322
  }
379
323
 
380
324
  function extendEnumType(type) {
381
- var name = type.name;
382
- var extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : typeExtensionsMap[name] : type.extensionASTNodes;
383
- return new _definition.GraphQLEnumType({
384
- name: name,
385
- description: type.description,
386
- values: extendValueMap(type),
387
- astNode: type.astNode,
388
- extensionASTNodes: extensionASTNodes
325
+ var config = type.toConfig();
326
+ var extensions = typeExtsMap[type.name] || [];
327
+ var valueNodes = (0, _flatMap.default)(extensions, function (node) {
328
+ return node.values || [];
389
329
  });
390
- }
391
-
392
- function extendValueMap(type) {
393
- var newValueMap = Object.create(null);
394
- var oldValueMap = (0, _keyMap.default)(type.getValues(), function (value) {
395
- return value.name;
396
- });
397
-
398
- var _arr2 = Object.keys(oldValueMap);
399
-
400
- for (var _i3 = 0; _i3 < _arr2.length; _i3++) {
401
- var _valueName = _arr2[_i3];
402
- var _value = oldValueMap[_valueName];
403
- newValueMap[_valueName] = {
404
- name: _value.name,
405
- description: _value.description,
406
- value: _value.value,
407
- deprecationReason: _value.deprecationReason,
408
- astNode: _value.astNode
409
- };
410
- } // If there are any extensions to the values, apply those here.
411
-
412
-
413
- var extensions = typeExtensionsMap[type.name];
414
-
415
- if (extensions) {
416
- var _iteratorNormalCompletion4 = true;
417
- var _didIteratorError4 = false;
418
- var _iteratorError4 = undefined;
419
-
420
- try {
421
- for (var _iterator4 = extensions[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
422
- var extension = _step4.value;
423
- var _iteratorNormalCompletion5 = true;
424
- var _didIteratorError5 = false;
425
- var _iteratorError5 = undefined;
426
-
427
- try {
428
- for (var _iterator5 = extension.values[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
429
- var value = _step5.value;
430
- var valueName = value.name.value;
431
-
432
- if (oldValueMap[valueName]) {
433
- throw new _GraphQLError.GraphQLError("Enum value \"".concat(type.name, ".").concat(valueName, "\" already exists in the ") + 'schema. It cannot also be defined in this type extension.', [value]);
434
- }
435
-
436
- newValueMap[valueName] = astBuilder.buildEnumValue(value);
437
- }
438
- } catch (err) {
439
- _didIteratorError5 = true;
440
- _iteratorError5 = err;
441
- } finally {
442
- try {
443
- if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
444
- _iterator5.return();
445
- }
446
- } finally {
447
- if (_didIteratorError5) {
448
- throw _iteratorError5;
449
- }
450
- }
451
- }
452
- }
453
- } catch (err) {
454
- _didIteratorError4 = true;
455
- _iteratorError4 = err;
456
- } finally {
457
- try {
458
- if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
459
- _iterator4.return();
460
- }
461
- } finally {
462
- if (_didIteratorError4) {
463
- throw _iteratorError4;
464
- }
465
- }
466
- }
467
- }
468
-
469
- return newValueMap;
330
+ return new _definition.GraphQLEnumType(_objectSpread({}, config, {
331
+ values: _objectSpread({}, config.values, (0, _keyValMap.default)(valueNodes, function (value) {
332
+ return value.name.value;
333
+ }, function (value) {
334
+ return astBuilder.buildEnumValue(value);
335
+ })),
336
+ extensionASTNodes: config.extensionASTNodes.concat(extensions)
337
+ }));
470
338
  }
471
339
 
472
340
  function extendScalarType(type) {
473
- var name = type.name;
474
- var extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : typeExtensionsMap[name] : type.extensionASTNodes;
475
- return new _definition.GraphQLScalarType({
476
- name: name,
477
- description: type.description,
478
- astNode: type.astNode,
479
- extensionASTNodes: extensionASTNodes,
480
- serialize: type.serialize,
481
- parseValue: type.parseValue,
482
- parseLiteral: type.parseLiteral
483
- });
341
+ var config = type.toConfig();
342
+ var extensions = typeExtsMap[config.name] || [];
343
+ return new _definition.GraphQLScalarType(_objectSpread({}, config, {
344
+ extensionASTNodes: config.extensionASTNodes.concat(extensions)
345
+ }));
484
346
  }
485
347
 
486
348
  function extendObjectType(type) {
487
- var name = type.name;
488
- var extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : typeExtensionsMap[name] : type.extensionASTNodes;
489
- return new _definition.GraphQLObjectType({
490
- name: name,
491
- description: type.description,
349
+ var config = type.toConfig();
350
+ var extensions = typeExtsMap[config.name] || [];
351
+ var interfaceNodes = (0, _flatMap.default)(extensions, function (node) {
352
+ return node.interfaces || [];
353
+ });
354
+ var fieldNodes = (0, _flatMap.default)(extensions, function (node) {
355
+ return node.fields || [];
356
+ });
357
+ return new _definition.GraphQLObjectType(_objectSpread({}, config, {
492
358
  interfaces: function interfaces() {
493
- return extendImplementedInterfaces(type);
359
+ return [].concat(type.getInterfaces().map(replaceNamedType), interfaceNodes.map(function (node) {
360
+ return astBuilder.getNamedType(node);
361
+ }));
494
362
  },
495
363
  fields: function fields() {
496
- return extendFieldMap(type);
364
+ return _objectSpread({}, (0, _mapValue.default)(config.fields, extendField), (0, _keyValMap.default)(fieldNodes, function (node) {
365
+ return node.name.value;
366
+ }, function (node) {
367
+ return astBuilder.buildField(node);
368
+ }));
497
369
  },
498
- astNode: type.astNode,
499
- extensionASTNodes: extensionASTNodes,
500
- isTypeOf: type.isTypeOf
501
- });
502
- }
503
-
504
- function extendArgs(args) {
505
- return (0, _keyValMap.default)(args, function (arg) {
506
- return arg.name;
507
- }, function (arg) {
508
- return {
509
- type: extendType(arg.type),
510
- defaultValue: arg.defaultValue,
511
- description: arg.description,
512
- astNode: arg.astNode
513
- };
514
- });
370
+ extensionASTNodes: config.extensionASTNodes.concat(extensions)
371
+ }));
515
372
  }
516
373
 
517
374
  function extendInterfaceType(type) {
518
- var name = type.name;
519
- var extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : typeExtensionsMap[name] : type.extensionASTNodes;
520
- return new _definition.GraphQLInterfaceType({
521
- name: type.name,
522
- description: type.description,
375
+ var config = type.toConfig();
376
+ var extensions = typeExtsMap[config.name] || [];
377
+ var fieldNodes = (0, _flatMap.default)(extensions, function (node) {
378
+ return node.fields || [];
379
+ });
380
+ return new _definition.GraphQLInterfaceType(_objectSpread({}, config, {
523
381
  fields: function fields() {
524
- return extendFieldMap(type);
382
+ return _objectSpread({}, (0, _mapValue.default)(config.fields, extendField), (0, _keyValMap.default)(fieldNodes, function (node) {
383
+ return node.name.value;
384
+ }, function (node) {
385
+ return astBuilder.buildField(node);
386
+ }));
525
387
  },
526
- astNode: type.astNode,
527
- extensionASTNodes: extensionASTNodes,
528
- resolveType: type.resolveType
529
- });
388
+ extensionASTNodes: config.extensionASTNodes.concat(extensions)
389
+ }));
530
390
  }
531
391
 
532
392
  function extendUnionType(type) {
533
- var name = type.name;
534
- var extensionASTNodes = typeExtensionsMap[name] ? type.extensionASTNodes ? type.extensionASTNodes.concat(typeExtensionsMap[name]) : typeExtensionsMap[name] : type.extensionASTNodes;
535
- return new _definition.GraphQLUnionType({
536
- name: name,
537
- description: type.description,
393
+ var config = type.toConfig();
394
+ var extensions = typeExtsMap[config.name] || [];
395
+ var typeNodes = (0, _flatMap.default)(extensions, function (node) {
396
+ return node.types || [];
397
+ });
398
+ return new _definition.GraphQLUnionType(_objectSpread({}, config, {
538
399
  types: function types() {
539
- return extendPossibleTypes(type);
400
+ return [].concat(type.getTypes().map(replaceNamedType), typeNodes.map(function (node) {
401
+ return astBuilder.getNamedType(node);
402
+ }));
540
403
  },
541
- astNode: type.astNode,
542
- resolveType: type.resolveType,
543
- extensionASTNodes: extensionASTNodes
544
- });
545
- }
546
-
547
- function extendPossibleTypes(type) {
548
- var possibleTypes = type.getTypes().map(extendNamedType); // If there are any extensions to the union, apply those here.
549
-
550
- var extensions = typeExtensionsMap[type.name];
551
-
552
- if (extensions) {
553
- var _iteratorNormalCompletion6 = true;
554
- var _didIteratorError6 = false;
555
- var _iteratorError6 = undefined;
556
-
557
- try {
558
- for (var _iterator6 = extensions[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
559
- var extension = _step6.value;
560
- var _iteratorNormalCompletion7 = true;
561
- var _didIteratorError7 = false;
562
- var _iteratorError7 = undefined;
563
-
564
- try {
565
- for (var _iterator7 = extension.types[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
566
- var namedType = _step7.value;
567
- // Note: While this could make early assertions to get the correctly
568
- // typed values, that would throw immediately while type system
569
- // validation with validateSchema() will produce more actionable results.
570
- possibleTypes.push(astBuilder.buildType(namedType));
571
- }
572
- } catch (err) {
573
- _didIteratorError7 = true;
574
- _iteratorError7 = err;
575
- } finally {
576
- try {
577
- if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
578
- _iterator7.return();
579
- }
580
- } finally {
581
- if (_didIteratorError7) {
582
- throw _iteratorError7;
583
- }
584
- }
585
- }
586
- }
587
- } catch (err) {
588
- _didIteratorError6 = true;
589
- _iteratorError6 = err;
590
- } finally {
591
- try {
592
- if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
593
- _iterator6.return();
594
- }
595
- } finally {
596
- if (_didIteratorError6) {
597
- throw _iteratorError6;
598
- }
599
- }
600
- }
601
- }
602
-
603
- return possibleTypes;
604
- }
605
-
606
- function extendImplementedInterfaces(type) {
607
- var interfaces = type.getInterfaces().map(extendNamedType); // If there are any extensions to the interfaces, apply those here.
608
-
609
- var extensions = typeExtensionsMap[type.name];
610
-
611
- if (extensions) {
612
- var _iteratorNormalCompletion8 = true;
613
- var _didIteratorError8 = false;
614
- var _iteratorError8 = undefined;
615
-
616
- try {
617
- for (var _iterator8 = extensions[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
618
- var extension = _step8.value;
619
- var _iteratorNormalCompletion9 = true;
620
- var _didIteratorError9 = false;
621
- var _iteratorError9 = undefined;
622
-
623
- try {
624
- for (var _iterator9 = extension.interfaces[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
625
- var namedType = _step9.value;
626
- // Note: While this could make early assertions to get the correctly
627
- // typed values, that would throw immediately while type system
628
- // validation with validateSchema() will produce more actionable results.
629
- interfaces.push(astBuilder.buildType(namedType));
630
- }
631
- } catch (err) {
632
- _didIteratorError9 = true;
633
- _iteratorError9 = err;
634
- } finally {
635
- try {
636
- if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
637
- _iterator9.return();
638
- }
639
- } finally {
640
- if (_didIteratorError9) {
641
- throw _iteratorError9;
642
- }
643
- }
644
- }
645
- }
646
- } catch (err) {
647
- _didIteratorError8 = true;
648
- _iteratorError8 = err;
649
- } finally {
650
- try {
651
- if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
652
- _iterator8.return();
653
- }
654
- } finally {
655
- if (_didIteratorError8) {
656
- throw _iteratorError8;
657
- }
658
- }
659
- }
660
- }
661
-
662
- return interfaces;
663
- }
664
-
665
- function extendFieldMap(type) {
666
- var newFieldMap = Object.create(null);
667
- var oldFieldMap = type.getFields();
668
-
669
- var _arr3 = Object.keys(oldFieldMap);
670
-
671
- for (var _i4 = 0; _i4 < _arr3.length; _i4++) {
672
- var _fieldName2 = _arr3[_i4];
673
- var _field2 = oldFieldMap[_fieldName2];
674
- newFieldMap[_fieldName2] = {
675
- description: _field2.description,
676
- deprecationReason: _field2.deprecationReason,
677
- type: extendType(_field2.type),
678
- args: extendArgs(_field2.args),
679
- astNode: _field2.astNode,
680
- resolve: _field2.resolve
681
- };
682
- } // If there are any extensions to the fields, apply those here.
683
-
684
-
685
- var extensions = typeExtensionsMap[type.name];
686
-
687
- if (extensions) {
688
- var _iteratorNormalCompletion10 = true;
689
- var _didIteratorError10 = false;
690
- var _iteratorError10 = undefined;
691
-
692
- try {
693
- for (var _iterator10 = extensions[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
694
- var extension = _step10.value;
695
- var _iteratorNormalCompletion11 = true;
696
- var _didIteratorError11 = false;
697
- var _iteratorError11 = undefined;
698
-
699
- try {
700
- for (var _iterator11 = extension.fields[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
701
- var field = _step11.value;
702
- var fieldName = field.name.value;
703
-
704
- if (oldFieldMap[fieldName]) {
705
- throw new _GraphQLError.GraphQLError("Field \"".concat(type.name, ".").concat(fieldName, "\" already exists in the ") + 'schema. It cannot also be defined in this type extension.', [field]);
706
- }
707
-
708
- newFieldMap[fieldName] = astBuilder.buildField(field);
709
- }
710
- } catch (err) {
711
- _didIteratorError11 = true;
712
- _iteratorError11 = err;
713
- } finally {
714
- try {
715
- if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
716
- _iterator11.return();
717
- }
718
- } finally {
719
- if (_didIteratorError11) {
720
- throw _iteratorError11;
721
- }
722
- }
723
- }
724
- }
725
- } catch (err) {
726
- _didIteratorError10 = true;
727
- _iteratorError10 = err;
728
- } finally {
729
- try {
730
- if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
731
- _iterator10.return();
732
- }
733
- } finally {
734
- if (_didIteratorError10) {
735
- throw _iteratorError10;
736
- }
737
- }
738
- }
739
- }
740
-
741
- return newFieldMap;
404
+ extensionASTNodes: config.extensionASTNodes.concat(extensions)
405
+ }));
742
406
  }
743
407
 
744
- function extendType(typeDef) {
745
- if ((0, _definition.isListType)(typeDef)) {
746
- return (0, _definition.GraphQLList)(extendType(typeDef.ofType));
747
- }
748
-
749
- if ((0, _definition.isNonNullType)(typeDef)) {
750
- return (0, _definition.GraphQLNonNull)(extendType(typeDef.ofType));
751
- }
752
-
753
- return extendNamedType(typeDef);
408
+ function extendField(field) {
409
+ return _objectSpread({}, field, {
410
+ type: replaceType(field.type),
411
+ args: (0, _mapValue.default)(field.args, extendArg)
412
+ });
754
413
  }
755
- }
756
-
757
- function checkExtensionNode(type, node) {
758
- switch (node.kind) {
759
- case _kinds.Kind.OBJECT_TYPE_EXTENSION:
760
- if (!(0, _definition.isObjectType)(type)) {
761
- throw new _GraphQLError.GraphQLError("Cannot extend non-object type \"".concat(type.name, "\"."), [node]);
762
- }
763
414
 
764
- break;
765
-
766
- case _kinds.Kind.INTERFACE_TYPE_EXTENSION:
767
- if (!(0, _definition.isInterfaceType)(type)) {
768
- throw new _GraphQLError.GraphQLError("Cannot extend non-interface type \"".concat(type.name, "\"."), [node]);
769
- }
770
-
771
- break;
772
-
773
- case _kinds.Kind.ENUM_TYPE_EXTENSION:
774
- if (!(0, _definition.isEnumType)(type)) {
775
- throw new _GraphQLError.GraphQLError("Cannot extend non-enum type \"".concat(type.name, "\"."), [node]);
776
- }
777
-
778
- break;
779
-
780
- case _kinds.Kind.UNION_TYPE_EXTENSION:
781
- if (!(0, _definition.isUnionType)(type)) {
782
- throw new _GraphQLError.GraphQLError("Cannot extend non-union type \"".concat(type.name, "\"."), [node]);
783
- }
784
-
785
- break;
786
-
787
- case _kinds.Kind.INPUT_OBJECT_TYPE_EXTENSION:
788
- if (!(0, _definition.isInputObjectType)(type)) {
789
- throw new _GraphQLError.GraphQLError("Cannot extend non-input object type \"".concat(type.name, "\"."), [node]);
790
- }
791
-
792
- break;
415
+ function extendArg(arg) {
416
+ return _objectSpread({}, arg, {
417
+ type: replaceType(arg.type)
418
+ });
793
419
  }
794
420
  }