graphql 14.1.1 → 14.3.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 (377) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/error/GraphQLError.js +12 -10
  4. package/error/GraphQLError.js.flow +11 -6
  5. package/error/GraphQLError.mjs +20 -3
  6. package/error/formatError.js +2 -2
  7. package/error/formatError.js.flow +3 -3
  8. package/error/formatError.mjs +2 -2
  9. package/error/index.js +1 -1
  10. package/error/index.js.flow +5 -2
  11. package/error/index.mjs +2 -2
  12. package/error/locatedError.js +2 -2
  13. package/error/locatedError.js.flow +2 -2
  14. package/error/locatedError.mjs +2 -2
  15. package/error/printError.js +2 -2
  16. package/error/printError.js.flow +4 -5
  17. package/error/printError.mjs +2 -2
  18. package/error/syntaxError.js +2 -2
  19. package/error/syntaxError.js.flow +2 -2
  20. package/error/syntaxError.mjs +2 -2
  21. package/execution/execute.js +52 -37
  22. package/execution/execute.js.flow +66 -51
  23. package/execution/execute.mjs +50 -38
  24. package/execution/index.js +7 -1
  25. package/execution/index.js.flow +9 -4
  26. package/execution/index.mjs +3 -3
  27. package/execution/values.js +11 -11
  28. package/execution/values.js.flow +23 -19
  29. package/execution/values.mjs +11 -11
  30. package/graphql.js +13 -9
  31. package/graphql.js.flow +28 -10
  32. package/graphql.mjs +10 -9
  33. package/index.js +83 -53
  34. package/index.js.flow +60 -47
  35. package/index.mjs +26 -23
  36. package/jsutils/ObjMap.js +1 -1
  37. package/jsutils/ObjMap.js.flow +1 -1
  38. package/jsutils/ObjMap.mjs +1 -0
  39. package/jsutils/PromiseOrValue.js +1 -0
  40. package/jsutils/{MaybePromise.js.flow → PromiseOrValue.js.flow} +2 -2
  41. package/jsutils/PromiseOrValue.mjs +1 -0
  42. package/jsutils/dedent.js +2 -2
  43. package/jsutils/dedent.js.flow +1 -1
  44. package/jsutils/dedent.mjs +2 -2
  45. package/jsutils/defineToJSON.js +2 -2
  46. package/jsutils/defineToJSON.js.flow +1 -1
  47. package/jsutils/defineToJSON.mjs +2 -2
  48. package/jsutils/defineToStringTag.js +2 -2
  49. package/jsutils/defineToStringTag.js.flow +1 -1
  50. package/jsutils/defineToStringTag.mjs +2 -2
  51. package/jsutils/inspect.js +94 -19
  52. package/jsutils/inspect.js.flow +98 -20
  53. package/jsutils/inspect.mjs +94 -20
  54. package/jsutils/instanceOf.js +2 -2
  55. package/jsutils/instanceOf.js.flow +1 -1
  56. package/jsutils/instanceOf.mjs +2 -2
  57. package/jsutils/invariant.js +5 -3
  58. package/jsutils/invariant.js.flow +3 -2
  59. package/jsutils/invariant.mjs +5 -3
  60. package/jsutils/isInvalid.js +2 -2
  61. package/jsutils/isInvalid.js.flow +1 -1
  62. package/jsutils/isInvalid.mjs +2 -2
  63. package/jsutils/isNullish.js +2 -2
  64. package/jsutils/isNullish.js.flow +1 -1
  65. package/jsutils/isNullish.mjs +2 -2
  66. package/jsutils/isPromise.js +2 -2
  67. package/jsutils/isPromise.js.flow +1 -1
  68. package/jsutils/isPromise.mjs +2 -2
  69. package/jsutils/keyMap.js +4 -3
  70. package/jsutils/keyMap.js.flow +6 -6
  71. package/jsutils/keyMap.mjs +4 -3
  72. package/jsutils/keyValMap.js +4 -3
  73. package/jsutils/keyValMap.js.flow +6 -6
  74. package/jsutils/keyValMap.mjs +4 -3
  75. package/jsutils/mapValue.js +2 -2
  76. package/jsutils/mapValue.js.flow +2 -2
  77. package/jsutils/mapValue.mjs +2 -2
  78. package/jsutils/memoize3.js +3 -3
  79. package/jsutils/memoize3.js.flow +2 -2
  80. package/jsutils/memoize3.mjs +3 -3
  81. package/jsutils/nodejsCustomInspectSymbol.js +2 -2
  82. package/jsutils/nodejsCustomInspectSymbol.js.flow +1 -1
  83. package/jsutils/nodejsCustomInspectSymbol.mjs +2 -2
  84. package/jsutils/orList.js +2 -2
  85. package/jsutils/orList.js.flow +1 -1
  86. package/jsutils/orList.mjs +2 -2
  87. package/jsutils/promiseForObject.js +2 -2
  88. package/jsutils/promiseForObject.js.flow +2 -2
  89. package/jsutils/promiseForObject.mjs +2 -2
  90. package/jsutils/promiseReduce.js +2 -2
  91. package/jsutils/promiseReduce.js.flow +5 -5
  92. package/jsutils/promiseReduce.mjs +2 -2
  93. package/jsutils/quotedOrList.js +2 -2
  94. package/jsutils/quotedOrList.js.flow +1 -1
  95. package/jsutils/quotedOrList.mjs +2 -2
  96. package/jsutils/suggestionList.js +2 -2
  97. package/jsutils/suggestionList.js.flow +1 -1
  98. package/jsutils/suggestionList.mjs +2 -2
  99. package/language/ast.js +1 -1
  100. package/language/ast.js.flow +3 -3
  101. package/language/ast.mjs +1 -0
  102. package/language/blockString.js +114 -0
  103. package/language/blockString.js.flow +102 -0
  104. package/language/blockString.mjs +104 -0
  105. package/language/directiveLocation.js +2 -2
  106. package/language/directiveLocation.js.flow +1 -1
  107. package/language/directiveLocation.mjs +2 -2
  108. package/language/index.js +9 -9
  109. package/language/index.js.flow +10 -5
  110. package/language/index.mjs +3 -3
  111. package/language/kinds.js +2 -2
  112. package/language/kinds.js.flow +1 -1
  113. package/language/kinds.mjs +2 -2
  114. package/language/lexer.js +52 -44
  115. package/language/lexer.js.flow +65 -54
  116. package/language/lexer.mjs +49 -43
  117. package/language/location.js +2 -2
  118. package/language/location.js.flow +2 -2
  119. package/language/location.mjs +2 -2
  120. package/language/parser.js +75 -67
  121. package/language/parser.js.flow +138 -127
  122. package/language/parser.mjs +76 -68
  123. package/language/predicates.js +2 -2
  124. package/language/predicates.js.flow +2 -2
  125. package/language/predicates.mjs +2 -2
  126. package/language/printer.js +6 -14
  127. package/language/printer.js.flow +8 -17
  128. package/language/printer.mjs +5 -14
  129. package/language/source.js +2 -2
  130. package/language/source.js.flow +1 -1
  131. package/language/source.mjs +2 -2
  132. package/language/visitor.js +4 -6
  133. package/language/visitor.js.flow +3 -3
  134. package/language/visitor.mjs +4 -6
  135. package/package.json +1 -1
  136. package/polyfills/find.js +2 -2
  137. package/polyfills/find.js.flow +1 -1
  138. package/polyfills/find.mjs +2 -2
  139. package/polyfills/flatMap.js +38 -0
  140. package/polyfills/flatMap.js.flow +34 -0
  141. package/polyfills/flatMap.mjs +30 -0
  142. package/polyfills/isFinite.js +2 -2
  143. package/polyfills/isFinite.js.flow +1 -1
  144. package/polyfills/isFinite.mjs +2 -2
  145. package/polyfills/isInteger.js +2 -2
  146. package/polyfills/isInteger.js.flow +1 -1
  147. package/polyfills/isInteger.mjs +2 -2
  148. package/polyfills/objectEntries.js +2 -2
  149. package/polyfills/objectEntries.js.flow +2 -2
  150. package/polyfills/objectEntries.mjs +2 -2
  151. package/polyfills/objectValues.js +2 -2
  152. package/polyfills/objectValues.js.flow +2 -2
  153. package/polyfills/objectValues.mjs +2 -2
  154. package/subscription/asyncIteratorReject.js +1 -1
  155. package/subscription/asyncIteratorReject.js.flow +1 -1
  156. package/subscription/asyncIteratorReject.mjs +2 -2
  157. package/subscription/index.js +1 -1
  158. package/subscription/index.js.flow +1 -1
  159. package/subscription/index.mjs +2 -2
  160. package/subscription/mapAsyncIterator.js +1 -1
  161. package/subscription/mapAsyncIterator.js.flow +5 -5
  162. package/subscription/mapAsyncIterator.mjs +2 -2
  163. package/subscription/subscribe.js +2 -2
  164. package/subscription/subscribe.js.flow +6 -6
  165. package/subscription/subscribe.mjs +2 -2
  166. package/type/definition.js +138 -22
  167. package/type/definition.js.flow +184 -36
  168. package/type/definition.mjs +136 -23
  169. package/type/directives.js +14 -3
  170. package/type/directives.js.flow +24 -11
  171. package/type/directives.mjs +16 -5
  172. package/type/index.js +7 -7
  173. package/type/index.js.flow +8 -4
  174. package/type/index.mjs +10 -6
  175. package/type/introspection.js +14 -9
  176. package/type/introspection.js.flow +12 -18
  177. package/type/introspection.mjs +14 -9
  178. package/type/scalars.js +5 -4
  179. package/type/scalars.js.flow +4 -10
  180. package/type/scalars.mjs +7 -6
  181. package/type/schema.js +55 -3
  182. package/type/schema.js.flow +73 -17
  183. package/type/schema.mjs +56 -4
  184. package/type/validate.js +19 -47
  185. package/type/validate.js.flow +17 -29
  186. package/type/validate.mjs +18 -47
  187. package/utilities/TypeInfo.js +93 -73
  188. package/utilities/TypeInfo.js.flow +30 -23
  189. package/utilities/TypeInfo.mjs +93 -73
  190. package/utilities/assertValidName.js +2 -2
  191. package/utilities/assertValidName.js.flow +2 -2
  192. package/utilities/assertValidName.mjs +2 -2
  193. package/utilities/astFromValue.js +5 -4
  194. package/utilities/astFromValue.js.flow +8 -7
  195. package/utilities/astFromValue.mjs +7 -6
  196. package/utilities/buildASTSchema.js +63 -62
  197. package/utilities/buildASTSchema.js.flow +92 -108
  198. package/utilities/buildASTSchema.mjs +61 -62
  199. package/utilities/buildClientSchema.js +38 -45
  200. package/utilities/buildClientSchema.js.flow +66 -79
  201. package/utilities/buildClientSchema.mjs +37 -44
  202. package/utilities/coerceValue.js +6 -7
  203. package/utilities/coerceValue.js.flow +5 -4
  204. package/utilities/coerceValue.mjs +7 -8
  205. package/utilities/concatAST.js +9 -13
  206. package/utilities/concatAST.js.flow +4 -10
  207. package/utilities/concatAST.mjs +6 -13
  208. package/utilities/extendSchema.js +219 -511
  209. package/utilities/extendSchema.js.flow +195 -304
  210. package/utilities/extendSchema.mjs +218 -512
  211. package/utilities/findBreakingChanges.js +54 -95
  212. package/utilities/findBreakingChanges.js.flow +49 -47
  213. package/utilities/findBreakingChanges.mjs +80 -95
  214. package/utilities/findDeprecatedUsages.js +4 -4
  215. package/utilities/findDeprecatedUsages.js.flow +5 -5
  216. package/utilities/findDeprecatedUsages.mjs +4 -4
  217. package/utilities/getOperationAST.js +2 -2
  218. package/utilities/getOperationAST.js.flow +5 -2
  219. package/utilities/getOperationAST.mjs +2 -2
  220. package/utilities/getOperationRootType.js +24 -24
  221. package/utilities/getOperationRootType.js.flow +40 -35
  222. package/utilities/getOperationRootType.mjs +24 -24
  223. package/utilities/index.js +9 -1
  224. package/utilities/index.js.flow +13 -6
  225. package/utilities/index.mjs +13 -8
  226. package/utilities/introspectionFromSchema.js +6 -4
  227. package/utilities/introspectionFromSchema.js.flow +8 -7
  228. package/utilities/introspectionFromSchema.mjs +6 -5
  229. package/utilities/introspectionQuery.js +2 -2
  230. package/utilities/introspectionQuery.js.flow +2 -2
  231. package/utilities/introspectionQuery.mjs +2 -2
  232. package/utilities/isValidJSValue.js +4 -2
  233. package/utilities/isValidJSValue.js.flow +3 -2
  234. package/utilities/isValidJSValue.mjs +4 -2
  235. package/utilities/isValidLiteralValue.js +2 -2
  236. package/utilities/isValidLiteralValue.js.flow +4 -4
  237. package/utilities/isValidLiteralValue.mjs +2 -2
  238. package/utilities/lexicographicSortSchema.js +84 -123
  239. package/utilities/lexicographicSortSchema.js.flow +68 -96
  240. package/utilities/lexicographicSortSchema.mjs +84 -123
  241. package/utilities/schemaPrinter.js +47 -73
  242. package/utilities/schemaPrinter.js.flow +69 -120
  243. package/utilities/schemaPrinter.mjs +45 -72
  244. package/utilities/separateOperations.js +8 -12
  245. package/utilities/separateOperations.js.flow +6 -3
  246. package/utilities/separateOperations.mjs +8 -12
  247. package/utilities/stripIgnoredCharacters.js +140 -0
  248. package/utilities/stripIgnoredCharacters.js.flow +129 -0
  249. package/utilities/stripIgnoredCharacters.mjs +127 -0
  250. package/utilities/typeComparators.js +2 -2
  251. package/utilities/typeComparators.js.flow +4 -3
  252. package/utilities/typeComparators.mjs +2 -2
  253. package/utilities/typeFromAST.js +9 -4
  254. package/utilities/typeFromAST.js.flow +15 -9
  255. package/utilities/typeFromAST.mjs +6 -4
  256. package/utilities/valueFromAST.js +7 -4
  257. package/utilities/valueFromAST.js.flow +7 -5
  258. package/utilities/valueFromAST.mjs +6 -4
  259. package/utilities/valueFromASTUntyped.js +11 -6
  260. package/utilities/valueFromASTUntyped.js.flow +9 -5
  261. package/utilities/valueFromASTUntyped.mjs +10 -6
  262. package/validation/ValidationContext.js +1 -1
  263. package/validation/ValidationContext.js.flow +19 -20
  264. package/validation/ValidationContext.mjs +2 -2
  265. package/validation/index.js +1 -1
  266. package/validation/index.js.flow +2 -1
  267. package/validation/index.mjs +3 -2
  268. package/validation/rules/ExecutableDefinitions.js +3 -3
  269. package/validation/rules/ExecutableDefinitions.js.flow +4 -4
  270. package/validation/rules/ExecutableDefinitions.mjs +3 -3
  271. package/validation/rules/FieldsOnCorrectType.js +3 -3
  272. package/validation/rules/FieldsOnCorrectType.js.flow +7 -7
  273. package/validation/rules/FieldsOnCorrectType.mjs +3 -3
  274. package/validation/rules/FragmentsOnCompositeTypes.js +4 -4
  275. package/validation/rules/FragmentsOnCompositeTypes.js.flow +5 -5
  276. package/validation/rules/FragmentsOnCompositeTypes.mjs +4 -4
  277. package/validation/rules/KnownArgumentNames.js +1 -1
  278. package/validation/rules/KnownArgumentNames.js.flow +5 -5
  279. package/validation/rules/KnownArgumentNames.mjs +2 -2
  280. package/validation/rules/KnownDirectives.js +8 -6
  281. package/validation/rules/KnownDirectives.js.flow +11 -9
  282. package/validation/rules/KnownDirectives.mjs +8 -6
  283. package/validation/rules/KnownFragmentNames.js +3 -3
  284. package/validation/rules/KnownFragmentNames.js.flow +4 -4
  285. package/validation/rules/KnownFragmentNames.mjs +3 -3
  286. package/validation/rules/KnownTypeNames.js +2 -2
  287. package/validation/rules/KnownTypeNames.js.flow +6 -6
  288. package/validation/rules/KnownTypeNames.mjs +2 -2
  289. package/validation/rules/LoneAnonymousOperation.js +3 -3
  290. package/validation/rules/LoneAnonymousOperation.js.flow +4 -4
  291. package/validation/rules/LoneAnonymousOperation.mjs +3 -3
  292. package/validation/rules/LoneSchemaDefinition.js +2 -2
  293. package/validation/rules/LoneSchemaDefinition.js.flow +3 -3
  294. package/validation/rules/LoneSchemaDefinition.mjs +2 -2
  295. package/validation/rules/NoFragmentCycles.js +2 -2
  296. package/validation/rules/NoFragmentCycles.js.flow +4 -4
  297. package/validation/rules/NoFragmentCycles.mjs +2 -2
  298. package/validation/rules/NoUndefinedVariables.js +2 -2
  299. package/validation/rules/NoUndefinedVariables.js.flow +3 -3
  300. package/validation/rules/NoUndefinedVariables.mjs +2 -2
  301. package/validation/rules/NoUnusedFragments.js +7 -7
  302. package/validation/rules/NoUnusedFragments.js.flow +4 -4
  303. package/validation/rules/NoUnusedFragments.mjs +7 -7
  304. package/validation/rules/NoUnusedVariables.js +5 -5
  305. package/validation/rules/NoUnusedVariables.js.flow +6 -5
  306. package/validation/rules/NoUnusedVariables.mjs +5 -5
  307. package/validation/rules/OverlappingFieldsCanBeMerged.js +26 -23
  308. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +17 -17
  309. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +26 -23
  310. package/validation/rules/PossibleFragmentSpreads.js +4 -4
  311. package/validation/rules/PossibleFragmentSpreads.js.flow +5 -5
  312. package/validation/rules/PossibleFragmentSpreads.mjs +4 -4
  313. package/validation/rules/PossibleTypeExtensions.js +3 -3
  314. package/validation/rules/PossibleTypeExtensions.js.flow +5 -5
  315. package/validation/rules/PossibleTypeExtensions.mjs +4 -4
  316. package/validation/rules/ProvidedRequiredArguments.js +6 -8
  317. package/validation/rules/ProvidedRequiredArguments.js.flow +8 -8
  318. package/validation/rules/ProvidedRequiredArguments.mjs +7 -9
  319. package/validation/rules/ScalarLeafs.js +4 -4
  320. package/validation/rules/ScalarLeafs.js.flow +6 -6
  321. package/validation/rules/ScalarLeafs.mjs +4 -4
  322. package/validation/rules/SingleFieldSubscriptions.js +2 -2
  323. package/validation/rules/SingleFieldSubscriptions.js.flow +4 -4
  324. package/validation/rules/SingleFieldSubscriptions.mjs +2 -2
  325. package/validation/rules/UniqueArgumentNames.js +2 -2
  326. package/validation/rules/UniqueArgumentNames.js.flow +3 -3
  327. package/validation/rules/UniqueArgumentNames.mjs +2 -2
  328. package/validation/rules/UniqueDirectiveNames.js +2 -2
  329. package/validation/rules/UniqueDirectiveNames.js.flow +3 -3
  330. package/validation/rules/UniqueDirectiveNames.mjs +2 -2
  331. package/validation/rules/UniqueDirectivesPerLocation.js +3 -2
  332. package/validation/rules/UniqueDirectivesPerLocation.js.flow +4 -4
  333. package/validation/rules/UniqueDirectivesPerLocation.mjs +3 -2
  334. package/validation/rules/UniqueEnumValueNames.js +4 -8
  335. package/validation/rules/UniqueEnumValueNames.js.flow +6 -8
  336. package/validation/rules/UniqueEnumValueNames.mjs +4 -8
  337. package/validation/rules/UniqueFieldDefinitionNames.js +4 -8
  338. package/validation/rules/UniqueFieldDefinitionNames.js.flow +6 -8
  339. package/validation/rules/UniqueFieldDefinitionNames.mjs +4 -8
  340. package/validation/rules/UniqueFragmentNames.js +2 -2
  341. package/validation/rules/UniqueFragmentNames.js.flow +3 -3
  342. package/validation/rules/UniqueFragmentNames.mjs +2 -2
  343. package/validation/rules/UniqueInputFieldNames.js +2 -4
  344. package/validation/rules/UniqueInputFieldNames.js.flow +3 -4
  345. package/validation/rules/UniqueInputFieldNames.mjs +2 -4
  346. package/validation/rules/UniqueOperationNames.js +2 -2
  347. package/validation/rules/UniqueOperationNames.js.flow +3 -3
  348. package/validation/rules/UniqueOperationNames.mjs +2 -2
  349. package/validation/rules/UniqueOperationTypes.js +2 -2
  350. package/validation/rules/UniqueOperationTypes.js.flow +3 -3
  351. package/validation/rules/UniqueOperationTypes.mjs +2 -2
  352. package/validation/rules/UniqueTypeNames.js +2 -2
  353. package/validation/rules/UniqueTypeNames.js.flow +4 -4
  354. package/validation/rules/UniqueTypeNames.mjs +2 -2
  355. package/validation/rules/UniqueVariableNames.js +2 -2
  356. package/validation/rules/UniqueVariableNames.js.flow +4 -4
  357. package/validation/rules/UniqueVariableNames.mjs +2 -2
  358. package/validation/rules/ValuesOfCorrectType.js +2 -2
  359. package/validation/rules/ValuesOfCorrectType.js.flow +5 -5
  360. package/validation/rules/ValuesOfCorrectType.mjs +2 -2
  361. package/validation/rules/VariablesAreInputTypes.js +3 -3
  362. package/validation/rules/VariablesAreInputTypes.js.flow +5 -5
  363. package/validation/rules/VariablesAreInputTypes.mjs +3 -3
  364. package/validation/rules/VariablesInAllowedPosition.js +3 -3
  365. package/validation/rules/VariablesInAllowedPosition.js.flow +7 -8
  366. package/validation/rules/VariablesInAllowedPosition.mjs +3 -3
  367. package/validation/specifiedRules.js +2 -2
  368. package/validation/specifiedRules.js.flow +13 -6
  369. package/validation/specifiedRules.mjs +7 -7
  370. package/validation/validate.js +2 -2
  371. package/validation/validate.js.flow +10 -6
  372. package/validation/validate.mjs +2 -2
  373. package/jsutils/MaybePromise.js +0 -1
  374. package/jsutils/MaybePromise.mjs +0 -0
  375. package/language/blockStringValue.js +0 -73
  376. package/language/blockStringValue.js.flow +0 -64
  377. package/language/blockStringValue.mjs +0 -66
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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.
@@ -7,26 +7,24 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
+ import flatMap from '../polyfills/flatMap';
10
11
  import objectValues from '../polyfills/objectValues';
12
+ import inspect from '../jsutils/inspect';
11
13
  import invariant from '../jsutils/invariant';
12
14
  import mapValue from '../jsutils/mapValue';
13
15
  import keyValMap from '../jsutils/keyValMap';
14
16
  import { ASTDefinitionBuilder } from './buildASTSchema';
15
17
  import { assertValidSDLExtension } from '../validation/validate';
16
- import { assertSchema, GraphQLSchema } from '../type/schema';
18
+ import {
19
+ type GraphQLSchemaValidationOptions,
20
+ assertSchema,
21
+ GraphQLSchema,
22
+ } from '../type/schema';
17
23
  import { isIntrospectionType } from '../type/introspection';
18
24
  import { isSpecifiedScalarType } from '../type/scalars';
19
25
 
20
- import type { GraphQLSchemaValidationOptions } from '../type/schema';
21
-
22
- import type {
23
- GraphQLType,
24
- GraphQLNamedType,
25
- GraphQLArgument,
26
- GraphQLFieldConfigArgumentMap,
27
- } from '../type/definition';
28
-
29
26
  import {
27
+ type GraphQLNamedType,
30
28
  isScalarType,
31
29
  isObjectType,
32
30
  isInterfaceType,
@@ -49,11 +47,11 @@ import { GraphQLDirective } from '../type/directives';
49
47
 
50
48
  import { Kind } from '../language/kinds';
51
49
 
52
- import type {
53
- DocumentNode,
54
- DirectiveDefinitionNode,
55
- SchemaExtensionNode,
56
- SchemaDefinitionNode,
50
+ import {
51
+ type DocumentNode,
52
+ type DirectiveDefinitionNode,
53
+ type SchemaExtensionNode,
54
+ type SchemaDefinitionNode,
57
55
  } from '../language/ast';
58
56
  import {
59
57
  isTypeDefinitionNode,
@@ -116,405 +114,298 @@ export function extendSchema(
116
114
  }
117
115
 
118
116
  // Collect the type definitions and extensions found in the document.
119
- const typeDefinitionMap = Object.create(null);
120
- const typeExtensionsMap = Object.create(null);
117
+ const typeDefs = [];
118
+ const typeExtsMap = Object.create(null);
121
119
 
122
120
  // New directives and types are separate because a directives and types can
123
121
  // have the same name. For example, a type named "skip".
124
- const directiveDefinitions: Array<DirectiveDefinitionNode> = [];
122
+ const directiveDefs: Array<DirectiveDefinitionNode> = [];
125
123
 
126
124
  let schemaDef: ?SchemaDefinitionNode;
127
125
  // Schema extensions are collected which may add additional operation types.
128
- const schemaExtensions: Array<SchemaExtensionNode> = [];
126
+ const schemaExts: Array<SchemaExtensionNode> = [];
129
127
 
130
128
  for (const def of documentAST.definitions) {
131
129
  if (def.kind === Kind.SCHEMA_DEFINITION) {
132
130
  schemaDef = def;
133
131
  } else if (def.kind === Kind.SCHEMA_EXTENSION) {
134
- schemaExtensions.push(def);
132
+ schemaExts.push(def);
135
133
  } else if (isTypeDefinitionNode(def)) {
136
- const typeName = def.name.value;
137
- typeDefinitionMap[typeName] = def;
134
+ typeDefs.push(def);
138
135
  } else if (isTypeExtensionNode(def)) {
139
136
  const extendedTypeName = def.name.value;
140
- const existingTypeExtensions = typeExtensionsMap[extendedTypeName];
141
- typeExtensionsMap[extendedTypeName] = existingTypeExtensions
142
- ? existingTypeExtensions.concat([def])
137
+ const existingTypeExts = typeExtsMap[extendedTypeName];
138
+ typeExtsMap[extendedTypeName] = existingTypeExts
139
+ ? existingTypeExts.concat([def])
143
140
  : [def];
144
141
  } else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
145
- directiveDefinitions.push(def);
142
+ directiveDefs.push(def);
146
143
  }
147
144
  }
148
145
 
149
146
  // If this document contains no new types, extensions, or directives then
150
147
  // return the same unmodified GraphQLSchema instance.
151
148
  if (
152
- Object.keys(typeExtensionsMap).length === 0 &&
153
- Object.keys(typeDefinitionMap).length === 0 &&
154
- directiveDefinitions.length === 0 &&
155
- schemaExtensions.length === 0 &&
149
+ Object.keys(typeExtsMap).length === 0 &&
150
+ typeDefs.length === 0 &&
151
+ directiveDefs.length === 0 &&
152
+ schemaExts.length === 0 &&
156
153
  !schemaDef
157
154
  ) {
158
155
  return schema;
159
156
  }
160
157
 
161
- const astBuilder = new ASTDefinitionBuilder(
162
- typeDefinitionMap,
163
- options,
164
- typeName => {
165
- const existingType = schema.getType(typeName);
166
- invariant(existingType, `Unknown type: "${typeName}".`);
158
+ const schemaConfig = schema.toConfig();
159
+ const astBuilder = new ASTDefinitionBuilder(options, typeName => {
160
+ const type = typeMap[typeName];
161
+ invariant(type, `Unknown type: "${typeName}".`);
162
+ return type;
163
+ });
167
164
 
168
- return extendNamedType(existingType);
169
- },
165
+ const typeMap = keyValMap(
166
+ typeDefs,
167
+ node => node.name.value,
168
+ node => astBuilder.buildType(node),
170
169
  );
171
-
172
- const extendTypeCache = Object.create(null);
170
+ for (const existingType of schemaConfig.types) {
171
+ typeMap[existingType.name] = extendNamedType(existingType);
172
+ }
173
173
 
174
174
  // Get the extended root operation types.
175
175
  const operationTypes = {
176
- query: extendMaybeNamedType(schema.getQueryType()),
177
- mutation: extendMaybeNamedType(schema.getMutationType()),
178
- subscription: extendMaybeNamedType(schema.getSubscriptionType()),
176
+ query: schemaConfig.query && schemaConfig.query.name,
177
+ mutation: schemaConfig.mutation && schemaConfig.mutation.name,
178
+ subscription: schemaConfig.subscription && schemaConfig.subscription.name,
179
179
  };
180
180
 
181
181
  if (schemaDef) {
182
182
  for (const { operation, type } of schemaDef.operationTypes) {
183
- // Note: While this could make early assertions to get the correctly
184
- // typed values, that would throw immediately while type system
185
- // validation with validateSchema() will produce more actionable results.
186
- operationTypes[operation] = (astBuilder.buildType(type): any);
183
+ operationTypes[operation] = type.name.value;
187
184
  }
188
185
  }
186
+
189
187
  // Then, incorporate schema definition and all schema extensions.
190
- for (const schemaExtension of schemaExtensions) {
191
- if (schemaExtension.operationTypes) {
192
- for (const { operation, type } of schemaExtension.operationTypes) {
193
- // Note: While this could make early assertions to get the correctly
194
- // typed values, that would throw immediately while type system
195
- // validation with validateSchema() will produce more actionable results.
196
- operationTypes[operation] = (astBuilder.buildType(type): any);
188
+ for (const schemaExt of schemaExts) {
189
+ if (schemaExt.operationTypes) {
190
+ for (const { operation, type } of schemaExt.operationTypes) {
191
+ operationTypes[operation] = type.name.value;
197
192
  }
198
193
  }
199
194
  }
200
195
 
201
- const schemaExtensionASTNodes = schemaExtensions
202
- ? schema.extensionASTNodes
203
- ? schema.extensionASTNodes.concat(schemaExtensions)
204
- : schemaExtensions
205
- : schema.extensionASTNodes;
206
-
207
- const types = [
208
- // Iterate through all types, getting the type definition for each, ensuring
209
- // that any type not directly referenced by a field will get created.
210
- ...objectValues(schema.getTypeMap()).map(type => extendNamedType(type)),
211
- // Do the same with new types.
212
- ...objectValues(typeDefinitionMap).map(type => astBuilder.buildType(type)),
213
- ];
214
-
215
196
  // Support both original legacy names and extended legacy names.
216
- const allowedLegacyNames = schema.__allowedLegacyNames.concat(
197
+ const allowedLegacyNames = schemaConfig.allowedLegacyNames.concat(
217
198
  (options && options.allowedLegacyNames) || [],
218
199
  );
219
200
 
220
201
  // Then produce and return a Schema with these types.
221
202
  return new GraphQLSchema({
222
- ...operationTypes,
223
- types,
203
+ // Note: While this could make early assertions to get the correctly
204
+ // typed values, that would throw immediately while type system
205
+ // validation with validateSchema() will produce more actionable results.
206
+ query: (getMaybeTypeByName(operationTypes.query): any),
207
+ mutation: (getMaybeTypeByName(operationTypes.mutation): any),
208
+ subscription: (getMaybeTypeByName(operationTypes.subscription): any),
209
+
210
+ types: objectValues(typeMap),
224
211
  directives: getMergedDirectives(),
225
- astNode: schema.astNode,
226
- extensionASTNodes: schemaExtensionASTNodes,
212
+ astNode: schemaDef || schemaConfig.astNode,
213
+ extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExts),
227
214
  allowedLegacyNames,
228
215
  });
229
216
 
230
217
  // Below are functions used for producing this schema that have closed over
231
218
  // this scope and have access to the schema, cache, and newly defined types.
232
219
 
220
+ function replaceType(type) {
221
+ if (isListType(type)) {
222
+ return new GraphQLList(replaceType(type.ofType));
223
+ } else if (isNonNullType(type)) {
224
+ return new GraphQLNonNull(replaceType(type.ofType));
225
+ }
226
+ return replaceNamedType(type);
227
+ }
228
+
229
+ function replaceNamedType<T: GraphQLNamedType>(type: T): T {
230
+ return ((typeMap[type.name]: any): T);
231
+ }
232
+
233
+ function getMaybeTypeByName(typeName: ?string): ?GraphQLNamedType {
234
+ return typeName ? typeMap[typeName] : null;
235
+ }
236
+
233
237
  function getMergedDirectives(): Array<GraphQLDirective> {
234
238
  const existingDirectives = schema.getDirectives().map(extendDirective);
235
239
  invariant(existingDirectives, 'schema must have default directives');
236
240
 
237
241
  return existingDirectives.concat(
238
- directiveDefinitions.map(node => astBuilder.buildDirective(node)),
242
+ directiveDefs.map(node => astBuilder.buildDirective(node)),
239
243
  );
240
244
  }
241
245
 
242
- function extendMaybeNamedType<T: GraphQLNamedType>(type: ?T): ?T {
243
- return type ? extendNamedType(type) : null;
244
- }
245
-
246
- function extendNamedType<T: GraphQLNamedType>(type: T): T {
246
+ function extendNamedType(type: GraphQLNamedType): GraphQLNamedType {
247
247
  if (isIntrospectionType(type) || isSpecifiedScalarType(type)) {
248
248
  // Builtin types are not extended.
249
249
  return type;
250
+ } else if (isScalarType(type)) {
251
+ return extendScalarType(type);
252
+ } else if (isObjectType(type)) {
253
+ return extendObjectType(type);
254
+ } else if (isInterfaceType(type)) {
255
+ return extendInterfaceType(type);
256
+ } else if (isUnionType(type)) {
257
+ return extendUnionType(type);
258
+ } else if (isEnumType(type)) {
259
+ return extendEnumType(type);
260
+ } else if (isInputObjectType(type)) {
261
+ return extendInputObjectType(type);
250
262
  }
251
263
 
252
- const name = type.name;
253
- if (!extendTypeCache[name]) {
254
- if (isScalarType(type)) {
255
- extendTypeCache[name] = extendScalarType(type);
256
- } else if (isObjectType(type)) {
257
- extendTypeCache[name] = extendObjectType(type);
258
- } else if (isInterfaceType(type)) {
259
- extendTypeCache[name] = extendInterfaceType(type);
260
- } else if (isUnionType(type)) {
261
- extendTypeCache[name] = extendUnionType(type);
262
- } else if (isEnumType(type)) {
263
- extendTypeCache[name] = extendEnumType(type);
264
- } else if (isInputObjectType(type)) {
265
- extendTypeCache[name] = extendInputObjectType(type);
266
- }
267
- }
268
- return (extendTypeCache[name]: any);
264
+ // Not reachable. All possible types have been considered.
265
+ /* istanbul ignore next */
266
+ throw new Error(`Unexpected type: "${inspect((type: empty))}".`);
269
267
  }
270
268
 
271
269
  function extendDirective(directive: GraphQLDirective): GraphQLDirective {
270
+ const config = directive.toConfig();
271
+
272
272
  return new GraphQLDirective({
273
- name: directive.name,
274
- description: directive.description,
275
- locations: directive.locations,
276
- args: extendArgs(directive.args),
277
- astNode: directive.astNode,
273
+ ...config,
274
+ args: mapValue(config.args, extendArg),
278
275
  });
279
276
  }
280
277
 
281
278
  function extendInputObjectType(
282
279
  type: GraphQLInputObjectType,
283
280
  ): GraphQLInputObjectType {
284
- const name = type.name;
285
- const extensionASTNodes = typeExtensionsMap[name]
286
- ? type.extensionASTNodes
287
- ? type.extensionASTNodes.concat(typeExtensionsMap[name])
288
- : typeExtensionsMap[name]
289
- : type.extensionASTNodes;
281
+ const config = type.toConfig();
282
+ const extensions = typeExtsMap[config.name] || [];
283
+ const fieldNodes = flatMap(extensions, node => node.fields || []);
284
+
290
285
  return new GraphQLInputObjectType({
291
- name,
292
- description: type.description,
293
- fields: () => extendInputFieldMap(type),
294
- astNode: type.astNode,
295
- extensionASTNodes,
286
+ ...config,
287
+ fields: () => ({
288
+ ...mapValue(config.fields, field => ({
289
+ ...field,
290
+ type: replaceType(field.type),
291
+ })),
292
+ ...keyValMap(
293
+ fieldNodes,
294
+ field => field.name.value,
295
+ field => astBuilder.buildInputField(field),
296
+ ),
297
+ }),
298
+ extensionASTNodes: config.extensionASTNodes.concat(extensions),
296
299
  });
297
300
  }
298
301
 
299
- function extendInputFieldMap(type: GraphQLInputObjectType) {
300
- const newFieldMap = mapValue(type.getFields(), field => ({
301
- description: field.description,
302
- type: extendType(field.type),
303
- defaultValue: field.defaultValue,
304
- astNode: field.astNode,
305
- }));
306
-
307
- // If there are any extensions to the fields, apply those here.
308
- const extensions = typeExtensionsMap[type.name];
309
- if (extensions) {
310
- for (const extension of extensions) {
311
- for (const field of extension.fields) {
312
- newFieldMap[field.name.value] = astBuilder.buildInputField(field);
313
- }
314
- }
315
- }
316
-
317
- return newFieldMap;
318
- }
319
-
320
302
  function extendEnumType(type: GraphQLEnumType): GraphQLEnumType {
321
- const name = type.name;
322
- const extensionASTNodes = typeExtensionsMap[name]
323
- ? type.extensionASTNodes
324
- ? type.extensionASTNodes.concat(typeExtensionsMap[name])
325
- : typeExtensionsMap[name]
326
- : type.extensionASTNodes;
303
+ const config = type.toConfig();
304
+ const extensions = typeExtsMap[type.name] || [];
305
+ const valueNodes = flatMap(extensions, node => node.values || []);
306
+
327
307
  return new GraphQLEnumType({
328
- name,
329
- description: type.description,
330
- values: extendValueMap(type),
331
- astNode: type.astNode,
332
- extensionASTNodes,
308
+ ...config,
309
+ values: {
310
+ ...config.values,
311
+ ...keyValMap(
312
+ valueNodes,
313
+ value => value.name.value,
314
+ value => astBuilder.buildEnumValue(value),
315
+ ),
316
+ },
317
+ extensionASTNodes: config.extensionASTNodes.concat(extensions),
333
318
  });
334
319
  }
335
320
 
336
- function extendValueMap(type: GraphQLEnumType) {
337
- const newValueMap = Object.create(null);
338
- for (const value of type.getValues()) {
339
- newValueMap[value.name] = {
340
- description: value.description,
341
- value: value.value,
342
- deprecationReason: value.deprecationReason,
343
- astNode: value.astNode,
344
- };
345
- }
346
-
347
- // If there are any extensions to the values, apply those here.
348
- const extensions = typeExtensionsMap[type.name];
349
- if (extensions) {
350
- for (const extension of extensions) {
351
- for (const value of extension.values) {
352
- newValueMap[value.name.value] = astBuilder.buildEnumValue(value);
353
- }
354
- }
355
- }
356
-
357
- return newValueMap;
358
- }
359
-
360
321
  function extendScalarType(type: GraphQLScalarType): GraphQLScalarType {
361
- const name = type.name;
362
- const extensionASTNodes = typeExtensionsMap[name]
363
- ? type.extensionASTNodes
364
- ? type.extensionASTNodes.concat(typeExtensionsMap[name])
365
- : typeExtensionsMap[name]
366
- : type.extensionASTNodes;
322
+ const config = type.toConfig();
323
+ const extensions = typeExtsMap[config.name] || [];
324
+
367
325
  return new GraphQLScalarType({
368
- name,
369
- description: type.description,
370
- astNode: type.astNode,
371
- extensionASTNodes,
372
- serialize: type.serialize,
373
- parseValue: type.parseValue,
374
- parseLiteral: type.parseLiteral,
326
+ ...config,
327
+ extensionASTNodes: config.extensionASTNodes.concat(extensions),
375
328
  });
376
329
  }
377
330
 
378
331
  function extendObjectType(type: GraphQLObjectType): GraphQLObjectType {
379
- const name = type.name;
380
- const extensionASTNodes = typeExtensionsMap[name]
381
- ? type.extensionASTNodes
382
- ? type.extensionASTNodes.concat(typeExtensionsMap[name])
383
- : typeExtensionsMap[name]
384
- : type.extensionASTNodes;
385
- return new GraphQLObjectType({
386
- name,
387
- description: type.description,
388
- interfaces: () => extendImplementedInterfaces(type),
389
- fields: () => extendFieldMap(type),
390
- astNode: type.astNode,
391
- extensionASTNodes,
392
- isTypeOf: type.isTypeOf,
393
- });
394
- }
332
+ const config = type.toConfig();
333
+ const extensions = typeExtsMap[config.name] || [];
334
+ const interfaceNodes = flatMap(extensions, node => node.interfaces || []);
335
+ const fieldNodes = flatMap(extensions, node => node.fields || []);
395
336
 
396
- function extendArgs(
397
- args: Array<GraphQLArgument>,
398
- ): GraphQLFieldConfigArgumentMap {
399
- return keyValMap(
400
- args,
401
- arg => arg.name,
402
- arg => ({
403
- type: extendType(arg.type),
404
- defaultValue: arg.defaultValue,
405
- description: arg.description,
406
- astNode: arg.astNode,
337
+ return new GraphQLObjectType({
338
+ ...config,
339
+ interfaces: () => [
340
+ ...type.getInterfaces().map(replaceNamedType),
341
+ // Note: While this could make early assertions to get the correctly
342
+ // typed values, that would throw immediately while type system
343
+ // validation with validateSchema() will produce more actionable results.
344
+ ...interfaceNodes.map(node => (astBuilder.getNamedType(node): any)),
345
+ ],
346
+ fields: () => ({
347
+ ...mapValue(config.fields, extendField),
348
+ ...keyValMap(
349
+ fieldNodes,
350
+ node => node.name.value,
351
+ node => astBuilder.buildField(node),
352
+ ),
407
353
  }),
408
- );
354
+ extensionASTNodes: config.extensionASTNodes.concat(extensions),
355
+ });
409
356
  }
410
357
 
411
358
  function extendInterfaceType(
412
359
  type: GraphQLInterfaceType,
413
360
  ): GraphQLInterfaceType {
414
- const name = type.name;
415
- const extensionASTNodes = typeExtensionsMap[name]
416
- ? type.extensionASTNodes
417
- ? type.extensionASTNodes.concat(typeExtensionsMap[name])
418
- : typeExtensionsMap[name]
419
- : type.extensionASTNodes;
361
+ const config = type.toConfig();
362
+ const extensions = typeExtsMap[config.name] || [];
363
+ const fieldNodes = flatMap(extensions, node => node.fields || []);
364
+
420
365
  return new GraphQLInterfaceType({
421
- name: type.name,
422
- description: type.description,
423
- fields: () => extendFieldMap(type),
424
- astNode: type.astNode,
425
- extensionASTNodes,
426
- resolveType: type.resolveType,
366
+ ...config,
367
+ fields: () => ({
368
+ ...mapValue(config.fields, extendField),
369
+ ...keyValMap(
370
+ fieldNodes,
371
+ node => node.name.value,
372
+ node => astBuilder.buildField(node),
373
+ ),
374
+ }),
375
+ extensionASTNodes: config.extensionASTNodes.concat(extensions),
427
376
  });
428
377
  }
429
378
 
430
379
  function extendUnionType(type: GraphQLUnionType): GraphQLUnionType {
431
- const name = type.name;
432
- const extensionASTNodes = typeExtensionsMap[name]
433
- ? type.extensionASTNodes
434
- ? type.extensionASTNodes.concat(typeExtensionsMap[name])
435
- : typeExtensionsMap[name]
436
- : type.extensionASTNodes;
380
+ const config = type.toConfig();
381
+ const extensions = typeExtsMap[config.name] || [];
382
+ const typeNodes = flatMap(extensions, node => node.types || []);
383
+
437
384
  return new GraphQLUnionType({
438
- name,
439
- description: type.description,
440
- types: () => extendPossibleTypes(type),
441
- astNode: type.astNode,
442
- resolveType: type.resolveType,
443
- extensionASTNodes,
385
+ ...config,
386
+ types: () => [
387
+ ...type.getTypes().map(replaceNamedType),
388
+ // Note: While this could make early assertions to get the correctly
389
+ // typed values, that would throw immediately while type system
390
+ // validation with validateSchema() will produce more actionable results.
391
+ ...typeNodes.map(node => (astBuilder.getNamedType(node): any)),
392
+ ],
393
+ extensionASTNodes: config.extensionASTNodes.concat(extensions),
444
394
  });
445
395
  }
446
396
 
447
- function extendPossibleTypes(
448
- type: GraphQLUnionType,
449
- ): Array<GraphQLObjectType> {
450
- const possibleTypes = type.getTypes().map(extendNamedType);
451
-
452
- // If there are any extensions to the union, apply those here.
453
- const extensions = typeExtensionsMap[type.name];
454
- if (extensions) {
455
- for (const extension of extensions) {
456
- for (const namedType of extension.types) {
457
- // Note: While this could make early assertions to get the correctly
458
- // typed values, that would throw immediately while type system
459
- // validation with validateSchema() will produce more actionable results.
460
- possibleTypes.push((astBuilder.buildType(namedType): any));
461
- }
462
- }
463
- }
464
- return possibleTypes;
397
+ function extendField(field) {
398
+ return {
399
+ ...field,
400
+ type: replaceType(field.type),
401
+ args: mapValue(field.args, extendArg),
402
+ };
465
403
  }
466
404
 
467
- function extendImplementedInterfaces(
468
- type: GraphQLObjectType,
469
- ): Array<GraphQLInterfaceType> {
470
- const interfaces = type.getInterfaces().map(extendNamedType);
471
-
472
- // If there are any extensions to the interfaces, apply those here.
473
- const extensions = typeExtensionsMap[type.name];
474
- if (extensions) {
475
- for (const extension of extensions) {
476
- for (const namedType of extension.interfaces) {
477
- // Note: While this could make early assertions to get the correctly
478
- // typed values, that would throw immediately while type system
479
- // validation with validateSchema() will produce more actionable results.
480
- interfaces.push((astBuilder.buildType(namedType): any));
481
- }
482
- }
483
- }
484
-
485
- return interfaces;
486
- }
487
-
488
- function extendFieldMap(type: GraphQLObjectType | GraphQLInterfaceType) {
489
- const newFieldMap = mapValue(type.getFields(), field => ({
490
- description: field.description,
491
- deprecationReason: field.deprecationReason,
492
- type: extendType(field.type),
493
- args: extendArgs(field.args),
494
- astNode: field.astNode,
495
- resolve: field.resolve,
496
- }));
497
-
498
- // If there are any extensions to the fields, apply those here.
499
- const extensions = typeExtensionsMap[type.name];
500
- if (extensions) {
501
- for (const extension of extensions) {
502
- for (const field of extension.fields) {
503
- newFieldMap[field.name.value] = astBuilder.buildField(field);
504
- }
505
- }
506
- }
507
-
508
- return newFieldMap;
509
- }
510
-
511
- function extendType<T: GraphQLType>(typeDef: T): T {
512
- if (isListType(typeDef)) {
513
- return (GraphQLList(extendType(typeDef.ofType)): any);
514
- }
515
- if (isNonNullType(typeDef)) {
516
- return (GraphQLNonNull(extendType(typeDef.ofType)): any);
517
- }
518
- return extendNamedType(typeDef);
405
+ function extendArg(arg) {
406
+ return {
407
+ ...arg,
408
+ type: replaceType(arg.type),
409
+ };
519
410
  }
520
411
  }