graphql 0.12.3 → 0.13.2

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 (412) hide show
  1. package/error/GraphQLError.js +2 -3
  2. package/error/GraphQLError.js.flow +3 -4
  3. package/{module/error/GraphQLError.js → error/GraphQLError.mjs} +2 -3
  4. package/error/formatError.js +1 -1
  5. package/error/formatError.js.flow +1 -1
  6. package/{module/error/formatError.js → error/formatError.mjs} +1 -1
  7. package/error/index.js.flow +1 -1
  8. package/{module/error/index.js → error/index.mjs} +1 -1
  9. package/error/locatedError.js +2 -1
  10. package/error/locatedError.js.flow +2 -1
  11. package/{module/error/locatedError.js → error/locatedError.mjs} +2 -1
  12. package/error/printError.js +1 -1
  13. package/error/printError.js.flow +1 -1
  14. package/{module/error/printError.js → error/printError.mjs} +1 -1
  15. package/error/syntaxError.js +1 -1
  16. package/error/syntaxError.js.flow +1 -1
  17. package/{module/error/syntaxError.js → error/syntaxError.mjs} +1 -1
  18. package/execution/execute.js +70 -90
  19. package/execution/execute.js.flow +83 -106
  20. package/{module/execution/execute.js → execution/execute.mjs} +53 -81
  21. package/execution/index.js.flow +1 -1
  22. package/{module/execution/index.js → execution/index.mjs} +1 -1
  23. package/execution/values.js +2 -6
  24. package/execution/values.js.flow +6 -7
  25. package/{module/execution/values.js → execution/values.mjs} +2 -2
  26. package/graphql.js +1 -1
  27. package/graphql.js.flow +3 -2
  28. package/{module/graphql.js → graphql.mjs} +1 -1
  29. package/index.js +24 -6
  30. package/index.js.flow +16 -2
  31. package/{module/index.js → index.mjs} +10 -2
  32. package/jsutils/MaybePromise.js +1 -0
  33. package/{module/jsutils/ObjMap.js.flow → jsutils/MaybePromise.js.flow} +2 -2
  34. package/{module/jsutils/ObjMap.js → jsutils/MaybePromise.mjs} +0 -0
  35. package/jsutils/ObjMap.js.flow +1 -1
  36. package/{module/language/ast.js → jsutils/ObjMap.mjs} +0 -0
  37. package/jsutils/dedent.js +23 -18
  38. package/jsutils/dedent.js.flow +21 -20
  39. package/jsutils/dedent.mjs +50 -0
  40. package/jsutils/find.js +1 -1
  41. package/jsutils/find.js.flow +1 -1
  42. package/{module/jsutils/find.js → jsutils/find.mjs} +1 -1
  43. package/jsutils/instanceOf.js +17 -16
  44. package/jsutils/instanceOf.js.flow +21 -15
  45. package/jsutils/instanceOf.mjs +31 -0
  46. package/jsutils/invariant.js +1 -1
  47. package/jsutils/invariant.js.flow +1 -1
  48. package/{module/jsutils/invariant.js → jsutils/invariant.mjs} +1 -1
  49. package/jsutils/isInvalid.js +1 -1
  50. package/jsutils/isInvalid.js.flow +1 -1
  51. package/{module/jsutils/isInvalid.js → jsutils/isInvalid.mjs} +1 -1
  52. package/jsutils/isNullish.js +1 -1
  53. package/jsutils/isNullish.js.flow +1 -1
  54. package/{module/jsutils/isNullish.js → jsutils/isNullish.mjs} +1 -1
  55. package/jsutils/isPromise.js +24 -0
  56. package/jsutils/isPromise.js.flow +20 -0
  57. package/jsutils/isPromise.mjs +18 -0
  58. package/jsutils/keyMap.js +1 -1
  59. package/jsutils/keyMap.js.flow +1 -1
  60. package/{module/jsutils/keyMap.js → jsutils/keyMap.mjs} +1 -1
  61. package/jsutils/keyValMap.js +1 -1
  62. package/jsutils/keyValMap.js.flow +1 -1
  63. package/{module/jsutils/keyValMap.js → jsutils/keyValMap.mjs} +1 -1
  64. package/jsutils/memoize3.js +48 -0
  65. package/jsutils/memoize3.js.flow +44 -0
  66. package/jsutils/memoize3.mjs +42 -0
  67. package/jsutils/objectValues.js +24 -0
  68. package/jsutils/objectValues.js.flow +18 -0
  69. package/jsutils/objectValues.mjs +19 -0
  70. package/jsutils/orList.js +1 -1
  71. package/jsutils/orList.js.flow +1 -1
  72. package/{module/jsutils/orList.js → jsutils/orList.mjs} +1 -1
  73. package/jsutils/promiseForObject.js +34 -0
  74. package/jsutils/promiseForObject.js.flow +30 -0
  75. package/jsutils/promiseForObject.mjs +28 -0
  76. package/jsutils/promiseReduce.js +34 -0
  77. package/jsutils/promiseReduce.js.flow +32 -0
  78. package/jsutils/promiseReduce.mjs +26 -0
  79. package/jsutils/quotedOrList.js +1 -1
  80. package/jsutils/quotedOrList.js.flow +1 -1
  81. package/{module/jsutils/quotedOrList.js → jsutils/quotedOrList.mjs} +1 -1
  82. package/jsutils/suggestionList.js +1 -1
  83. package/jsutils/suggestionList.js.flow +1 -1
  84. package/{module/jsutils/suggestionList.js → jsutils/suggestionList.mjs} +1 -1
  85. package/language/ast.js.flow +3 -30
  86. package/language/ast.mjs +0 -0
  87. package/language/blockStringValue.js +1 -1
  88. package/language/blockStringValue.js.flow +1 -1
  89. package/{module/language/blockStringValue.js → language/blockStringValue.mjs} +1 -1
  90. package/language/directiveLocation.js +3 -3
  91. package/language/directiveLocation.js.flow +4 -4
  92. package/{module/language/directiveLocation.js → language/directiveLocation.mjs} +3 -3
  93. package/language/index.js +10 -10
  94. package/language/index.js.flow +5 -4
  95. package/{module/language/index.js → language/index.mjs} +3 -3
  96. package/language/kinds.js +70 -71
  97. package/language/kinds.js.flow +71 -71
  98. package/language/kinds.mjs +79 -0
  99. package/language/lexer.js +73 -87
  100. package/language/lexer.js.flow +87 -93
  101. package/{module/language/lexer.js → language/lexer.mjs} +73 -87
  102. package/language/location.js +1 -1
  103. package/language/location.js.flow +1 -1
  104. package/{module/language/location.js → language/location.mjs} +1 -1
  105. package/language/parser.js +68 -58
  106. package/language/parser.js.flow +104 -110
  107. package/{module/language/parser.js → language/parser.mjs} +69 -59
  108. package/language/printer.js +52 -55
  109. package/language/printer.js.flow +74 -120
  110. package/{module/language/printer.js → language/printer.mjs} +52 -55
  111. package/language/source.js +1 -1
  112. package/language/source.js.flow +1 -1
  113. package/{module/language/source.js → language/source.mjs} +1 -1
  114. package/language/visitor.js +1 -1
  115. package/language/visitor.js.flow +1 -1
  116. package/{module/language/visitor.js → language/visitor.mjs} +1 -1
  117. package/package.json +4 -9
  118. package/subscription/asyncIteratorReject.js +1 -1
  119. package/subscription/asyncIteratorReject.js.flow +1 -1
  120. package/{module/subscription/asyncIteratorReject.js → subscription/asyncIteratorReject.mjs} +1 -1
  121. package/subscription/index.js.flow +1 -1
  122. package/{module/subscription/index.js → subscription/index.mjs} +1 -1
  123. package/subscription/mapAsyncIterator.js +3 -1
  124. package/subscription/mapAsyncIterator.js.flow +7 -4
  125. package/{module/subscription/mapAsyncIterator.js → subscription/mapAsyncIterator.mjs} +4 -1
  126. package/subscription/subscribe.js +1 -1
  127. package/subscription/subscribe.js.flow +1 -1
  128. package/{module/subscription/subscribe.js → subscription/subscribe.mjs} +1 -1
  129. package/type/definition.js +76 -10
  130. package/type/definition.js.flow +105 -13
  131. package/{module/type/definition.js → type/definition.mjs} +72 -4
  132. package/type/directives.js +4 -4
  133. package/type/directives.js.flow +3 -3
  134. package/{module/type/directives.js → type/directives.mjs} +8 -8
  135. package/type/index.js +2 -5
  136. package/type/index.js.flow +6 -5
  137. package/{module/type/index.js → type/index.mjs} +3 -5
  138. package/type/introspection.js +34 -41
  139. package/type/introspection.js.flow +7 -10
  140. package/{module/type/introspection.js → type/introspection.mjs} +6 -15
  141. package/type/scalars.js +6 -10
  142. package/type/scalars.js.flow +2 -2
  143. package/{module/type/scalars.js → type/scalars.mjs} +2 -2
  144. package/type/schema.js +39 -15
  145. package/type/schema.js.flow +73 -22
  146. package/{module/type/schema.js → type/schema.mjs} +37 -16
  147. package/type/validate.js +33 -30
  148. package/type/validate.js.flow +40 -37
  149. package/{module/type/validate.js → type/validate.mjs} +30 -30
  150. package/utilities/TypeInfo.js +23 -27
  151. package/utilities/TypeInfo.js.flow +2 -2
  152. package/{module/utilities/TypeInfo.js → utilities/TypeInfo.mjs} +2 -2
  153. package/utilities/assertValidName.js +2 -6
  154. package/utilities/assertValidName.js.flow +2 -10
  155. package/{module/utilities/assertValidName.js → utilities/assertValidName.mjs} +2 -6
  156. package/utilities/astFromValue.js +37 -37
  157. package/utilities/astFromValue.js.flow +36 -44
  158. package/{module/utilities/astFromValue.js → utilities/astFromValue.mjs} +26 -25
  159. package/utilities/buildASTSchema.js +65 -82
  160. package/utilities/buildASTSchema.js.flow +52 -59
  161. package/{module/utilities/buildASTSchema.js → utilities/buildASTSchema.mjs} +48 -62
  162. package/utilities/buildClientSchema.js +12 -15
  163. package/utilities/buildClientSchema.js.flow +7 -11
  164. package/{module/utilities/buildClientSchema.js → utilities/buildClientSchema.mjs} +4 -5
  165. package/utilities/coerceValue.js +1 -1
  166. package/utilities/coerceValue.js.flow +1 -1
  167. package/{module/utilities/coerceValue.js → utilities/coerceValue.mjs} +1 -1
  168. package/utilities/concatAST.js +1 -1
  169. package/utilities/concatAST.js.flow +1 -1
  170. package/{module/utilities/concatAST.js → utilities/concatAST.mjs} +1 -1
  171. package/utilities/extendSchema.js +91 -77
  172. package/utilities/extendSchema.js.flow +93 -68
  173. package/{module/utilities/extendSchema.js → utilities/extendSchema.mjs} +65 -52
  174. package/utilities/findBreakingChanges.js +1 -1
  175. package/utilities/findBreakingChanges.js.flow +1 -1
  176. package/{module/utilities/findBreakingChanges.js → utilities/findBreakingChanges.mjs} +1 -1
  177. package/utilities/findDeprecatedUsages.js +1 -1
  178. package/utilities/findDeprecatedUsages.js.flow +1 -1
  179. package/{module/utilities/findDeprecatedUsages.js → utilities/findDeprecatedUsages.mjs} +1 -1
  180. package/utilities/getOperationAST.js +2 -2
  181. package/utilities/getOperationAST.js.flow +3 -3
  182. package/{module/utilities/getOperationAST.js → utilities/getOperationAST.mjs} +3 -3
  183. package/utilities/index.js +30 -0
  184. package/utilities/index.js.flow +10 -3
  185. package/{module/utilities/index.js → utilities/index.mjs} +10 -3
  186. package/utilities/introspectionFromSchema.js +43 -0
  187. package/utilities/introspectionFromSchema.js.flow +37 -0
  188. package/utilities/introspectionFromSchema.mjs +31 -0
  189. package/utilities/introspectionQuery.js +1 -1
  190. package/utilities/introspectionQuery.js.flow +1 -1
  191. package/{module/utilities/introspectionQuery.js → utilities/introspectionQuery.mjs} +1 -1
  192. package/utilities/isValidJSValue.js +1 -1
  193. package/utilities/isValidJSValue.js.flow +1 -1
  194. package/{module/utilities/isValidJSValue.js → utilities/isValidJSValue.mjs} +1 -1
  195. package/utilities/isValidLiteralValue.js +8 -4
  196. package/utilities/isValidLiteralValue.js.flow +4 -4
  197. package/{module/utilities/isValidLiteralValue.js → utilities/isValidLiteralValue.mjs} +4 -4
  198. package/utilities/lexicographicSortSchema.js +243 -0
  199. package/utilities/lexicographicSortSchema.js.flow +198 -0
  200. package/utilities/lexicographicSortSchema.mjs +225 -0
  201. package/utilities/schemaPrinter.js +31 -29
  202. package/utilities/schemaPrinter.js.flow +28 -15
  203. package/{module/utilities/schemaPrinter.js → utilities/schemaPrinter.mjs} +21 -20
  204. package/utilities/separateOperations.js +1 -1
  205. package/utilities/separateOperations.js.flow +1 -1
  206. package/{module/utilities/separateOperations.js → utilities/separateOperations.mjs} +1 -1
  207. package/utilities/typeComparators.js +7 -10
  208. package/utilities/typeComparators.js.flow +7 -10
  209. package/{module/utilities/typeComparators.js → utilities/typeComparators.mjs} +7 -10
  210. package/utilities/typeFromAST.js +7 -11
  211. package/utilities/typeFromAST.js.flow +3 -3
  212. package/{module/utilities/typeFromAST.js → utilities/typeFromAST.mjs} +3 -3
  213. package/utilities/valueFromAST.js +26 -28
  214. package/utilities/valueFromAST.js.flow +14 -23
  215. package/{module/utilities/valueFromAST.js → utilities/valueFromAST.mjs} +9 -10
  216. package/utilities/valueFromASTUntyped.js +17 -22
  217. package/utilities/valueFromASTUntyped.js.flow +6 -7
  218. package/{module/utilities/valueFromASTUntyped.js → utilities/valueFromASTUntyped.mjs} +6 -7
  219. package/validation/ValidationContext.js +184 -0
  220. package/{module/validation/validate.js.flow → validation/ValidationContext.js.flow} +4 -60
  221. package/{module/validation/validate.js → validation/ValidationContext.mjs} +15 -57
  222. package/validation/index.js +12 -7
  223. package/validation/index.js.flow +6 -2
  224. package/{module/validation/index.js → validation/index.mjs} +6 -2
  225. package/validation/rules/ExecutableDefinitions.js +3 -3
  226. package/validation/rules/ExecutableDefinitions.js.flow +6 -10
  227. package/{module/validation/rules/ExecutableDefinitions.js → validation/rules/ExecutableDefinitions.mjs} +4 -4
  228. package/validation/rules/FieldsOnCorrectType.js +1 -1
  229. package/validation/rules/FieldsOnCorrectType.js.flow +2 -2
  230. package/{module/validation/rules/FieldsOnCorrectType.js → validation/rules/FieldsOnCorrectType.mjs} +1 -1
  231. package/validation/rules/FragmentsOnCompositeTypes.js +1 -1
  232. package/validation/rules/FragmentsOnCompositeTypes.js.flow +2 -2
  233. package/{module/validation/rules/FragmentsOnCompositeTypes.js → validation/rules/FragmentsOnCompositeTypes.mjs} +1 -1
  234. package/validation/rules/KnownArgumentNames.js +3 -3
  235. package/validation/rules/KnownArgumentNames.js.flow +6 -8
  236. package/{module/validation/rules/KnownArgumentNames.js → validation/rules/KnownArgumentNames.mjs} +4 -4
  237. package/validation/rules/KnownDirectives.js +23 -27
  238. package/validation/rules/KnownDirectives.js.flow +3 -3
  239. package/{module/validation/rules/KnownDirectives.js → validation/rules/KnownDirectives.mjs} +2 -2
  240. package/validation/rules/KnownFragmentNames.js +1 -1
  241. package/validation/rules/KnownFragmentNames.js.flow +2 -2
  242. package/{module/validation/rules/KnownFragmentNames.js → validation/rules/KnownFragmentNames.mjs} +1 -1
  243. package/validation/rules/KnownTypeNames.js +1 -1
  244. package/validation/rules/KnownTypeNames.js.flow +2 -2
  245. package/{module/validation/rules/KnownTypeNames.js → validation/rules/KnownTypeNames.mjs} +1 -1
  246. package/validation/rules/LoneAnonymousOperation.js +2 -2
  247. package/validation/rules/LoneAnonymousOperation.js.flow +4 -4
  248. package/{module/validation/rules/LoneAnonymousOperation.js → validation/rules/LoneAnonymousOperation.mjs} +3 -3
  249. package/validation/rules/NoFragmentCycles.js +1 -1
  250. package/validation/rules/NoFragmentCycles.js.flow +2 -2
  251. package/{module/validation/rules/NoFragmentCycles.js → validation/rules/NoFragmentCycles.mjs} +1 -1
  252. package/validation/rules/NoUndefinedVariables.js +1 -1
  253. package/validation/rules/NoUndefinedVariables.js.flow +2 -2
  254. package/{module/validation/rules/NoUndefinedVariables.js → validation/rules/NoUndefinedVariables.mjs} +1 -1
  255. package/validation/rules/NoUnusedFragments.js +1 -1
  256. package/validation/rules/NoUnusedFragments.js.flow +2 -2
  257. package/{module/validation/rules/NoUnusedFragments.js → validation/rules/NoUnusedFragments.mjs} +1 -1
  258. package/validation/rules/NoUnusedVariables.js +1 -1
  259. package/validation/rules/NoUnusedVariables.js.flow +2 -2
  260. package/{module/validation/rules/NoUnusedVariables.js → validation/rules/NoUnusedVariables.mjs} +1 -1
  261. package/validation/rules/OverlappingFieldsCanBeMerged.js +4 -8
  262. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +3 -3
  263. package/{module/validation/rules/OverlappingFieldsCanBeMerged.js → validation/rules/OverlappingFieldsCanBeMerged.mjs} +2 -2
  264. package/validation/rules/PossibleFragmentSpreads.js +1 -1
  265. package/validation/rules/PossibleFragmentSpreads.js.flow +2 -2
  266. package/{module/validation/rules/PossibleFragmentSpreads.js → validation/rules/PossibleFragmentSpreads.mjs} +1 -1
  267. package/validation/rules/ProvidedNonNullArguments.js +1 -1
  268. package/validation/rules/ProvidedNonNullArguments.js.flow +2 -2
  269. package/{module/validation/rules/ProvidedNonNullArguments.js → validation/rules/ProvidedNonNullArguments.mjs} +1 -1
  270. package/validation/rules/ScalarLeafs.js +1 -1
  271. package/validation/rules/ScalarLeafs.js.flow +2 -2
  272. package/{module/validation/rules/ScalarLeafs.js → validation/rules/ScalarLeafs.mjs} +1 -1
  273. package/validation/rules/SingleFieldSubscriptions.js +1 -1
  274. package/validation/rules/SingleFieldSubscriptions.js.flow +2 -2
  275. package/{module/validation/rules/SingleFieldSubscriptions.js → validation/rules/SingleFieldSubscriptions.mjs} +1 -1
  276. package/validation/rules/UniqueArgumentNames.js +1 -1
  277. package/validation/rules/UniqueArgumentNames.js.flow +2 -2
  278. package/{module/validation/rules/UniqueArgumentNames.js → validation/rules/UniqueArgumentNames.mjs} +1 -1
  279. package/validation/rules/UniqueDirectivesPerLocation.js +1 -1
  280. package/validation/rules/UniqueDirectivesPerLocation.js.flow +2 -2
  281. package/{module/validation/rules/UniqueDirectivesPerLocation.js → validation/rules/UniqueDirectivesPerLocation.mjs} +1 -1
  282. package/validation/rules/UniqueFragmentNames.js +1 -1
  283. package/validation/rules/UniqueFragmentNames.js.flow +2 -2
  284. package/{module/validation/rules/UniqueFragmentNames.js → validation/rules/UniqueFragmentNames.mjs} +1 -1
  285. package/validation/rules/UniqueInputFieldNames.js +1 -1
  286. package/validation/rules/UniqueInputFieldNames.js.flow +2 -2
  287. package/{module/validation/rules/UniqueInputFieldNames.js → validation/rules/UniqueInputFieldNames.mjs} +1 -1
  288. package/validation/rules/UniqueOperationNames.js +1 -1
  289. package/validation/rules/UniqueOperationNames.js.flow +2 -2
  290. package/{module/validation/rules/UniqueOperationNames.js → validation/rules/UniqueOperationNames.mjs} +1 -1
  291. package/validation/rules/UniqueVariableNames.js +1 -1
  292. package/validation/rules/UniqueVariableNames.js.flow +2 -2
  293. package/{module/validation/rules/UniqueVariableNames.js → validation/rules/UniqueVariableNames.mjs} +1 -1
  294. package/validation/rules/ValuesOfCorrectType.js +1 -1
  295. package/validation/rules/ValuesOfCorrectType.js.flow +2 -2
  296. package/{module/validation/rules/ValuesOfCorrectType.js → validation/rules/ValuesOfCorrectType.mjs} +1 -1
  297. package/validation/rules/VariablesAreInputTypes.js +1 -1
  298. package/validation/rules/VariablesAreInputTypes.js.flow +2 -2
  299. package/{module/validation/rules/VariablesAreInputTypes.js → validation/rules/VariablesAreInputTypes.mjs} +1 -1
  300. package/validation/rules/VariablesDefaultValueAllowed.js +1 -1
  301. package/validation/rules/VariablesDefaultValueAllowed.js.flow +2 -2
  302. package/{module/validation/rules/VariablesDefaultValueAllowed.js → validation/rules/VariablesDefaultValueAllowed.mjs} +1 -1
  303. package/validation/rules/VariablesInAllowedPosition.js +9 -11
  304. package/validation/rules/VariablesInAllowedPosition.js.flow +3 -4
  305. package/{module/validation/rules/VariablesInAllowedPosition.js → validation/rules/VariablesInAllowedPosition.mjs} +2 -3
  306. package/validation/specifiedRules.js +1 -1
  307. package/validation/specifiedRules.js.flow +2 -2
  308. package/{module/validation/specifiedRules.js → validation/specifiedRules.mjs} +1 -1
  309. package/validation/validate.js +14 -175
  310. package/validation/validate.js.flow +3 -209
  311. package/validation/validate.mjs +57 -0
  312. package/module/error/GraphQLError.js.flow +0 -209
  313. package/module/error/formatError.js.flow +0 -34
  314. package/module/error/index.js.flow +0 -16
  315. package/module/error/locatedError.js.flow +0 -37
  316. package/module/error/printError.js.flow +0 -82
  317. package/module/error/syntaxError.js.flow +0 -25
  318. package/module/execution/execute.js.flow +0 -1375
  319. package/module/execution/index.js.flow +0 -13
  320. package/module/execution/values.js.flow +0 -206
  321. package/module/graphql.js.flow +0 -202
  322. package/module/index.js.flow +0 -389
  323. package/module/jsutils/dedent.js +0 -45
  324. package/module/jsutils/dedent.js.flow +0 -49
  325. package/module/jsutils/find.js.flow +0 -19
  326. package/module/jsutils/instanceOf.js +0 -27
  327. package/module/jsutils/instanceOf.js.flow +0 -44
  328. package/module/jsutils/invariant.js.flow +0 -15
  329. package/module/jsutils/isInvalid.js.flow +0 -15
  330. package/module/jsutils/isNullish.js.flow +0 -15
  331. package/module/jsutils/keyMap.js.flow +0 -43
  332. package/module/jsutils/keyValMap.js.flow +0 -38
  333. package/module/jsutils/orList.js.flow +0 -24
  334. package/module/jsutils/quotedOrList.js.flow +0 -17
  335. package/module/jsutils/suggestionList.js.flow +0 -94
  336. package/module/language/ast.js.flow +0 -594
  337. package/module/language/blockStringValue.js.flow +0 -64
  338. package/module/language/directiveLocation.js.flow +0 -39
  339. package/module/language/index.js.flow +0 -84
  340. package/module/language/kinds.js +0 -80
  341. package/module/language/kinds.js.flow +0 -80
  342. package/module/language/lexer.js.flow +0 -762
  343. package/module/language/location.js.flow +0 -34
  344. package/module/language/parser.js.flow +0 -1537
  345. package/module/language/printer.js.flow +0 -311
  346. package/module/language/source.js.flow +0 -43
  347. package/module/language/visitor.js.flow +0 -476
  348. package/module/subscription/asyncIteratorReject.js.flow +0 -41
  349. package/module/subscription/index.js.flow +0 -10
  350. package/module/subscription/mapAsyncIterator.js.flow +0 -78
  351. package/module/subscription/subscribe.js.flow +0 -288
  352. package/module/type/definition.js.flow +0 -1225
  353. package/module/type/directives.js.flow +0 -168
  354. package/module/type/index.js.flow +0 -156
  355. package/module/type/introspection.js.flow +0 -482
  356. package/module/type/scalars.js.flow +0 -158
  357. package/module/type/schema.js.flow +0 -271
  358. package/module/type/validate.js.flow +0 -723
  359. package/module/type/wrappers.js +0 -80
  360. package/module/type/wrappers.js.flow +0 -91
  361. package/module/utilities/TypeInfo.js.flow +0 -296
  362. package/module/utilities/assertValidName.js.flow +0 -56
  363. package/module/utilities/astFromValue.js.flow +0 -159
  364. package/module/utilities/buildASTSchema.js.flow +0 -518
  365. package/module/utilities/buildClientSchema.js.flow +0 -418
  366. package/module/utilities/coerceValue.js.flow +0 -257
  367. package/module/utilities/concatAST.js.flow +0 -29
  368. package/module/utilities/extendSchema.js.flow +0 -374
  369. package/module/utilities/findBreakingChanges.js.flow +0 -851
  370. package/module/utilities/findDeprecatedUsages.js.flow +0 -68
  371. package/module/utilities/getOperationAST.js.flow +0 -40
  372. package/module/utilities/index.js.flow +0 -111
  373. package/module/utilities/introspectionQuery.js.flow +0 -271
  374. package/module/utilities/isValidJSValue.js.flow +0 -22
  375. package/module/utilities/isValidLiteralValue.js.flow +0 -36
  376. package/module/utilities/schemaPrinter.js.flow +0 -402
  377. package/module/utilities/separateOperations.js.flow +0 -100
  378. package/module/utilities/typeComparators.js.flow +0 -135
  379. package/module/utilities/typeFromAST.js.flow +0 -56
  380. package/module/utilities/valueFromAST.js.flow +0 -184
  381. package/module/utilities/valueFromASTUntyped.js.flow +0 -64
  382. package/module/validation/index.js.flow +0 -138
  383. package/module/validation/rules/ExecutableDefinitions.js.flow +0 -52
  384. package/module/validation/rules/FieldsOnCorrectType.js.flow +0 -144
  385. package/module/validation/rules/FragmentsOnCompositeTypes.js.flow +0 -74
  386. package/module/validation/rules/KnownArgumentNames.js.flow +0 -98
  387. package/module/validation/rules/KnownDirectives.js.flow +0 -116
  388. package/module/validation/rules/KnownFragmentNames.js.flow +0 -36
  389. package/module/validation/rules/KnownTypeNames.js.flow +0 -59
  390. package/module/validation/rules/LoneAnonymousOperation.js.flow +0 -41
  391. package/module/validation/rules/NoFragmentCycles.js.flow +0 -85
  392. package/module/validation/rules/NoUndefinedVariables.js.flow +0 -57
  393. package/module/validation/rules/NoUnusedFragments.js.flow +0 -59
  394. package/module/validation/rules/NoUnusedVariables.js.flow +0 -62
  395. package/module/validation/rules/OverlappingFieldsCanBeMerged.js.flow +0 -847
  396. package/module/validation/rules/PossibleFragmentSpreads.js.flow +0 -94
  397. package/module/validation/rules/ProvidedNonNullArguments.js.flow +0 -105
  398. package/module/validation/rules/ScalarLeafs.js.flow +0 -69
  399. package/module/validation/rules/SingleFieldSubscriptions.js.flow +0 -44
  400. package/module/validation/rules/UniqueArgumentNames.js.flow +0 -48
  401. package/module/validation/rules/UniqueDirectivesPerLocation.js.flow +0 -57
  402. package/module/validation/rules/UniqueFragmentNames.js.flow +0 -42
  403. package/module/validation/rules/UniqueInputFieldNames.js.flow +0 -53
  404. package/module/validation/rules/UniqueOperationNames.js.flow +0 -44
  405. package/module/validation/rules/UniqueVariableNames.js.flow +0 -44
  406. package/module/validation/rules/ValuesOfCorrectType.js.flow +0 -218
  407. package/module/validation/rules/VariablesAreInputTypes.js.flow +0 -48
  408. package/module/validation/rules/VariablesDefaultValueAllowed.js.flow +0 -55
  409. package/module/validation/rules/VariablesInAllowedPosition.js.flow +0 -83
  410. package/module/validation/specifiedRules.js.flow +0 -127
  411. package/type/wrappers.js +0 -89
  412. package/type/wrappers.js.flow +0 -91
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @flow
7
+ * @flow strict
8
8
  */
9
9
 
10
10
  import { forEach, isCollection } from 'iterall';
@@ -12,10 +12,15 @@ import { GraphQLError, locatedError } from '../error';
12
12
  import invariant from '../jsutils/invariant';
13
13
  import isInvalid from '../jsutils/isInvalid';
14
14
  import isNullish from '../jsutils/isNullish';
15
+ import isPromise from '../jsutils/isPromise';
16
+ import memoize3 from '../jsutils/memoize3';
17
+ import promiseForObject from '../jsutils/promiseForObject';
18
+ import promiseReduce from '../jsutils/promiseReduce';
15
19
  import type { ObjMap } from '../jsutils/ObjMap';
20
+ import type { MaybePromise } from '../jsutils/MaybePromise';
16
21
 
17
22
  import { typeFromAST } from '../utilities/typeFromAST';
18
- import * as Kind from '../language/kinds';
23
+ import { Kind } from '../language/kinds';
19
24
  import {
20
25
  getVariableValues,
21
26
  getArgumentValues,
@@ -28,7 +33,6 @@ import {
28
33
  isListType,
29
34
  isNonNullType,
30
35
  } from '../type/definition';
31
- import type { GraphQLList } from '../type/wrappers';
32
36
  import type {
33
37
  GraphQLObjectType,
34
38
  GraphQLOutputType,
@@ -38,6 +42,7 @@ import type {
38
42
  GraphQLFieldResolver,
39
43
  GraphQLResolveInfo,
40
44
  ResponsePath,
45
+ GraphQLList,
41
46
  } from '../type/definition';
42
47
  import { GraphQLSchema } from '../type/schema';
43
48
  import {
@@ -133,7 +138,7 @@ export type ExecutionArgs = {|
133
138
  declare function execute(
134
139
  ExecutionArgs,
135
140
  ..._: []
136
- ): Promise<ExecutionResult> | ExecutionResult;
141
+ ): MaybePromise<ExecutionResult>;
137
142
  /* eslint-disable no-redeclare */
138
143
  declare function execute(
139
144
  schema: GraphQLSchema,
@@ -143,7 +148,7 @@ declare function execute(
143
148
  variableValues?: ?{ [variable: string]: mixed },
144
149
  operationName?: ?string,
145
150
  fieldResolver?: ?GraphQLFieldResolver<any, any>,
146
- ): Promise<ExecutionResult> | ExecutionResult;
151
+ ): MaybePromise<ExecutionResult>;
147
152
  export function execute(
148
153
  argsOrSchema,
149
154
  document,
@@ -222,11 +227,10 @@ function executeImpl(
222
227
  */
223
228
  function buildResponse(
224
229
  context: ExecutionContext,
225
- data: Promise<ObjMap<mixed> | null> | ObjMap<mixed> | null,
230
+ data: MaybePromise<ObjMap<mixed> | null>,
226
231
  ) {
227
- const promise = getPromise(data);
228
- if (promise) {
229
- return promise.then(resolved => buildResponse(context, resolved));
232
+ if (isPromise(data)) {
233
+ return data.then(resolved => buildResponse(context, resolved));
230
234
  }
231
235
  return context.errors.length === 0
232
236
  ? { data }
@@ -376,7 +380,7 @@ function executeOperation(
376
380
  exeContext: ExecutionContext,
377
381
  operation: OperationDefinitionNode,
378
382
  rootValue: mixed,
379
- ): Promise<ObjMap<mixed> | null> | ObjMap<mixed> | null {
383
+ ): MaybePromise<ObjMap<mixed> | null> {
380
384
  const type = getOperationRootType(exeContext.schema, operation);
381
385
  const fields = collectFields(
382
386
  exeContext,
@@ -398,9 +402,8 @@ function executeOperation(
398
402
  operation.operation === 'mutation'
399
403
  ? executeFieldsSerially(exeContext, type, rootValue, path, fields)
400
404
  : executeFields(exeContext, type, rootValue, path, fields);
401
- const promise = getPromise(result);
402
- if (promise) {
403
- return promise.then(undefined, error => {
405
+ if (isPromise(result)) {
406
+ return result.then(undefined, error => {
404
407
  exeContext.errors.push(error);
405
408
  return Promise.resolve(null);
406
409
  });
@@ -463,33 +466,32 @@ function executeFieldsSerially(
463
466
  sourceValue: mixed,
464
467
  path: ResponsePath | void,
465
468
  fields: ObjMap<Array<FieldNode>>,
466
- ): Promise<ObjMap<mixed>> {
467
- return Object.keys(fields).reduce(
468
- (prevPromise, responseName) =>
469
- prevPromise.then(results => {
470
- const fieldNodes = fields[responseName];
471
- const fieldPath = addPath(path, responseName);
472
- const result = resolveField(
473
- exeContext,
474
- parentType,
475
- sourceValue,
476
- fieldNodes,
477
- fieldPath,
478
- );
479
- if (result === undefined) {
480
- return results;
481
- }
482
- const promise = getPromise(result);
483
- if (promise) {
484
- return promise.then(resolvedResult => {
485
- results[responseName] = resolvedResult;
486
- return results;
487
- });
488
- }
489
- results[responseName] = result;
469
+ ): MaybePromise<ObjMap<mixed>> {
470
+ return promiseReduce(
471
+ Object.keys(fields),
472
+ (results, responseName) => {
473
+ const fieldNodes = fields[responseName];
474
+ const fieldPath = addPath(path, responseName);
475
+ const result = resolveField(
476
+ exeContext,
477
+ parentType,
478
+ sourceValue,
479
+ fieldNodes,
480
+ fieldPath,
481
+ );
482
+ if (result === undefined) {
490
483
  return results;
491
- }),
492
- Promise.resolve({}),
484
+ }
485
+ if (isPromise(result)) {
486
+ return result.then(resolvedResult => {
487
+ results[responseName] = resolvedResult;
488
+ return results;
489
+ });
490
+ }
491
+ results[responseName] = result;
492
+ return results;
493
+ },
494
+ Object.create(null),
493
495
  );
494
496
  }
495
497
 
@@ -503,7 +505,7 @@ function executeFields(
503
505
  sourceValue: mixed,
504
506
  path: ResponsePath | void,
505
507
  fields: ObjMap<Array<FieldNode>>,
506
- ): Promise<ObjMap<mixed>> | ObjMap<mixed> {
508
+ ): MaybePromise<ObjMap<mixed>> {
507
509
  let containsPromise = false;
508
510
 
509
511
  const finalResults = Object.keys(fields).reduce((results, responseName) => {
@@ -520,7 +522,7 @@ function executeFields(
520
522
  return results;
521
523
  }
522
524
  results[responseName] = result;
523
- if (getPromise(result)) {
525
+ if (!containsPromise && isPromise(result)) {
524
526
  containsPromise = true;
525
527
  }
526
528
  return results;
@@ -660,24 +662,6 @@ function doesFragmentConditionMatch(
660
662
  return false;
661
663
  }
662
664
 
663
- /**
664
- * This function transforms a JS object `ObjMap<Promise<T>>` into
665
- * a `Promise<ObjMap<T>>`
666
- *
667
- * This is akin to bluebird's `Promise.props`, but implemented only using
668
- * `Promise.all` so it will work with any implementation of ES6 promises.
669
- */
670
- function promiseForObject<T>(object: ObjMap<Promise<T>>): Promise<ObjMap<T>> {
671
- const keys = Object.keys(object);
672
- const valuesAndPromises = keys.map(name => object[name]);
673
- return Promise.all(valuesAndPromises).then(values =>
674
- values.reduce((resolvedObject, value, i) => {
675
- resolvedObject[keys[i]] = value;
676
- return resolvedObject;
677
- }, Object.create(null)),
678
- );
679
- }
680
-
681
665
  /**
682
666
  * Implements the logic to compute the key of a given field's entry
683
667
  */
@@ -697,7 +681,7 @@ function resolveField(
697
681
  source: mixed,
698
682
  fieldNodes: $ReadOnlyArray<FieldNode>,
699
683
  path: ResponsePath,
700
- ): mixed {
684
+ ): MaybePromise<mixed> {
701
685
  const fieldNode = fieldNodes[0];
702
686
  const fieldName = fieldNode.name.value;
703
687
 
@@ -786,8 +770,7 @@ export function resolveFieldValueOrError<TSource>(
786
770
  const context = exeContext.contextValue;
787
771
 
788
772
  const result = resolveFn(source, args, context, info);
789
- const promise = getPromise(result);
790
- return promise ? promise.then(undefined, asErrorInstance) : result;
773
+ return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
791
774
  } catch (error) {
792
775
  return asErrorInstance(error);
793
776
  }
@@ -808,7 +791,7 @@ function completeValueCatchingError(
808
791
  info: GraphQLResolveInfo,
809
792
  path: ResponsePath,
810
793
  result: mixed,
811
- ): mixed {
794
+ ): MaybePromise<mixed> {
812
795
  // If the field type is non-nullable, then it is resolved without any
813
796
  // protection from errors, however it still properly locates the error.
814
797
  if (isNonNullType(returnType)) {
@@ -833,13 +816,12 @@ function completeValueCatchingError(
833
816
  path,
834
817
  result,
835
818
  );
836
- const promise = getPromise(completed);
837
- if (promise) {
819
+ if (isPromise(completed)) {
838
820
  // If `completeValueWithLocatedError` returned a rejected promise, log
839
821
  // the rejection error and resolve to null.
840
822
  // Note: we don't rely on a `catch` method, but we do expect "thenable"
841
823
  // to take a second callback for the error case.
842
- return promise.then(undefined, error => {
824
+ return completed.then(undefined, error => {
843
825
  exeContext.errors.push(error);
844
826
  return Promise.resolve(null);
845
827
  });
@@ -862,7 +844,7 @@ function completeValueWithLocatedError(
862
844
  info: GraphQLResolveInfo,
863
845
  path: ResponsePath,
864
846
  result: mixed,
865
- ): mixed {
847
+ ): MaybePromise<mixed> {
866
848
  try {
867
849
  const completed = completeValue(
868
850
  exeContext,
@@ -872,9 +854,8 @@ function completeValueWithLocatedError(
872
854
  path,
873
855
  result,
874
856
  );
875
- const promise = getPromise(completed);
876
- if (promise) {
877
- return promise.then(undefined, error =>
857
+ if (isPromise(completed)) {
858
+ return completed.then(undefined, error =>
878
859
  Promise.reject(
879
860
  locatedError(
880
861
  asErrorInstance(error),
@@ -922,11 +903,10 @@ function completeValue(
922
903
  info: GraphQLResolveInfo,
923
904
  path: ResponsePath,
924
905
  result: mixed,
925
- ): mixed {
906
+ ): MaybePromise<mixed> {
926
907
  // If result is a Promise, apply-lift over completeValue.
927
- const promise = getPromise(result);
928
- if (promise) {
929
- return promise.then(resolved =>
908
+ if (isPromise(result)) {
909
+ return result.then(resolved =>
930
910
  completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
931
911
  );
932
912
  }
@@ -1025,7 +1005,7 @@ function completeListValue(
1025
1005
  info: GraphQLResolveInfo,
1026
1006
  path: ResponsePath,
1027
1007
  result: mixed,
1028
- ): mixed {
1008
+ ): MaybePromise<$ReadOnlyArray<mixed>> {
1029
1009
  invariant(
1030
1010
  isCollection(result),
1031
1011
  `Expected Iterable, but did not find one for field ${
@@ -1051,7 +1031,7 @@ function completeListValue(
1051
1031
  item,
1052
1032
  );
1053
1033
 
1054
- if (!containsPromise && getPromise(completedItem)) {
1034
+ if (!containsPromise && isPromise(completedItem)) {
1055
1035
  containsPromise = true;
1056
1036
  }
1057
1037
  completedResults.push(completedItem);
@@ -1087,14 +1067,13 @@ function completeAbstractValue(
1087
1067
  info: GraphQLResolveInfo,
1088
1068
  path: ResponsePath,
1089
1069
  result: mixed,
1090
- ): mixed {
1070
+ ): MaybePromise<ObjMap<mixed>> {
1091
1071
  const runtimeType = returnType.resolveType
1092
1072
  ? returnType.resolveType(result, exeContext.contextValue, info)
1093
1073
  : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
1094
1074
 
1095
- const promise = getPromise(runtimeType);
1096
- if (promise) {
1097
- return promise.then(resolvedRuntimeType =>
1075
+ if (isPromise(runtimeType)) {
1076
+ return runtimeType.then(resolvedRuntimeType =>
1098
1077
  completeObjectValue(
1099
1078
  exeContext,
1100
1079
  ensureValidRuntimeType(
@@ -1116,7 +1095,7 @@ function completeAbstractValue(
1116
1095
  return completeObjectValue(
1117
1096
  exeContext,
1118
1097
  ensureValidRuntimeType(
1119
- ((runtimeType: any): ?GraphQLObjectType | string),
1098
+ runtimeType,
1120
1099
  exeContext,
1121
1100
  returnType,
1122
1101
  fieldNodes,
@@ -1176,17 +1155,16 @@ function completeObjectValue(
1176
1155
  info: GraphQLResolveInfo,
1177
1156
  path: ResponsePath,
1178
1157
  result: mixed,
1179
- ): mixed {
1158
+ ): MaybePromise<ObjMap<mixed>> {
1180
1159
  // If there is an isTypeOf predicate function, call it with the
1181
1160
  // current result. If isTypeOf returns false, then raise an error rather
1182
1161
  // than continuing execution.
1183
1162
  if (returnType.isTypeOf) {
1184
1163
  const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
1185
1164
 
1186
- const promise = getPromise(isTypeOf);
1187
- if (promise) {
1188
- return promise.then(isTypeOfResult => {
1189
- if (!isTypeOfResult) {
1165
+ if (isPromise(isTypeOf)) {
1166
+ return isTypeOf.then(resolvedIsTypeOf => {
1167
+ if (!resolvedIsTypeOf) {
1190
1168
  throw invalidReturnTypeError(returnType, result, fieldNodes);
1191
1169
  }
1192
1170
  return collectAndExecuteSubfields(
@@ -1233,8 +1211,23 @@ function collectAndExecuteSubfields(
1233
1211
  info: GraphQLResolveInfo,
1234
1212
  path: ResponsePath,
1235
1213
  result: mixed,
1236
- ): mixed {
1214
+ ): MaybePromise<ObjMap<mixed>> {
1237
1215
  // Collect sub-fields to execute to complete this value.
1216
+ const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
1217
+ return executeFields(exeContext, returnType, result, path, subFieldNodes);
1218
+ }
1219
+
1220
+ /**
1221
+ * A memoized collection of relevant subfields in the context of the return
1222
+ * type. Memoizing ensures the subfields are not repeatedly calculated, which
1223
+ * saves overhead when resolving lists of values.
1224
+ */
1225
+ const collectSubfields = memoize3(_collectSubfields);
1226
+ function _collectSubfields(
1227
+ exeContext: ExecutionContext,
1228
+ returnType: GraphQLObjectType,
1229
+ fieldNodes: $ReadOnlyArray<FieldNode>,
1230
+ ): ObjMap<Array<FieldNode>> {
1238
1231
  let subFieldNodes = Object.create(null);
1239
1232
  const visitedFragmentNames = Object.create(null);
1240
1233
  for (let i = 0; i < fieldNodes.length; i++) {
@@ -1249,8 +1242,7 @@ function collectAndExecuteSubfields(
1249
1242
  );
1250
1243
  }
1251
1244
  }
1252
-
1253
- return executeFields(exeContext, returnType, result, path, subFieldNodes);
1245
+ return subFieldNodes;
1254
1246
  }
1255
1247
 
1256
1248
  /**
@@ -1288,9 +1280,8 @@ function defaultResolveTypeFn(
1288
1280
  if (type.isTypeOf) {
1289
1281
  const isTypeOfResult = type.isTypeOf(value, context, info);
1290
1282
 
1291
- const promise = getPromise(isTypeOfResult);
1292
- if (promise) {
1293
- promisedIsTypeOfResults[i] = promise;
1283
+ if (isPromise(isTypeOfResult)) {
1284
+ promisedIsTypeOfResults[i] = isTypeOfResult;
1294
1285
  } else if (isTypeOfResult) {
1295
1286
  return type;
1296
1287
  }
@@ -1330,20 +1321,6 @@ export const defaultFieldResolver: GraphQLFieldResolver<any, *> = function(
1330
1321
  }
1331
1322
  };
1332
1323
 
1333
- /**
1334
- * Only returns the value if it acts like a Promise, i.e. has a "then" function,
1335
- * otherwise returns void.
1336
- */
1337
- function getPromise<T>(value: Promise<T> | mixed): Promise<T> | void {
1338
- if (
1339
- typeof value === 'object' &&
1340
- value !== null &&
1341
- typeof value.then === 'function'
1342
- ) {
1343
- return (value: any);
1344
- }
1345
- }
1346
-
1347
1324
  /**
1348
1325
  * This method looks up the field on the given type defintion.
1349
1326
  * It has special casing for the two introspection fields, __schema
@@ -6,7 +6,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  *
9
- *
9
+ * strict
10
10
  */
11
11
 
12
12
  import { forEach, isCollection } from 'iterall';
@@ -14,10 +14,14 @@ import { GraphQLError, locatedError } from '../error';
14
14
  import invariant from '../jsutils/invariant';
15
15
  import isInvalid from '../jsutils/isInvalid';
16
16
  import isNullish from '../jsutils/isNullish';
17
+ import isPromise from '../jsutils/isPromise';
18
+ import memoize3 from '../jsutils/memoize3';
19
+ import promiseForObject from '../jsutils/promiseForObject';
20
+ import promiseReduce from '../jsutils/promiseReduce';
17
21
 
18
22
 
19
23
  import { typeFromAST } from '../utilities/typeFromAST';
20
- import * as Kind from '../language/kinds';
24
+ import { Kind } from '../language/kinds';
21
25
  import { getVariableValues, getArgumentValues, getDirectiveValues } from './values';
22
26
  import { isObjectType, isAbstractType, isLeafType, isListType, isNonNullType } from '../type/definition';
23
27
 
@@ -112,9 +116,8 @@ function executeImpl(schema, document, rootValue, contextValue, variableValues,
112
116
  * response defined by the "Response" section of the GraphQL specification.
113
117
  */
114
118
  function buildResponse(context, data) {
115
- var promise = getPromise(data);
116
- if (promise) {
117
- return promise.then(function (resolved) {
119
+ if (isPromise(data)) {
120
+ return data.then(function (resolved) {
118
121
  return buildResponse(context, resolved);
119
122
  });
120
123
  }
@@ -240,9 +243,8 @@ function executeOperation(exeContext, operation, rootValue) {
240
243
  // Similar to completeValueCatchingError.
241
244
  try {
242
245
  var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
243
- var promise = getPromise(result);
244
- if (promise) {
245
- return promise.then(undefined, function (error) {
246
+ if (isPromise(result)) {
247
+ return result.then(undefined, function (error) {
246
248
  exeContext.errors.push(error);
247
249
  return Promise.resolve(null);
248
250
  });
@@ -287,25 +289,22 @@ export function getOperationRootType(schema, operation) {
287
289
  * for "write" mode.
288
290
  */
289
291
  function executeFieldsSerially(exeContext, parentType, sourceValue, path, fields) {
290
- return Object.keys(fields).reduce(function (prevPromise, responseName) {
291
- return prevPromise.then(function (results) {
292
- var fieldNodes = fields[responseName];
293
- var fieldPath = addPath(path, responseName);
294
- var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
295
- if (result === undefined) {
296
- return results;
297
- }
298
- var promise = getPromise(result);
299
- if (promise) {
300
- return promise.then(function (resolvedResult) {
301
- results[responseName] = resolvedResult;
302
- return results;
303
- });
304
- }
305
- results[responseName] = result;
292
+ return promiseReduce(Object.keys(fields), function (results, responseName) {
293
+ var fieldNodes = fields[responseName];
294
+ var fieldPath = addPath(path, responseName);
295
+ var result = resolveField(exeContext, parentType, sourceValue, fieldNodes, fieldPath);
296
+ if (result === undefined) {
306
297
  return results;
307
- });
308
- }, Promise.resolve({}));
298
+ }
299
+ if (isPromise(result)) {
300
+ return result.then(function (resolvedResult) {
301
+ results[responseName] = resolvedResult;
302
+ return results;
303
+ });
304
+ }
305
+ results[responseName] = result;
306
+ return results;
307
+ }, Object.create(null));
309
308
  }
310
309
 
311
310
  /**
@@ -323,7 +322,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
323
322
  return results;
324
323
  }
325
324
  results[responseName] = result;
326
- if (getPromise(result)) {
325
+ if (!containsPromise && isPromise(result)) {
327
326
  containsPromise = true;
328
327
  }
329
328
  return results;
@@ -421,26 +420,6 @@ function doesFragmentConditionMatch(exeContext, fragment, type) {
421
420
  return false;
422
421
  }
423
422
 
424
- /**
425
- * This function transforms a JS object `ObjMap<Promise<T>>` into
426
- * a `Promise<ObjMap<T>>`
427
- *
428
- * This is akin to bluebird's `Promise.props`, but implemented only using
429
- * `Promise.all` so it will work with any implementation of ES6 promises.
430
- */
431
- function promiseForObject(object) {
432
- var keys = Object.keys(object);
433
- var valuesAndPromises = keys.map(function (name) {
434
- return object[name];
435
- });
436
- return Promise.all(valuesAndPromises).then(function (values) {
437
- return values.reduce(function (resolvedObject, value, i) {
438
- resolvedObject[keys[i]] = value;
439
- return resolvedObject;
440
- }, Object.create(null));
441
- });
442
- }
443
-
444
423
  /**
445
424
  * Implements the logic to compute the key of a given field's entry
446
425
  */
@@ -506,8 +485,7 @@ export function resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resol
506
485
  var context = exeContext.contextValue;
507
486
 
508
487
  var result = resolveFn(source, args, context, info);
509
- var promise = getPromise(result);
510
- return promise ? promise.then(undefined, asErrorInstance) : result;
488
+ return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
511
489
  } catch (error) {
512
490
  return asErrorInstance(error);
513
491
  }
@@ -532,13 +510,12 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
532
510
  // a null value for this field if one is encountered.
533
511
  try {
534
512
  var completed = completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result);
535
- var promise = getPromise(completed);
536
- if (promise) {
513
+ if (isPromise(completed)) {
537
514
  // If `completeValueWithLocatedError` returned a rejected promise, log
538
515
  // the rejection error and resolve to null.
539
516
  // Note: we don't rely on a `catch` method, but we do expect "thenable"
540
517
  // to take a second callback for the error case.
541
- return promise.then(undefined, function (error) {
518
+ return completed.then(undefined, function (error) {
542
519
  exeContext.errors.push(error);
543
520
  return Promise.resolve(null);
544
521
  });
@@ -557,9 +534,8 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
557
534
  function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info, path, result) {
558
535
  try {
559
536
  var completed = completeValue(exeContext, returnType, fieldNodes, info, path, result);
560
- var promise = getPromise(completed);
561
- if (promise) {
562
- return promise.then(undefined, function (error) {
537
+ if (isPromise(completed)) {
538
+ return completed.then(undefined, function (error) {
563
539
  return Promise.reject(locatedError(asErrorInstance(error), fieldNodes, responsePathAsArray(path)));
564
540
  });
565
541
  }
@@ -592,9 +568,8 @@ function completeValueWithLocatedError(exeContext, returnType, fieldNodes, info,
592
568
  */
593
569
  function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
594
570
  // If result is a Promise, apply-lift over completeValue.
595
- var promise = getPromise(result);
596
- if (promise) {
597
- return promise.then(function (resolved) {
571
+ if (isPromise(result)) {
572
+ return result.then(function (resolved) {
598
573
  return completeValue(exeContext, returnType, fieldNodes, info, path, resolved);
599
574
  });
600
575
  }
@@ -664,7 +639,7 @@ function completeListValue(exeContext, returnType, fieldNodes, info, path, resul
664
639
  var fieldPath = addPath(path, index);
665
640
  var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);
666
641
 
667
- if (!containsPromise && getPromise(completedItem)) {
642
+ if (!containsPromise && isPromise(completedItem)) {
668
643
  containsPromise = true;
669
644
  }
670
645
  completedResults.push(completedItem);
@@ -693,9 +668,8 @@ function completeLeafValue(returnType, result) {
693
668
  function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result) {
694
669
  var runtimeType = returnType.resolveType ? returnType.resolveType(result, exeContext.contextValue, info) : defaultResolveTypeFn(result, exeContext.contextValue, info, returnType);
695
670
 
696
- var promise = getPromise(runtimeType);
697
- if (promise) {
698
- return promise.then(function (resolvedRuntimeType) {
671
+ if (isPromise(runtimeType)) {
672
+ return runtimeType.then(function (resolvedRuntimeType) {
699
673
  return completeObjectValue(exeContext, ensureValidRuntimeType(resolvedRuntimeType, exeContext, returnType, fieldNodes, info, result), fieldNodes, info, path, result);
700
674
  });
701
675
  }
@@ -727,10 +701,9 @@ function completeObjectValue(exeContext, returnType, fieldNodes, info, path, res
727
701
  if (returnType.isTypeOf) {
728
702
  var isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
729
703
 
730
- var promise = getPromise(isTypeOf);
731
- if (promise) {
732
- return promise.then(function (isTypeOfResult) {
733
- if (!isTypeOfResult) {
704
+ if (isPromise(isTypeOf)) {
705
+ return isTypeOf.then(function (resolvedIsTypeOf) {
706
+ if (!resolvedIsTypeOf) {
734
707
  throw invalidReturnTypeError(returnType, result, fieldNodes);
735
708
  }
736
709
  return collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, path, result);
@@ -751,6 +724,17 @@ function invalidReturnTypeError(returnType, result, fieldNodes) {
751
724
 
752
725
  function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, path, result) {
753
726
  // Collect sub-fields to execute to complete this value.
727
+ var subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
728
+ return executeFields(exeContext, returnType, result, path, subFieldNodes);
729
+ }
730
+
731
+ /**
732
+ * A memoized collection of relevant subfields in the context of the return
733
+ * type. Memoizing ensures the subfields are not repeatedly calculated, which
734
+ * saves overhead when resolving lists of values.
735
+ */
736
+ var collectSubfields = memoize3(_collectSubfields);
737
+ function _collectSubfields(exeContext, returnType, fieldNodes) {
754
738
  var subFieldNodes = Object.create(null);
755
739
  var visitedFragmentNames = Object.create(null);
756
740
  for (var i = 0; i < fieldNodes.length; i++) {
@@ -759,8 +743,7 @@ function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, info, pa
759
743
  subFieldNodes = collectFields(exeContext, returnType, selectionSet, subFieldNodes, visitedFragmentNames);
760
744
  }
761
745
  }
762
-
763
- return executeFields(exeContext, returnType, result, path, subFieldNodes);
746
+ return subFieldNodes;
764
747
  }
765
748
 
766
749
  /**
@@ -789,9 +772,8 @@ function defaultResolveTypeFn(value, context, info, abstractType) {
789
772
  if (type.isTypeOf) {
790
773
  var isTypeOfResult = type.isTypeOf(value, context, info);
791
774
 
792
- var promise = getPromise(isTypeOfResult);
793
- if (promise) {
794
- promisedIsTypeOfResults[i] = promise;
775
+ if (isPromise(isTypeOfResult)) {
776
+ promisedIsTypeOfResults[i] = isTypeOfResult;
795
777
  } else if (isTypeOfResult) {
796
778
  return type;
797
779
  }
@@ -826,16 +808,6 @@ export var defaultFieldResolver = function defaultFieldResolver(source, args, co
826
808
  }
827
809
  };
828
810
 
829
- /**
830
- * Only returns the value if it acts like a Promise, i.e. has a "then" function,
831
- * otherwise returns void.
832
- */
833
- function getPromise(value) {
834
- if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null && typeof value.then === 'function') {
835
- return value;
836
- }
837
- }
838
-
839
811
  /**
840
812
  * This method looks up the field on the given type defintion.
841
813
  * It has special casing for the two introspection fields, __schema
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @flow
7
+ * @flow strict
8
8
  */
9
9
 
10
10
  export { execute, defaultFieldResolver, responsePathAsArray } from './execute';
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- *
7
+ * strict
8
8
  */
9
9
 
10
10
  export { execute, defaultFieldResolver, responsePathAsArray } from './execute';