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
package/type/validate.js CHANGED
@@ -6,6 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.validateSchema = validateSchema;
7
7
  exports.assertValidSchema = assertValidSchema;
8
8
 
9
+ var _find = _interopRequireDefault(require("../polyfills/find"));
10
+
11
+ var _flatMap = _interopRequireDefault(require("../polyfills/flatMap"));
12
+
13
+ var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
14
+
15
+ var _objectEntries = _interopRequireDefault(require("../polyfills/objectEntries"));
16
+
9
17
  var _definition = require("./definition");
10
18
 
11
19
  var _directives = require("./directives");
@@ -16,12 +24,6 @@ var _schema = require("./schema");
16
24
 
17
25
  var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
18
26
 
19
- var _find = _interopRequireDefault(require("../jsutils/find"));
20
-
21
- var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
22
-
23
- var _objectValues = _interopRequireDefault(require("../jsutils/objectValues"));
24
-
25
27
  var _GraphQLError = require("../error/GraphQLError");
26
28
 
27
29
  var _assertValidName = require("../utilities/assertValidName");
@@ -30,7 +32,14 @@ var _typeComparators = require("../utilities/typeComparators");
30
32
 
31
33
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
34
 
33
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+ /**
36
+ * Copyright (c) Facebook, Inc. and its affiliates.
37
+ *
38
+ * This source code is licensed under the MIT license found in the
39
+ * LICENSE file in the root directory of this source tree.
40
+ *
41
+ *
42
+ */
34
43
 
35
44
  /**
36
45
  * Implements the "Type Validation" sub-sections of the specification's
@@ -41,7 +50,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
41
50
  */
42
51
  function validateSchema(schema) {
43
52
  // First check to ensure the provided value is in fact a GraphQLSchema.
44
- !(0, _schema.isSchema)(schema) ? (0, _invariant.default)(0, "Expected ".concat((0, _inspect.default)(schema), " to be a GraphQL schema.")) : void 0; // If this Schema has already been validated, return the previous results.
53
+ (0, _schema.assertSchema)(schema); // If this Schema has already been validated, return the previous results.
45
54
 
46
55
  if (schema.__validationErrors) {
47
56
  return schema.__validationErrors;
@@ -78,10 +87,6 @@ var SchemaValidationContext =
78
87
  /*#__PURE__*/
79
88
  function () {
80
89
  function SchemaValidationContext(schema) {
81
- _defineProperty(this, "_errors", void 0);
82
-
83
- _defineProperty(this, "schema", void 0);
84
-
85
90
  this._errors = [];
86
91
  this.schema = schema;
87
92
  }
@@ -89,7 +94,7 @@ function () {
89
94
  var _proto = SchemaValidationContext.prototype;
90
95
 
91
96
  _proto.reportError = function reportError(message, nodes) {
92
- var _nodes = (Array.isArray(nodes) ? nodes : [nodes]).filter(Boolean);
97
+ var _nodes = Array.isArray(nodes) ? nodes.filter(Boolean) : nodes;
93
98
 
94
99
  this.addError(new _GraphQLError.GraphQLError(message, _nodes));
95
100
  };
@@ -321,15 +326,7 @@ function validateFields(context, type) {
321
326
  for (var _iterator5 = fields[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
322
327
  var field = _step5.value;
323
328
  // Ensure they are named correctly.
324
- validateName(context, field); // Ensure they were defined at most once.
325
-
326
- var fieldNodes = getAllFieldNodes(type, field.name);
327
-
328
- if (fieldNodes.length > 1) {
329
- context.reportError("Field ".concat(type.name, ".").concat(field.name, " can only be defined once."), fieldNodes);
330
- continue;
331
- } // Ensure the type is an output type
332
-
329
+ validateName(context, field); // Ensure the type is an output type
333
330
 
334
331
  if (!(0, _definition.isOutputType)(field.type)) {
335
332
  context.reportError("The type of ".concat(type.name, ".").concat(field.name, " must be Output Type ") + "but got: ".concat((0, _inspect.default)(field.type), "."), getFieldTypeNode(type, field.name));
@@ -432,104 +429,122 @@ function validateObjectImplementsInterface(context, object, iface) {
432
429
  var objectFieldMap = object.getFields();
433
430
  var ifaceFieldMap = iface.getFields(); // Assert each interface field is implemented.
434
431
 
435
- var _arr = Object.keys(ifaceFieldMap);
432
+ var _iteratorNormalCompletion8 = true;
433
+ var _didIteratorError8 = false;
434
+ var _iteratorError8 = undefined;
436
435
 
437
- for (var _i = 0; _i < _arr.length; _i++) {
438
- var fieldName = _arr[_i];
439
- var objectField = objectFieldMap[fieldName];
440
- var ifaceField = ifaceFieldMap[fieldName]; // Assert interface field exists on object.
436
+ try {
437
+ for (var _iterator8 = (0, _objectEntries.default)(ifaceFieldMap)[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
438
+ var _ref2 = _step8.value;
439
+ var fieldName = _ref2[0];
440
+ var ifaceField = _ref2[1];
441
+ var objectField = objectFieldMap[fieldName]; // Assert interface field exists on object.
442
+
443
+ if (!objectField) {
444
+ context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expected but ") + "".concat(object.name, " does not provide it."), [getFieldNode(iface, fieldName)].concat(getAllNodes(object)));
445
+ continue;
446
+ } // Assert interface field type is satisfied by object field type, by being
447
+ // a valid subtype. (covariant)
441
448
 
442
- if (!objectField) {
443
- context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expected but ") + "".concat(object.name, " does not provide it."), [getFieldNode(iface, fieldName)].concat(getAllNodes(object)));
444
- continue;
445
- } // Assert interface field type is satisfied by object field type, by being
446
- // a valid subtype. (covariant)
447
449
 
450
+ if (!(0, _typeComparators.isTypeSubTypeOf)(context.schema, objectField.type, ifaceField.type)) {
451
+ context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expects type ") + "".concat((0, _inspect.default)(ifaceField.type), " but ").concat(object.name, ".").concat(fieldName, " ") + "is type ".concat((0, _inspect.default)(objectField.type), "."), [getFieldTypeNode(iface, fieldName), getFieldTypeNode(object, fieldName)]);
452
+ } // Assert each interface field arg is implemented.
448
453
 
449
- if (!(0, _typeComparators.isTypeSubTypeOf)(context.schema, objectField.type, ifaceField.type)) {
450
- context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expects type ") + "".concat((0, _inspect.default)(ifaceField.type), " but ").concat(object.name, ".").concat(fieldName, " ") + "is type ".concat((0, _inspect.default)(objectField.type), "."), [getFieldTypeNode(iface, fieldName), getFieldTypeNode(object, fieldName)]);
451
- } // Assert each interface field arg is implemented.
452
454
 
455
+ var _iteratorNormalCompletion9 = true;
456
+ var _didIteratorError9 = false;
457
+ var _iteratorError9 = undefined;
453
458
 
454
- var _iteratorNormalCompletion8 = true;
455
- var _didIteratorError8 = false;
456
- var _iteratorError8 = undefined;
459
+ try {
460
+ var _loop = function _loop() {
461
+ var ifaceArg = _step9.value;
462
+ var argName = ifaceArg.name;
463
+ var objectArg = (0, _find.default)(objectField.args, function (arg) {
464
+ return arg.name === argName;
465
+ }); // Assert interface field arg exists on object field.
457
466
 
458
- try {
459
- var _loop = function _loop() {
460
- var ifaceArg = _step8.value;
461
- var argName = ifaceArg.name;
462
- var objectArg = (0, _find.default)(objectField.args, function (arg) {
463
- return arg.name === argName;
464
- }); // Assert interface field arg exists on object field.
467
+ if (!objectArg) {
468
+ context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expected but ".concat(object.name, ".").concat(fieldName, " does not provide it."), [getFieldArgNode(iface, fieldName, argName), getFieldNode(object, fieldName)]);
469
+ return "continue";
470
+ } // Assert interface field arg type matches object field arg type.
471
+ // (invariant)
472
+ // TODO: change to contravariant?
465
473
 
466
- if (!objectArg) {
467
- context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expected but ".concat(object.name, ".").concat(fieldName, " does not provide it."), [getFieldArgNode(iface, fieldName, argName), getFieldNode(object, fieldName)]);
468
- return "continue";
469
- } // Assert interface field arg type matches object field arg type.
470
- // (invariant)
471
- // TODO: change to contravariant?
472
474
 
475
+ if (!(0, _typeComparators.isEqualType)(ifaceArg.type, objectArg.type)) {
476
+ context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expects type ".concat((0, _inspect.default)(ifaceArg.type), " but ") + "".concat(object.name, ".").concat(fieldName, "(").concat(argName, ":) is type ") + "".concat((0, _inspect.default)(objectArg.type), "."), [getFieldArgTypeNode(iface, fieldName, argName), getFieldArgTypeNode(object, fieldName, argName)]);
477
+ } // TODO: validate default values?
473
478
 
474
- if (!(0, _typeComparators.isEqualType)(ifaceArg.type, objectArg.type)) {
475
- context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expects type ".concat((0, _inspect.default)(ifaceArg.type), " but ") + "".concat(object.name, ".").concat(fieldName, "(").concat(argName, ":) is type ") + "".concat((0, _inspect.default)(objectArg.type), "."), [getFieldArgTypeNode(iface, fieldName, argName), getFieldArgTypeNode(object, fieldName, argName)]);
476
- } // TODO: validate default values?
479
+ };
477
480
 
478
- };
481
+ for (var _iterator9 = ifaceField.args[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
482
+ var _ret = _loop();
479
483
 
480
- for (var _iterator8 = ifaceField.args[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
481
- var _ret = _loop();
484
+ if (_ret === "continue") continue;
485
+ } // Assert additional arguments must not be required.
486
+
487
+ } catch (err) {
488
+ _didIteratorError9 = true;
489
+ _iteratorError9 = err;
490
+ } finally {
491
+ try {
492
+ if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
493
+ _iterator9.return();
494
+ }
495
+ } finally {
496
+ if (_didIteratorError9) {
497
+ throw _iteratorError9;
498
+ }
499
+ }
500
+ }
482
501
 
483
- if (_ret === "continue") continue;
484
- } // Assert additional arguments must not be required.
502
+ var _iteratorNormalCompletion10 = true;
503
+ var _didIteratorError10 = false;
504
+ var _iteratorError10 = undefined;
485
505
 
486
- } catch (err) {
487
- _didIteratorError8 = true;
488
- _iteratorError8 = err;
489
- } finally {
490
506
  try {
491
- if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
492
- _iterator8.return();
507
+ var _loop2 = function _loop2() {
508
+ var objectArg = _step10.value;
509
+ var argName = objectArg.name;
510
+ var ifaceArg = (0, _find.default)(ifaceField.args, function (arg) {
511
+ return arg.name === argName;
512
+ });
513
+
514
+ if (!ifaceArg && (0, _definition.isRequiredArgument)(objectArg)) {
515
+ context.reportError("Object field ".concat(object.name, ".").concat(fieldName, " includes required ") + "argument ".concat(argName, " that is missing from the Interface field ") + "".concat(iface.name, ".").concat(fieldName, "."), [getFieldArgNode(object, fieldName, argName), getFieldNode(iface, fieldName)]);
516
+ }
517
+ };
518
+
519
+ for (var _iterator10 = objectField.args[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
520
+ _loop2();
493
521
  }
522
+ } catch (err) {
523
+ _didIteratorError10 = true;
524
+ _iteratorError10 = err;
494
525
  } finally {
495
- if (_didIteratorError8) {
496
- throw _iteratorError8;
526
+ try {
527
+ if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
528
+ _iterator10.return();
529
+ }
530
+ } finally {
531
+ if (_didIteratorError10) {
532
+ throw _iteratorError10;
533
+ }
497
534
  }
498
535
  }
499
536
  }
500
-
501
- var _iteratorNormalCompletion9 = true;
502
- var _didIteratorError9 = false;
503
- var _iteratorError9 = undefined;
504
-
537
+ } catch (err) {
538
+ _didIteratorError8 = true;
539
+ _iteratorError8 = err;
540
+ } finally {
505
541
  try {
506
- var _loop2 = function _loop2() {
507
- var objectArg = _step9.value;
508
- var argName = objectArg.name;
509
- var ifaceArg = (0, _find.default)(ifaceField.args, function (arg) {
510
- return arg.name === argName;
511
- });
512
-
513
- if (!ifaceArg && (0, _definition.isRequiredArgument)(objectArg)) {
514
- context.reportError("Object field ".concat(object.name, ".").concat(fieldName, " includes required ") + "argument ".concat(argName, " that is missing from the Interface field ") + "".concat(iface.name, ".").concat(fieldName, "."), [getFieldArgNode(object, fieldName, argName), getFieldNode(iface, fieldName)]);
515
- }
516
- };
517
-
518
- for (var _iterator9 = objectField.args[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
519
- _loop2();
542
+ if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
543
+ _iterator8.return();
520
544
  }
521
- } catch (err) {
522
- _didIteratorError9 = true;
523
- _iteratorError9 = err;
524
545
  } finally {
525
- try {
526
- if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
527
- _iterator9.return();
528
- }
529
- } finally {
530
- if (_didIteratorError9) {
531
- throw _iteratorError9;
532
- }
546
+ if (_didIteratorError8) {
547
+ throw _iteratorError8;
533
548
  }
534
549
  }
535
550
  }
@@ -543,13 +558,13 @@ function validateUnionMembers(context, union) {
543
558
  }
544
559
 
545
560
  var includedTypeNames = Object.create(null);
546
- var _iteratorNormalCompletion10 = true;
547
- var _didIteratorError10 = false;
548
- var _iteratorError10 = undefined;
561
+ var _iteratorNormalCompletion11 = true;
562
+ var _didIteratorError11 = false;
563
+ var _iteratorError11 = undefined;
549
564
 
550
565
  try {
551
- for (var _iterator10 = memberTypes[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
552
- var memberType = _step10.value;
566
+ for (var _iterator11 = memberTypes[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
567
+ var memberType = _step11.value;
553
568
 
554
569
  if (includedTypeNames[memberType.name]) {
555
570
  context.reportError("Union type ".concat(union.name, " can only include type ") + "".concat(memberType.name, " once."), getUnionMemberTypeNodes(union, memberType.name));
@@ -563,16 +578,16 @@ function validateUnionMembers(context, union) {
563
578
  }
564
579
  }
565
580
  } catch (err) {
566
- _didIteratorError10 = true;
567
- _iteratorError10 = err;
581
+ _didIteratorError11 = true;
582
+ _iteratorError11 = err;
568
583
  } finally {
569
584
  try {
570
- if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
571
- _iterator10.return();
585
+ if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
586
+ _iterator11.return();
572
587
  }
573
588
  } finally {
574
- if (_didIteratorError10) {
575
- throw _iteratorError10;
589
+ if (_didIteratorError11) {
590
+ throw _iteratorError11;
576
591
  }
577
592
  }
578
593
  }
@@ -585,21 +600,14 @@ function validateEnumValues(context, enumType) {
585
600
  context.reportError("Enum type ".concat(enumType.name, " must define one or more values."), getAllNodes(enumType));
586
601
  }
587
602
 
588
- var _iteratorNormalCompletion11 = true;
589
- var _didIteratorError11 = false;
590
- var _iteratorError11 = undefined;
603
+ var _iteratorNormalCompletion12 = true;
604
+ var _didIteratorError12 = false;
605
+ var _iteratorError12 = undefined;
591
606
 
592
607
  try {
593
- for (var _iterator11 = enumValues[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
594
- var enumValue = _step11.value;
595
- var valueName = enumValue.name; // Ensure no duplicates.
596
-
597
- var allNodes = getEnumValueNodes(enumType, valueName);
598
-
599
- if (allNodes && allNodes.length > 1) {
600
- context.reportError("Enum type ".concat(enumType.name, " can include value ").concat(valueName, " only once."), allNodes);
601
- } // Ensure valid name.
602
-
608
+ for (var _iterator12 = enumValues[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
609
+ var enumValue = _step12.value;
610
+ var valueName = enumValue.name; // Ensure valid name.
603
611
 
604
612
  validateName(context, enumValue);
605
613
 
@@ -608,16 +616,16 @@ function validateEnumValues(context, enumType) {
608
616
  }
609
617
  }
610
618
  } catch (err) {
611
- _didIteratorError11 = true;
612
- _iteratorError11 = err;
619
+ _didIteratorError12 = true;
620
+ _iteratorError12 = err;
613
621
  } finally {
614
622
  try {
615
- if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
616
- _iterator11.return();
623
+ if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
624
+ _iterator12.return();
617
625
  }
618
626
  } finally {
619
- if (_didIteratorError11) {
620
- throw _iteratorError11;
627
+ if (_didIteratorError12) {
628
+ throw _iteratorError12;
621
629
  }
622
630
  }
623
631
  }
@@ -631,32 +639,31 @@ function validateInputFields(context, inputObj) {
631
639
  } // Ensure the arguments are valid
632
640
 
633
641
 
634
- var _iteratorNormalCompletion12 = true;
635
- var _didIteratorError12 = false;
636
- var _iteratorError12 = undefined;
642
+ var _iteratorNormalCompletion13 = true;
643
+ var _didIteratorError13 = false;
644
+ var _iteratorError13 = undefined;
637
645
 
638
646
  try {
639
- for (var _iterator12 = fields[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
640
- var field = _step12.value;
647
+ for (var _iterator13 = fields[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
648
+ var field = _step13.value;
641
649
  // Ensure they are named correctly.
642
- validateName(context, field); // TODO: Ensure they are unique per field.
643
- // Ensure the type is an input type
650
+ validateName(context, field); // Ensure the type is an input type
644
651
 
645
652
  if (!(0, _definition.isInputType)(field.type)) {
646
653
  context.reportError("The type of ".concat(inputObj.name, ".").concat(field.name, " must be Input Type ") + "but got: ".concat((0, _inspect.default)(field.type), "."), field.astNode && field.astNode.type);
647
654
  }
648
655
  }
649
656
  } catch (err) {
650
- _didIteratorError12 = true;
651
- _iteratorError12 = err;
657
+ _didIteratorError13 = true;
658
+ _iteratorError13 = err;
652
659
  } finally {
653
660
  try {
654
- if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
655
- _iterator12.return();
661
+ if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
662
+ _iterator13.return();
656
663
  }
657
664
  } finally {
658
- if (_didIteratorError12) {
659
- throw _iteratorError12;
665
+ if (_didIteratorError13) {
666
+ throw _iteratorError13;
660
667
  }
661
668
  }
662
669
  }
@@ -669,39 +676,9 @@ function getAllNodes(object) {
669
676
  }
670
677
 
671
678
  function getAllSubNodes(object, getter) {
672
- var result = [];
673
- var _iteratorNormalCompletion13 = true;
674
- var _didIteratorError13 = false;
675
- var _iteratorError13 = undefined;
676
-
677
- try {
678
- for (var _iterator13 = getAllNodes(object)[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
679
- var astNode = _step13.value;
680
-
681
- if (astNode) {
682
- var subNodes = getter(astNode);
683
-
684
- if (subNodes) {
685
- result = result.concat(subNodes);
686
- }
687
- }
688
- }
689
- } catch (err) {
690
- _didIteratorError13 = true;
691
- _iteratorError13 = err;
692
- } finally {
693
- try {
694
- if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
695
- _iterator13.return();
696
- }
697
- } finally {
698
- if (_didIteratorError13) {
699
- throw _iteratorError13;
700
- }
701
- }
702
- }
703
-
704
- return result;
679
+ return (0, _flatMap.default)(getAllNodes(object), function (item) {
680
+ return getter(item) || [];
681
+ });
705
682
  }
706
683
 
707
684
  function getImplementsInterfaceNode(type, iface) {
@@ -717,13 +694,9 @@ function getAllImplementsInterfaceNodes(type, iface) {
717
694
  }
718
695
 
719
696
  function getFieldNode(type, fieldName) {
720
- return getAllFieldNodes(type, fieldName)[0];
721
- }
722
-
723
- function getAllFieldNodes(type, fieldName) {
724
- return getAllSubNodes(type, function (typeNode) {
697
+ return (0, _find.default)(getAllSubNodes(type, function (typeNode) {
725
698
  return typeNode.fields;
726
- }).filter(function (fieldNode) {
699
+ }), function (fieldNode) {
727
700
  return fieldNode.name.value === fieldName;
728
701
  });
729
702
  }
@@ -797,12 +770,4 @@ function getUnionMemberTypeNodes(union, typeName) {
797
770
  }).filter(function (typeNode) {
798
771
  return typeNode.name.value === typeName;
799
772
  });
800
- }
801
-
802
- function getEnumValueNodes(enumType, valueName) {
803
- return getAllSubNodes(enumType, function (enumNode) {
804
- return enumNode.values;
805
- }).filter(function (valueNode) {
806
- return valueNode.name.value === valueName;
807
- });
808
773
  }
@@ -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,6 +7,10 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
+ import find from '../polyfills/find';
11
+ import flatMap from '../polyfills/flatMap';
12
+ import objectValues from '../polyfills/objectValues';
13
+ import objectEntries from '../polyfills/objectEntries';
10
14
  import {
11
15
  isObjectType,
12
16
  isInterfaceType,
@@ -28,17 +32,13 @@ import type {
28
32
  import { isDirective } from './directives';
29
33
  import type { GraphQLDirective } from './directives';
30
34
  import { isIntrospectionType } from './introspection';
31
- import { isSchema } from './schema';
35
+ import { assertSchema } from './schema';
32
36
  import type { GraphQLSchema } from './schema';
33
37
  import inspect from '../jsutils/inspect';
34
- import find from '../jsutils/find';
35
- import invariant from '../jsutils/invariant';
36
- import objectValues from '../jsutils/objectValues';
37
38
  import { GraphQLError } from '../error/GraphQLError';
38
39
  import type {
39
40
  ASTNode,
40
41
  FieldDefinitionNode,
41
- EnumValueDefinitionNode,
42
42
  InputValueDefinitionNode,
43
43
  NamedTypeNode,
44
44
  TypeNode,
@@ -57,10 +57,7 @@ export function validateSchema(
57
57
  schema: GraphQLSchema,
58
58
  ): $ReadOnlyArray<GraphQLError> {
59
59
  // First check to ensure the provided value is in fact a GraphQLSchema.
60
- invariant(
61
- isSchema(schema),
62
- `Expected ${inspect(schema)} to be a GraphQL schema.`,
63
- );
60
+ assertSchema(schema);
64
61
 
65
62
  // If this Schema has already been validated, return the previous results.
66
63
  if (schema.__validationErrors) {
@@ -104,7 +101,7 @@ class SchemaValidationContext {
104
101
  message: string,
105
102
  nodes?: $ReadOnlyArray<?ASTNode> | ?ASTNode,
106
103
  ): void {
107
- const _nodes = (Array.isArray(nodes) ? nodes : [nodes]).filter(Boolean);
104
+ const _nodes = Array.isArray(nodes) ? nodes.filter(Boolean) : nodes;
108
105
  this.addError(new GraphQLError(message, _nodes));
109
106
  }
110
107
 
@@ -284,16 +281,6 @@ function validateFields(
284
281
  // Ensure they are named correctly.
285
282
  validateName(context, field);
286
283
 
287
- // Ensure they were defined at most once.
288
- const fieldNodes = getAllFieldNodes(type, field.name);
289
- if (fieldNodes.length > 1) {
290
- context.reportError(
291
- `Field ${type.name}.${field.name} can only be defined once.`,
292
- fieldNodes,
293
- );
294
- continue;
295
- }
296
-
297
284
  // Ensure the type is an output type
298
285
  if (!isOutputType(field.type)) {
299
286
  context.reportError(
@@ -369,9 +356,8 @@ function validateObjectImplementsInterface(
369
356
  const ifaceFieldMap = iface.getFields();
370
357
 
371
358
  // Assert each interface field is implemented.
372
- for (const fieldName of Object.keys(ifaceFieldMap)) {
359
+ for (const [fieldName, ifaceField] of objectEntries(ifaceFieldMap)) {
373
360
  const objectField = objectFieldMap[fieldName];
374
- const ifaceField = ifaceFieldMap[fieldName];
375
361
 
376
362
  // Assert interface field exists on object.
377
363
  if (!objectField) {
@@ -503,15 +489,6 @@ function validateEnumValues(
503
489
  for (const enumValue of enumValues) {
504
490
  const valueName = enumValue.name;
505
491
 
506
- // Ensure no duplicates.
507
- const allNodes = getEnumValueNodes(enumType, valueName);
508
- if (allNodes && allNodes.length > 1) {
509
- context.reportError(
510
- `Enum type ${enumType.name} can include value ${valueName} only once.`,
511
- allNodes,
512
- );
513
- }
514
-
515
492
  // Ensure valid name.
516
493
  validateName(context, enumValue);
517
494
  if (valueName === 'true' || valueName === 'false' || valueName === 'null') {
@@ -541,8 +518,6 @@ function validateInputFields(
541
518
  // Ensure they are named correctly.
542
519
  validateName(context, field);
543
520
 
544
- // TODO: Ensure they are unique per field.
545
-
546
521
  // Ensure the type is an input type
547
522
  if (!isInputType(field.type)) {
548
523
  context.reportError(
@@ -574,16 +549,7 @@ function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
574
549
  object: SDLDefinedObject<T, K>,
575
550
  getter: (T | K) => ?(L | $ReadOnlyArray<L>),
576
551
  ): $ReadOnlyArray<L> {
577
- let result = [];
578
- for (const astNode of getAllNodes(object)) {
579
- if (astNode) {
580
- const subNodes = getter(astNode);
581
- if (subNodes) {
582
- result = result.concat(subNodes);
583
- }
584
- }
585
- }
586
- return result;
552
+ return flatMap(getAllNodes(object), item => getter(item) || []);
587
553
  }
588
554
 
589
555
  function getImplementsInterfaceNode(
@@ -606,14 +572,8 @@ function getFieldNode(
606
572
  type: GraphQLObjectType | GraphQLInterfaceType,
607
573
  fieldName: string,
608
574
  ): ?FieldDefinitionNode {
609
- return getAllFieldNodes(type, fieldName)[0];
610
- }
611
-
612
- function getAllFieldNodes(
613
- type: GraphQLObjectType | GraphQLInterfaceType,
614
- fieldName: string,
615
- ): $ReadOnlyArray<FieldDefinitionNode> {
616
- return getAllSubNodes(type, typeNode => typeNode.fields).filter(
575
+ return find(
576
+ getAllSubNodes(type, typeNode => typeNode.fields),
617
577
  fieldNode => fieldNode.name.value === fieldName,
618
578
  );
619
579
  }
@@ -686,12 +646,3 @@ function getUnionMemberTypeNodes(
686
646
  typeNode => typeNode.name.value === typeName,
687
647
  );
688
648
  }
689
-
690
- function getEnumValueNodes(
691
- enumType: GraphQLEnumType,
692
- valueName: string,
693
- ): ?$ReadOnlyArray<EnumValueDefinitionNode> {
694
- return getAllSubNodes(enumType, enumNode => enumNode.values).filter(
695
- valueNode => valueNode.name.value === valueName,
696
- );
697
- }