graphql 15.1.0 → 15.4.0

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 (343) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +10 -12
  3. package/error/GraphQLError.js +5 -5
  4. package/error/GraphQLError.js.flow +5 -5
  5. package/error/GraphQLError.mjs +1 -1
  6. package/error/formatError.js +1 -1
  7. package/error/formatError.js.flow +2 -3
  8. package/error/index.js +4 -4
  9. package/error/index.js.flow +0 -1
  10. package/error/locatedError.d.ts +2 -2
  11. package/error/locatedError.js +10 -5
  12. package/error/locatedError.js.flow +11 -5
  13. package/error/locatedError.mjs +6 -4
  14. package/error/syntaxError.js +1 -1
  15. package/error/syntaxError.js.flow +1 -2
  16. package/execution/execute.d.ts +24 -16
  17. package/execution/execute.js +123 -105
  18. package/execution/execute.js.flow +169 -153
  19. package/execution/execute.mjs +101 -82
  20. package/execution/index.d.ts +2 -0
  21. package/execution/index.js +9 -3
  22. package/execution/index.js.flow +12 -3
  23. package/execution/index.mjs +1 -1
  24. package/execution/values.js +11 -11
  25. package/execution/values.js.flow +10 -14
  26. package/graphql.js +5 -5
  27. package/graphql.js.flow +9 -9
  28. package/index.d.ts +19 -1
  29. package/index.js +27 -9
  30. package/index.js.flow +10 -3
  31. package/index.mjs +4 -3
  32. package/jsutils/ObjMap.js.flow +0 -1
  33. package/jsutils/Path.d.ts +6 -1
  34. package/jsutils/Path.js +3 -2
  35. package/jsutils/Path.js.flow +3 -2
  36. package/jsutils/Path.mjs +3 -2
  37. package/jsutils/PromiseOrValue.js.flow +0 -1
  38. package/jsutils/defineInspect.js +2 -2
  39. package/jsutils/defineInspect.js.flow +0 -1
  40. package/jsutils/devAssert.js.flow +0 -1
  41. package/jsutils/didYouMean.js.flow +0 -1
  42. package/jsutils/identityFunc.js.flow +0 -1
  43. package/jsutils/inspect.js +1 -2
  44. package/jsutils/inspect.js.flow +10 -8
  45. package/jsutils/inspect.mjs +1 -1
  46. package/jsutils/instanceOf.js.flow +2 -3
  47. package/jsutils/invariant.js.flow +0 -1
  48. package/jsutils/isAsyncIterable.js +19 -0
  49. package/jsutils/isAsyncIterable.js.flow +18 -0
  50. package/jsutils/isAsyncIterable.mjs +16 -0
  51. package/jsutils/isCollection.js +1 -1
  52. package/jsutils/isCollection.js.flow +0 -1
  53. package/jsutils/isObjectLike.js.flow +0 -1
  54. package/jsutils/isPromise.js.flow +0 -1
  55. package/jsutils/keyMap.js.flow +1 -2
  56. package/jsutils/keyValMap.js.flow +1 -2
  57. package/jsutils/mapValue.js +1 -1
  58. package/jsutils/mapValue.js.flow +1 -2
  59. package/jsutils/memoize3.js +2 -5
  60. package/jsutils/memoize3.js.flow +2 -5
  61. package/jsutils/memoize3.mjs +2 -5
  62. package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
  63. package/jsutils/printPathArray.js.flow +0 -1
  64. package/jsutils/promiseForObject.js.flow +1 -2
  65. package/jsutils/promiseReduce.js +1 -1
  66. package/jsutils/promiseReduce.js.flow +1 -1
  67. package/jsutils/promiseReduce.mjs +1 -1
  68. package/jsutils/suggestionList.js.flow +1 -2
  69. package/jsutils/toObjMap.js +1 -1
  70. package/jsutils/toObjMap.js.flow +5 -6
  71. package/language/ast.js +1 -1
  72. package/language/ast.js.flow +2 -3
  73. package/language/blockString.d.ts +1 -1
  74. package/language/blockString.js +53 -32
  75. package/language/blockString.js.flow +49 -34
  76. package/language/blockString.mjs +54 -33
  77. package/language/directiveLocation.js.flow +0 -1
  78. package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
  79. package/language/experimentalOnlineParser/grammar.js +987 -0
  80. package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
  81. package/language/experimentalOnlineParser/grammar.mjs +980 -0
  82. package/language/experimentalOnlineParser/index.d.ts +6 -0
  83. package/language/experimentalOnlineParser/index.js +31 -0
  84. package/language/experimentalOnlineParser/index.js.flow +7 -0
  85. package/language/experimentalOnlineParser/index.mjs +1 -0
  86. package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
  87. package/language/experimentalOnlineParser/onlineParser.js +604 -0
  88. package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
  89. package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
  90. package/language/index.js +12 -12
  91. package/language/index.js.flow +0 -1
  92. package/language/kinds.js.flow +0 -1
  93. package/language/lexer.js +242 -183
  94. package/language/lexer.js.flow +191 -186
  95. package/language/lexer.mjs +239 -180
  96. package/language/location.js.flow +1 -2
  97. package/language/parser.js +73 -68
  98. package/language/parser.js.flow +112 -106
  99. package/language/parser.mjs +66 -62
  100. package/language/predicates.js +1 -1
  101. package/language/predicates.js.flow +1 -2
  102. package/language/printLocation.js +1 -1
  103. package/language/printLocation.js.flow +4 -4
  104. package/language/printer.js +20 -13
  105. package/language/printer.js.flow +27 -25
  106. package/language/printer.mjs +18 -11
  107. package/language/source.d.ts +12 -6
  108. package/language/source.js +25 -9
  109. package/language/source.js.flow +25 -8
  110. package/language/source.mjs +19 -7
  111. package/language/tokenKind.js.flow +0 -1
  112. package/language/visitor.d.ts +3 -3
  113. package/language/visitor.js +5 -5
  114. package/language/visitor.js.flow +5 -5
  115. package/language/visitor.mjs +3 -3
  116. package/package.json +1 -1
  117. package/polyfills/arrayFrom.js +2 -2
  118. package/polyfills/arrayFrom.js.flow +1 -2
  119. package/polyfills/arrayFrom.mjs +1 -1
  120. package/polyfills/find.js +1 -1
  121. package/polyfills/find.js.flow +1 -2
  122. package/polyfills/find.mjs +1 -1
  123. package/polyfills/isFinite.js +1 -1
  124. package/polyfills/isFinite.js.flow +1 -2
  125. package/polyfills/isFinite.mjs +1 -1
  126. package/polyfills/isInteger.js +1 -1
  127. package/polyfills/isInteger.js.flow +1 -2
  128. package/polyfills/isInteger.mjs +1 -1
  129. package/polyfills/objectEntries.js +1 -1
  130. package/polyfills/objectEntries.js.flow +2 -3
  131. package/polyfills/objectEntries.mjs +1 -1
  132. package/polyfills/objectValues.js +1 -1
  133. package/polyfills/objectValues.js.flow +2 -3
  134. package/polyfills/objectValues.mjs +1 -1
  135. package/polyfills/symbols.js +3 -5
  136. package/polyfills/symbols.js.flow +9 -6
  137. package/polyfills/symbols.mjs +3 -5
  138. package/subscription/index.js +1 -1
  139. package/subscription/index.js.flow +0 -1
  140. package/subscription/mapAsyncIterator.js +2 -2
  141. package/subscription/mapAsyncIterator.js.flow +9 -10
  142. package/subscription/mapAsyncIterator.mjs +1 -1
  143. package/subscription/subscribe.js +61 -73
  144. package/subscription/subscribe.js.flow +74 -88
  145. package/subscription/subscribe.mjs +53 -65
  146. package/type/definition.d.ts +181 -31
  147. package/type/definition.js +37 -32
  148. package/type/definition.js.flow +66 -51
  149. package/type/definition.mjs +20 -18
  150. package/type/directives.d.ts +17 -3
  151. package/type/directives.js +17 -16
  152. package/type/directives.js.flow +20 -21
  153. package/type/directives.mjs +6 -5
  154. package/type/index.d.ts +12 -0
  155. package/type/index.js +6 -6
  156. package/type/index.js.flow +0 -1
  157. package/type/introspection.js +86 -68
  158. package/type/introspection.js.flow +85 -54
  159. package/type/introspection.mjs +79 -61
  160. package/type/scalars.js +9 -9
  161. package/type/scalars.js.flow +3 -3
  162. package/type/scalars.mjs +1 -1
  163. package/type/schema.d.ts +17 -4
  164. package/type/schema.js +13 -13
  165. package/type/schema.js.flow +18 -16
  166. package/type/schema.mjs +1 -1
  167. package/type/validate.js +52 -19
  168. package/type/validate.js.flow +67 -18
  169. package/type/validate.mjs +44 -10
  170. package/utilities/TypeInfo.js +7 -7
  171. package/utilities/TypeInfo.js.flow +16 -18
  172. package/utilities/TypeInfo.mjs +1 -1
  173. package/utilities/assertValidName.js +2 -2
  174. package/utilities/assertValidName.js.flow +0 -1
  175. package/utilities/astFromValue.js +10 -10
  176. package/utilities/astFromValue.js.flow +2 -3
  177. package/utilities/buildASTSchema.js +17 -27
  178. package/utilities/buildASTSchema.js.flow +11 -28
  179. package/utilities/buildASTSchema.mjs +11 -21
  180. package/utilities/buildClientSchema.js +14 -14
  181. package/utilities/buildClientSchema.js.flow +41 -29
  182. package/utilities/buildClientSchema.mjs +5 -5
  183. package/utilities/coerceInputValue.js +14 -14
  184. package/utilities/coerceInputValue.js.flow +7 -6
  185. package/utilities/coerceInputValue.mjs +2 -2
  186. package/utilities/concatAST.js +9 -8
  187. package/utilities/concatAST.js.flow +9 -9
  188. package/utilities/concatAST.mjs +9 -6
  189. package/utilities/extendSchema.js +26 -19
  190. package/utilities/extendSchema.js.flow +58 -45
  191. package/utilities/extendSchema.mjs +9 -2
  192. package/utilities/findBreakingChanges.js +9 -9
  193. package/utilities/findBreakingChanges.js.flow +12 -11
  194. package/utilities/findDeprecatedUsages.d.ts +9 -1
  195. package/utilities/findDeprecatedUsages.js +11 -27
  196. package/utilities/findDeprecatedUsages.js.flow +15 -44
  197. package/utilities/findDeprecatedUsages.mjs +11 -25
  198. package/utilities/getIntrospectionQuery.js.flow +2 -3
  199. package/utilities/getOperationAST.js +1 -1
  200. package/utilities/getOperationAST.js.flow +1 -5
  201. package/utilities/getOperationAST.mjs +1 -1
  202. package/utilities/getOperationRootType.js +1 -1
  203. package/utilities/getOperationRootType.js.flow +5 -6
  204. package/utilities/index.d.ts +4 -1
  205. package/utilities/index.js +22 -22
  206. package/utilities/index.js.flow +1 -2
  207. package/utilities/index.mjs +1 -1
  208. package/utilities/introspectionFromSchema.js +6 -8
  209. package/utilities/introspectionFromSchema.js.flow +10 -10
  210. package/utilities/introspectionFromSchema.mjs +3 -4
  211. package/utilities/lexicographicSortSchema.js +10 -8
  212. package/utilities/lexicographicSortSchema.js.flow +19 -12
  213. package/utilities/lexicographicSortSchema.mjs +3 -1
  214. package/utilities/printSchema.js +15 -16
  215. package/utilities/printSchema.js.flow +34 -25
  216. package/utilities/printSchema.mjs +6 -7
  217. package/utilities/separateOperations.js +2 -2
  218. package/utilities/separateOperations.js.flow +2 -6
  219. package/utilities/separateOperations.mjs +1 -1
  220. package/utilities/stripIgnoredCharacters.js +6 -16
  221. package/utilities/stripIgnoredCharacters.js.flow +4 -13
  222. package/utilities/stripIgnoredCharacters.mjs +3 -10
  223. package/utilities/typeComparators.js +1 -1
  224. package/utilities/typeComparators.js.flow +2 -4
  225. package/utilities/typeFromAST.js +6 -6
  226. package/utilities/typeFromAST.js.flow +11 -14
  227. package/utilities/typeFromAST.mjs +2 -2
  228. package/utilities/typedQueryDocumentNode.d.ts +20 -0
  229. package/utilities/valueFromAST.js +6 -6
  230. package/utilities/valueFromAST.js.flow +7 -5
  231. package/utilities/valueFromASTUntyped.js +4 -4
  232. package/utilities/valueFromASTUntyped.js.flow +2 -3
  233. package/validation/ValidationContext.d.ts +3 -0
  234. package/validation/ValidationContext.js +7 -3
  235. package/validation/ValidationContext.js.flow +28 -22
  236. package/validation/ValidationContext.mjs +4 -0
  237. package/validation/index.d.ts +4 -0
  238. package/validation/index.js +52 -36
  239. package/validation/index.js.flow +4 -1
  240. package/validation/index.mjs +4 -1
  241. package/validation/rules/ExecutableDefinitions.js +1 -1
  242. package/validation/rules/ExecutableDefinitions.js.flow +0 -1
  243. package/validation/rules/ExecutableDefinitionsRule.js +3 -3
  244. package/validation/rules/ExecutableDefinitionsRule.js.flow +2 -3
  245. package/validation/rules/FieldsOnCorrectTypeRule.js +5 -5
  246. package/validation/rules/FieldsOnCorrectTypeRule.js.flow +9 -8
  247. package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
  248. package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +2 -3
  249. package/validation/rules/KnownArgumentNamesRule.js +5 -5
  250. package/validation/rules/KnownArgumentNamesRule.js.flow +5 -5
  251. package/validation/rules/KnownDirectivesRule.js +6 -6
  252. package/validation/rules/KnownDirectivesRule.js.flow +10 -11
  253. package/validation/rules/KnownFragmentNamesRule.js +1 -1
  254. package/validation/rules/KnownFragmentNamesRule.js.flow +3 -3
  255. package/validation/rules/KnownTypeNamesRule.js +12 -10
  256. package/validation/rules/KnownTypeNamesRule.js.flow +14 -11
  257. package/validation/rules/KnownTypeNamesRule.mjs +6 -5
  258. package/validation/rules/LoneAnonymousOperationRule.js +2 -2
  259. package/validation/rules/LoneAnonymousOperationRule.js.flow +2 -3
  260. package/validation/rules/LoneSchemaDefinition.js +1 -1
  261. package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
  262. package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
  263. package/validation/rules/LoneSchemaDefinitionRule.js.flow +2 -3
  264. package/validation/rules/NoFragmentCyclesRule.js +1 -1
  265. package/validation/rules/NoFragmentCyclesRule.js.flow +4 -5
  266. package/validation/rules/NoUndefinedVariablesRule.js +1 -1
  267. package/validation/rules/NoUndefinedVariablesRule.js.flow +3 -3
  268. package/validation/rules/NoUnusedFragmentsRule.js +1 -1
  269. package/validation/rules/NoUnusedFragmentsRule.js.flow +3 -3
  270. package/validation/rules/NoUnusedVariablesRule.js +1 -1
  271. package/validation/rules/NoUnusedVariablesRule.js.flow +3 -3
  272. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
  273. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +29 -27
  274. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
  275. package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
  276. package/validation/rules/PossibleFragmentSpreadsRule.js.flow +7 -4
  277. package/validation/rules/PossibleTypeExtensions.js +1 -1
  278. package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
  279. package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
  280. package/validation/rules/PossibleTypeExtensionsRule.js.flow +8 -6
  281. package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
  282. package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +7 -6
  283. package/validation/rules/ScalarLeafsRule.js +3 -3
  284. package/validation/rules/ScalarLeafsRule.js.flow +3 -4
  285. package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
  286. package/validation/rules/SingleFieldSubscriptionsRule.js.flow +3 -4
  287. package/validation/rules/UniqueArgumentNamesRule.js +1 -1
  288. package/validation/rules/UniqueArgumentNamesRule.js.flow +2 -3
  289. package/validation/rules/UniqueDirectiveNames.js +1 -1
  290. package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
  291. package/validation/rules/UniqueDirectiveNamesRule.js +1 -1
  292. package/validation/rules/UniqueDirectiveNamesRule.js.flow +2 -3
  293. package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
  294. package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +4 -5
  295. package/validation/rules/UniqueEnumValueNames.js +1 -1
  296. package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
  297. package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
  298. package/validation/rules/UniqueEnumValueNamesRule.js.flow +11 -4
  299. package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
  300. package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
  301. package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
  302. package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +17 -6
  303. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
  304. package/validation/rules/UniqueFragmentNamesRule.js +1 -1
  305. package/validation/rules/UniqueFragmentNamesRule.js.flow +3 -3
  306. package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
  307. package/validation/rules/UniqueInputFieldNamesRule.js.flow +3 -3
  308. package/validation/rules/UniqueOperationNamesRule.js +1 -1
  309. package/validation/rules/UniqueOperationNamesRule.js.flow +3 -3
  310. package/validation/rules/UniqueOperationTypes.js +1 -1
  311. package/validation/rules/UniqueOperationTypes.js.flow +0 -1
  312. package/validation/rules/UniqueOperationTypesRule.js +1 -1
  313. package/validation/rules/UniqueOperationTypesRule.js.flow +10 -4
  314. package/validation/rules/UniqueTypeNames.js +1 -1
  315. package/validation/rules/UniqueTypeNames.js.flow +0 -1
  316. package/validation/rules/UniqueTypeNamesRule.js +1 -1
  317. package/validation/rules/UniqueTypeNamesRule.js.flow +3 -4
  318. package/validation/rules/UniqueVariableNamesRule.js +1 -1
  319. package/validation/rules/UniqueVariableNamesRule.js.flow +3 -4
  320. package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
  321. package/validation/rules/ValuesOfCorrectTypeRule.js.flow +3 -4
  322. package/validation/rules/VariablesAreInputTypesRule.js +4 -4
  323. package/validation/rules/VariablesAreInputTypesRule.js.flow +3 -4
  324. package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
  325. package/validation/rules/VariablesInAllowedPositionRule.js.flow +6 -6
  326. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +14 -0
  327. package/validation/rules/custom/NoDeprecatedCustomRule.js +79 -0
  328. package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +94 -0
  329. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +68 -0
  330. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +16 -0
  331. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +34 -0
  332. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +38 -0
  333. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +25 -0
  334. package/validation/specifiedRules.js +33 -33
  335. package/validation/specifiedRules.js.flow +0 -1
  336. package/validation/validate.js +7 -7
  337. package/validation/validate.js.flow +4 -9
  338. package/version.js +2 -2
  339. package/version.js.flow +2 -3
  340. package/version.mjs +2 -2
  341. package/polyfills/flatMap.js +0 -30
  342. package/polyfills/flatMap.js.flow +0 -28
  343. package/polyfills/flatMap.mjs +0 -23
@@ -1,36 +1,48 @@
1
1
  // @flow strict
2
-
3
2
  import arrayFrom from '../polyfills/arrayFrom';
4
3
 
4
+ import type { Path } from '../jsutils/Path';
5
+ import type { ObjMap } from '../jsutils/ObjMap';
6
+ import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
5
7
  import inspect from '../jsutils/inspect';
6
8
  import memoize3 from '../jsutils/memoize3';
7
9
  import invariant from '../jsutils/invariant';
8
10
  import devAssert from '../jsutils/devAssert';
9
11
  import isPromise from '../jsutils/isPromise';
10
- import { type ObjMap } from '../jsutils/ObjMap';
11
12
  import isObjectLike from '../jsutils/isObjectLike';
12
13
  import isCollection from '../jsutils/isCollection';
13
14
  import promiseReduce from '../jsutils/promiseReduce';
14
15
  import promiseForObject from '../jsutils/promiseForObject';
15
- import { type PromiseOrValue } from '../jsutils/PromiseOrValue';
16
- import { type Path, addPath, pathToArray } from '../jsutils/Path';
16
+ import { addPath, pathToArray } from '../jsutils/Path';
17
17
 
18
+ import type { GraphQLFormattedError } from '../error/formatError';
18
19
  import { GraphQLError } from '../error/GraphQLError';
19
20
  import { locatedError } from '../error/locatedError';
20
21
 
21
- import { Kind } from '../language/kinds';
22
- import {
23
- type DocumentNode,
24
- type OperationDefinitionNode,
25
- type SelectionSetNode,
26
- type FieldNode,
27
- type FragmentSpreadNode,
28
- type InlineFragmentNode,
29
- type FragmentDefinitionNode,
22
+ import type {
23
+ DocumentNode,
24
+ OperationDefinitionNode,
25
+ SelectionSetNode,
26
+ FieldNode,
27
+ FragmentSpreadNode,
28
+ InlineFragmentNode,
29
+ FragmentDefinitionNode,
30
30
  } from '../language/ast';
31
+ import { Kind } from '../language/kinds';
31
32
 
33
+ import type { GraphQLSchema } from '../type/schema';
34
+ import type {
35
+ GraphQLObjectType,
36
+ GraphQLOutputType,
37
+ GraphQLLeafType,
38
+ GraphQLAbstractType,
39
+ GraphQLField,
40
+ GraphQLFieldResolver,
41
+ GraphQLResolveInfo,
42
+ GraphQLTypeResolver,
43
+ GraphQLList,
44
+ } from '../type/definition';
32
45
  import { assertValidSchema } from '../type/validate';
33
- import { type GraphQLSchema } from '../type/schema';
34
46
  import {
35
47
  SchemaMetaFieldDef,
36
48
  TypeMetaFieldDef,
@@ -41,15 +53,7 @@ import {
41
53
  GraphQLSkipDirective,
42
54
  } from '../type/directives';
43
55
  import {
44
- type GraphQLObjectType,
45
- type GraphQLOutputType,
46
- type GraphQLLeafType,
47
- type GraphQLAbstractType,
48
- type GraphQLField,
49
- type GraphQLFieldResolver,
50
- type GraphQLResolveInfo,
51
- type GraphQLTypeResolver,
52
- type GraphQLList,
56
+ isNamedType,
53
57
  isObjectType,
54
58
  isAbstractType,
55
59
  isLeafType,
@@ -109,10 +113,18 @@ export type ExecutionContext = {|
109
113
  *
110
114
  * - `errors` is included when any errors occurred as a non-empty array.
111
115
  * - `data` is the result of a successful execution of the query.
116
+ * - `extensions` is reserved for adding non-standard properties.
112
117
  */
113
118
  export type ExecutionResult = {|
114
119
  errors?: $ReadOnlyArray<GraphQLError>,
115
120
  data?: ObjMap<mixed> | null,
121
+ extensions?: ObjMap<mixed>,
122
+ |};
123
+
124
+ export type FormattedExecutionResult = {|
125
+ errors?: $ReadOnlyArray<GraphQLFormattedError>,
126
+ data?: ObjMap<mixed> | null,
127
+ extensions?: ObjMap<mixed>,
116
128
  |};
117
129
 
118
130
  export type ExecutionArgs = {|
@@ -179,6 +191,22 @@ export function execute(
179
191
  });
180
192
  }
181
193
 
194
+ /**
195
+ * Also implements the "Evaluating requests" section of the GraphQL specification.
196
+ * However, it guarantees to complete synchronously (or throw an error) assuming
197
+ * that all field resolvers are also synchronous.
198
+ */
199
+ export function executeSync(args: ExecutionArgs): ExecutionResult {
200
+ const result = executeImpl(args);
201
+
202
+ // Assert that the execution was synchronous.
203
+ if (isPromise(result)) {
204
+ throw new Error('GraphQL execution failed to complete synchronously.');
205
+ }
206
+
207
+ return result;
208
+ }
209
+
182
210
  function executeImpl(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
183
211
  const {
184
212
  schema,
@@ -360,8 +388,6 @@ function executeOperation(
360
388
  // Errors from sub-fields of a NonNull type may propagate to the top level,
361
389
  // at which point we still log the error and null the parent field, which
362
390
  // in this case is the entire response.
363
- //
364
- // Similar to completeValueCatchingError.
365
391
  try {
366
392
  const result =
367
393
  operation.operation === 'mutation'
@@ -395,7 +421,7 @@ function executeFieldsSerially(
395
421
  Object.keys(fields),
396
422
  (results, responseName) => {
397
423
  const fieldNodes = fields[responseName];
398
- const fieldPath = addPath(path, responseName);
424
+ const fieldPath = addPath(path, responseName, parentType.name);
399
425
  const result = resolveField(
400
426
  exeContext,
401
427
  parentType,
@@ -435,7 +461,7 @@ function executeFields(
435
461
 
436
462
  for (const responseName of Object.keys(fields)) {
437
463
  const fieldNodes = fields[responseName];
438
- const fieldPath = addPath(path, responseName);
464
+ const fieldPath = addPath(path, responseName, parentType.name);
439
465
  const result = resolveField(
440
466
  exeContext,
441
467
  parentType,
@@ -446,7 +472,7 @@ function executeFields(
446
472
 
447
473
  if (result !== undefined) {
448
474
  results[responseName] = result;
449
- if (!containsPromise && isPromise(result)) {
475
+ if (isPromise(result)) {
450
476
  containsPromise = true;
451
477
  }
452
478
  }
@@ -617,6 +643,7 @@ function resolveField(
617
643
  return;
618
644
  }
619
645
 
646
+ const returnType = fieldDef.type;
620
647
  const resolveFn = fieldDef.resolve ?? exeContext.fieldResolver;
621
648
 
622
649
  const info = buildResolveInfo(
@@ -627,67 +654,7 @@ function resolveField(
627
654
  path,
628
655
  );
629
656
 
630
- // Get the resolve function, regardless of if its result is normal
631
- // or abrupt (error).
632
- const result = resolveFieldValueOrError(
633
- exeContext,
634
- fieldDef,
635
- fieldNodes,
636
- resolveFn,
637
- source,
638
- info,
639
- );
640
-
641
- return completeValueCatchingError(
642
- exeContext,
643
- fieldDef.type,
644
- fieldNodes,
645
- info,
646
- path,
647
- result,
648
- );
649
- }
650
-
651
- /**
652
- * @internal
653
- */
654
- export function buildResolveInfo(
655
- exeContext: ExecutionContext,
656
- fieldDef: GraphQLField<mixed, mixed>,
657
- fieldNodes: $ReadOnlyArray<FieldNode>,
658
- parentType: GraphQLObjectType,
659
- path: Path,
660
- ): GraphQLResolveInfo {
661
- // The resolve function's optional fourth argument is a collection of
662
- // information about the current execution state.
663
- return {
664
- fieldName: fieldDef.name,
665
- fieldNodes,
666
- returnType: fieldDef.type,
667
- parentType,
668
- path,
669
- schema: exeContext.schema,
670
- fragments: exeContext.fragments,
671
- rootValue: exeContext.rootValue,
672
- operation: exeContext.operation,
673
- variableValues: exeContext.variableValues,
674
- };
675
- }
676
-
677
- /**
678
- * Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
679
- * function. Returns the result of resolveFn or the abrupt-return Error object.
680
- *
681
- * @internal
682
- */
683
- export function resolveFieldValueOrError(
684
- exeContext: ExecutionContext,
685
- fieldDef: GraphQLField<mixed, mixed>,
686
- fieldNodes: $ReadOnlyArray<FieldNode>,
687
- resolveFn: GraphQLFieldResolver<mixed, mixed>,
688
- source: mixed,
689
- info: GraphQLResolveInfo,
690
- ): Error | mixed {
657
+ // Get the resolve function, regardless of if its result is normal or abrupt (error).
691
658
  try {
692
659
  // Build a JS object of arguments from the field.arguments AST, using the
693
660
  // variables scope to fulfill any variable references.
@@ -704,32 +671,7 @@ export function resolveFieldValueOrError(
704
671
  const contextValue = exeContext.contextValue;
705
672
 
706
673
  const result = resolveFn(source, args, contextValue, info);
707
- return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
708
- } catch (error) {
709
- return asErrorInstance(error);
710
- }
711
- }
712
674
 
713
- // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a
714
- // consistent Error interface.
715
- function asErrorInstance(error: mixed): Error {
716
- if (error instanceof Error) {
717
- return error;
718
- }
719
- return new Error('Unexpected error value: ' + inspect(error));
720
- }
721
-
722
- // This is a small wrapper around completeValue which detects and logs errors
723
- // in the execution context.
724
- function completeValueCatchingError(
725
- exeContext: ExecutionContext,
726
- returnType: GraphQLOutputType,
727
- fieldNodes: $ReadOnlyArray<FieldNode>,
728
- info: GraphQLResolveInfo,
729
- path: Path,
730
- result: mixed,
731
- ): PromiseOrValue<mixed> {
732
- try {
733
675
  let completed;
734
676
  if (isPromise(result)) {
735
677
  completed = result.then((resolved) =>
@@ -749,23 +691,49 @@ function completeValueCatchingError(
749
691
  if (isPromise(completed)) {
750
692
  // Note: we don't rely on a `catch` method, but we do expect "thenable"
751
693
  // to take a second callback for the error case.
752
- return completed.then(undefined, (error) =>
753
- handleFieldError(error, fieldNodes, path, returnType, exeContext),
754
- );
694
+ return completed.then(undefined, (rawError) => {
695
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
696
+ return handleFieldError(error, returnType, exeContext);
697
+ });
755
698
  }
756
699
  return completed;
757
- } catch (error) {
758
- return handleFieldError(error, fieldNodes, path, returnType, exeContext);
700
+ } catch (rawError) {
701
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
702
+ return handleFieldError(error, returnType, exeContext);
759
703
  }
760
704
  }
761
705
 
762
- function handleFieldError(rawError, fieldNodes, path, returnType, exeContext) {
763
- const error = locatedError(
764
- asErrorInstance(rawError),
706
+ /**
707
+ * @internal
708
+ */
709
+ export function buildResolveInfo(
710
+ exeContext: ExecutionContext,
711
+ fieldDef: GraphQLField<mixed, mixed>,
712
+ fieldNodes: $ReadOnlyArray<FieldNode>,
713
+ parentType: GraphQLObjectType,
714
+ path: Path,
715
+ ): GraphQLResolveInfo {
716
+ // The resolve function's optional fourth argument is a collection of
717
+ // information about the current execution state.
718
+ return {
719
+ fieldName: fieldDef.name,
765
720
  fieldNodes,
766
- pathToArray(path),
767
- );
721
+ returnType: fieldDef.type,
722
+ parentType,
723
+ path,
724
+ schema: exeContext.schema,
725
+ fragments: exeContext.fragments,
726
+ rootValue: exeContext.rootValue,
727
+ operation: exeContext.operation,
728
+ variableValues: exeContext.variableValues,
729
+ };
730
+ }
768
731
 
732
+ function handleFieldError(
733
+ error: GraphQLError,
734
+ returnType: GraphQLOutputType,
735
+ exeContext: ExecutionContext,
736
+ ): null {
769
737
  // If the field type is non-nullable, then it is resolved without any
770
738
  // protection from errors, however it still properly locates the error.
771
739
  if (isNonNullType(returnType)) {
@@ -913,21 +881,49 @@ function completeListValue(
913
881
  const completedResults = arrayFrom(result, (item, index) => {
914
882
  // No need to modify the info object containing the path,
915
883
  // since from here on it is not ever accessed by resolver functions.
916
- const fieldPath = addPath(path, index);
917
- const completedItem = completeValueCatchingError(
918
- exeContext,
919
- itemType,
920
- fieldNodes,
921
- info,
922
- fieldPath,
923
- item,
924
- );
884
+ const itemPath = addPath(path, index, undefined);
885
+ try {
886
+ let completedItem;
887
+ if (isPromise(item)) {
888
+ completedItem = item.then((resolved) =>
889
+ completeValue(
890
+ exeContext,
891
+ itemType,
892
+ fieldNodes,
893
+ info,
894
+ itemPath,
895
+ resolved,
896
+ ),
897
+ );
898
+ } else {
899
+ completedItem = completeValue(
900
+ exeContext,
901
+ itemType,
902
+ fieldNodes,
903
+ info,
904
+ itemPath,
905
+ item,
906
+ );
907
+ }
925
908
 
926
- if (!containsPromise && isPromise(completedItem)) {
927
- containsPromise = true;
909
+ if (isPromise(completedItem)) {
910
+ containsPromise = true;
911
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
912
+ // to take a second callback for the error case.
913
+ return completedItem.then(undefined, (rawError) => {
914
+ const error = locatedError(
915
+ rawError,
916
+ fieldNodes,
917
+ pathToArray(itemPath),
918
+ );
919
+ return handleFieldError(error, itemType, exeContext);
920
+ });
921
+ }
922
+ return completedItem;
923
+ } catch (rawError) {
924
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
925
+ return handleFieldError(error, itemType, exeContext);
928
926
  }
929
-
930
- return completedItem;
931
927
  });
932
928
 
933
929
  return containsPromise ? Promise.all(completedResults) : completedResults;
@@ -1002,23 +998,43 @@ function completeAbstractValue(
1002
998
  }
1003
999
 
1004
1000
  function ensureValidRuntimeType(
1005
- runtimeTypeOrName: ?GraphQLObjectType | string,
1001
+ runtimeTypeOrName: mixed,
1006
1002
  exeContext: ExecutionContext,
1007
1003
  returnType: GraphQLAbstractType,
1008
1004
  fieldNodes: $ReadOnlyArray<FieldNode>,
1009
1005
  info: GraphQLResolveInfo,
1010
1006
  result: mixed,
1011
1007
  ): GraphQLObjectType {
1012
- const runtimeType =
1013
- typeof runtimeTypeOrName === 'string'
1014
- ? exeContext.schema.getType(runtimeTypeOrName)
1015
- : runtimeTypeOrName;
1008
+ if (runtimeTypeOrName == null) {
1009
+ throw new GraphQLError(
1010
+ `Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}". Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
1011
+ fieldNodes,
1012
+ );
1013
+ }
1016
1014
 
1017
- if (!isObjectType(runtimeType)) {
1015
+ // FIXME: temporary workaround until support for passing object types would be removed in v16.0.0
1016
+ const runtimeTypeName = isNamedType(runtimeTypeOrName)
1017
+ ? runtimeTypeOrName.name
1018
+ : runtimeTypeOrName;
1019
+
1020
+ if (typeof runtimeTypeName !== 'string') {
1018
1021
  throw new GraphQLError(
1019
1022
  `Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
1020
- `value ${inspect(result)}, received "${inspect(runtimeType)}". ` +
1021
- `Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
1023
+ `value ${inspect(result)}, received "${inspect(runtimeTypeOrName)}".`,
1024
+ );
1025
+ }
1026
+
1027
+ const runtimeType = exeContext.schema.getType(runtimeTypeName);
1028
+ if (runtimeType == null) {
1029
+ throw new GraphQLError(
1030
+ `Abstract type "${returnType.name}" was resolve to a type "${runtimeTypeName}" that does not exist inside schema.`,
1031
+ fieldNodes,
1032
+ );
1033
+ }
1034
+
1035
+ if (!isObjectType(runtimeType)) {
1036
+ throw new GraphQLError(
1037
+ `Abstract type "${returnType.name}" was resolve to a non-object type "${runtimeTypeName}".`,
1022
1038
  fieldNodes,
1023
1039
  );
1024
1040
  }
@@ -1163,7 +1179,7 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
1163
1179
  if (isPromise(isTypeOfResult)) {
1164
1180
  promisedIsTypeOfResults[i] = isTypeOfResult;
1165
1181
  } else if (isTypeOfResult) {
1166
- return type;
1182
+ return type.name;
1167
1183
  }
1168
1184
  }
1169
1185
  }
@@ -1172,7 +1188,7 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
1172
1188
  return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
1173
1189
  for (let i = 0; i < isTypeOfResults.length; i++) {
1174
1190
  if (isTypeOfResults[i]) {
1175
- return possibleTypes[i];
1191
+ return possibleTypes[i].name;
1176
1192
  }
1177
1193
  }
1178
1194
  });
@@ -1201,12 +1217,12 @@ export const defaultFieldResolver: GraphQLFieldResolver<
1201
1217
 
1202
1218
  /**
1203
1219
  * This method looks up the field on the given type definition.
1204
- * It has special casing for the two introspection fields, __schema
1205
- * and __typename. __typename is special because it can always be
1206
- * queried as a field, even in situations where no other fields
1207
- * are allowed, like on a Union. __schema could get automatically
1208
- * added to the query type, but that would require mutating type
1209
- * definitions, which would cause issues.
1220
+ * It has special casing for the three introspection fields,
1221
+ * __schema, __type and __typename. __typename is special because
1222
+ * it can always be queried as a field, even in situations where no
1223
+ * other fields are allowed, like on a Union. __schema and __type
1224
+ * could get automatically added to the query type, but that would
1225
+ * require mutating type definitions, which would cause issues.
1210
1226
  *
1211
1227
  * @internal
1212
1228
  */