graphql 0.0.1-test.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 (390) hide show
  1. package/LICENSE +21 -0
  2. package/NotSupportedTSVersion.d.ts +1 -0
  3. package/README.md +158 -0
  4. package/error/GraphQLError.d.ts +142 -0
  5. package/error/GraphQLError.js +267 -0
  6. package/error/GraphQLError.mjs +253 -0
  7. package/error/index.d.ts +7 -0
  8. package/error/index.js +41 -0
  9. package/error/index.mjs +3 -0
  10. package/error/locatedError.d.ts +13 -0
  11. package/error/locatedError.js +40 -0
  12. package/error/locatedError.mjs +32 -0
  13. package/error/syntaxError.d.ts +11 -0
  14. package/error/syntaxError.js +21 -0
  15. package/error/syntaxError.mjs +11 -0
  16. package/execution/collectFields.d.ts +45 -0
  17. package/execution/collectFields.js +229 -0
  18. package/execution/collectFields.mjs +213 -0
  19. package/execution/execute.d.ts +185 -0
  20. package/execution/execute.js +1016 -0
  21. package/execution/execute.mjs +988 -0
  22. package/execution/index.d.ts +14 -0
  23. package/execution/index.js +67 -0
  24. package/execution/index.mjs +9 -0
  25. package/execution/mapAsyncIterator.d.ts +9 -0
  26. package/execution/mapAsyncIterator.js +68 -0
  27. package/execution/mapAsyncIterator.mjs +61 -0
  28. package/execution/subscribe.d.ts +68 -0
  29. package/execution/subscribe.js +261 -0
  30. package/execution/subscribe.mjs +239 -0
  31. package/execution/values.d.ts +81 -0
  32. package/execution/values.js +292 -0
  33. package/execution/values.mjs +255 -0
  34. package/graphql.d.ts +67 -0
  35. package/graphql.js +96 -0
  36. package/graphql.mjs +122 -0
  37. package/index.d.ts +411 -0
  38. package/index.js +1263 -0
  39. package/index.mjs +254 -0
  40. package/jsutils/Maybe.d.ts +2 -0
  41. package/jsutils/Maybe.js +5 -0
  42. package/jsutils/Maybe.mjs +1 -0
  43. package/jsutils/ObjMap.d.ts +16 -0
  44. package/jsutils/ObjMap.js +5 -0
  45. package/jsutils/ObjMap.mjs +1 -0
  46. package/jsutils/Path.d.ts +20 -0
  47. package/jsutils/Path.js +33 -0
  48. package/jsutils/Path.mjs +25 -0
  49. package/jsutils/PromiseOrValue.d.ts +1 -0
  50. package/jsutils/PromiseOrValue.js +5 -0
  51. package/jsutils/PromiseOrValue.mjs +1 -0
  52. package/jsutils/devAssert.d.ts +1 -0
  53. package/jsutils/devAssert.js +14 -0
  54. package/jsutils/devAssert.mjs +7 -0
  55. package/jsutils/didYouMean.d.ts +8 -0
  56. package/jsutils/didYouMean.js +38 -0
  57. package/jsutils/didYouMean.mjs +32 -0
  58. package/jsutils/groupBy.d.ts +7 -0
  59. package/jsutils/groupBy.js +26 -0
  60. package/jsutils/groupBy.mjs +19 -0
  61. package/jsutils/identityFunc.d.ts +4 -0
  62. package/jsutils/identityFunc.js +13 -0
  63. package/jsutils/identityFunc.mjs +6 -0
  64. package/jsutils/inspect.d.ts +4 -0
  65. package/jsutils/inspect.js +121 -0
  66. package/jsutils/inspect.mjs +115 -0
  67. package/jsutils/instanceOf.d.ts +16 -0
  68. package/jsutils/instanceOf.js +60 -0
  69. package/jsutils/instanceOf.mjs +52 -0
  70. package/jsutils/invariant.d.ts +4 -0
  71. package/jsutils/invariant.js +16 -0
  72. package/jsutils/invariant.mjs +9 -0
  73. package/jsutils/isAsyncIterable.d.ts +7 -0
  74. package/jsutils/isAsyncIterable.js +18 -0
  75. package/jsutils/isAsyncIterable.mjs +11 -0
  76. package/jsutils/isIterableObject.d.ts +20 -0
  77. package/jsutils/isIterableObject.js +32 -0
  78. package/jsutils/isIterableObject.mjs +25 -0
  79. package/jsutils/isObjectLike.d.ts +7 -0
  80. package/jsutils/isObjectLike.js +14 -0
  81. package/jsutils/isObjectLike.mjs +7 -0
  82. package/jsutils/isPromise.d.ts +5 -0
  83. package/jsutils/isPromise.js +17 -0
  84. package/jsutils/isPromise.mjs +10 -0
  85. package/jsutils/keyMap.d.ts +32 -0
  86. package/jsutils/keyMap.js +43 -0
  87. package/jsutils/keyMap.mjs +36 -0
  88. package/jsutils/keyValMap.d.ts +23 -0
  89. package/jsutils/keyValMap.js +33 -0
  90. package/jsutils/keyValMap.mjs +26 -0
  91. package/jsutils/mapValue.d.ts +9 -0
  92. package/jsutils/mapValue.js +20 -0
  93. package/jsutils/mapValue.mjs +13 -0
  94. package/jsutils/memoize3.d.ts +9 -0
  95. package/jsutils/memoize3.js +41 -0
  96. package/jsutils/memoize3.mjs +34 -0
  97. package/jsutils/naturalCompare.d.ts +8 -0
  98. package/jsutils/naturalCompare.js +69 -0
  99. package/jsutils/naturalCompare.mjs +61 -0
  100. package/jsutils/printPathArray.d.ts +6 -0
  101. package/jsutils/printPathArray.js +17 -0
  102. package/jsutils/printPathArray.mjs +10 -0
  103. package/jsutils/promiseForObject.d.ts +11 -0
  104. package/jsutils/promiseForObject.js +25 -0
  105. package/jsutils/promiseForObject.mjs +18 -0
  106. package/jsutils/promiseReduce.d.ts +13 -0
  107. package/jsutils/promiseReduce.js +27 -0
  108. package/jsutils/promiseReduce.mjs +20 -0
  109. package/jsutils/suggestionList.d.ts +8 -0
  110. package/jsutils/suggestionList.js +139 -0
  111. package/jsutils/suggestionList.mjs +130 -0
  112. package/jsutils/toError.d.ts +4 -0
  113. package/jsutils/toError.js +25 -0
  114. package/jsutils/toError.mjs +18 -0
  115. package/jsutils/toObjMap.d.ts +5 -0
  116. package/jsutils/toObjMap.js +24 -0
  117. package/jsutils/toObjMap.mjs +17 -0
  118. package/language/ast.d.ts +536 -0
  119. package/language/ast.js +224 -0
  120. package/language/ast.mjs +206 -0
  121. package/language/blockString.d.ts +28 -0
  122. package/language/blockString.js +195 -0
  123. package/language/blockString.mjs +178 -0
  124. package/language/characterClasses.d.ts +47 -0
  125. package/language/characterClasses.js +75 -0
  126. package/language/characterClasses.mjs +64 -0
  127. package/language/directiveLocation.d.ts +32 -0
  128. package/language/directiveLocation.js +40 -0
  129. package/language/directiveLocation.mjs +31 -0
  130. package/language/index.d.ts +97 -0
  131. package/language/index.js +215 -0
  132. package/language/index.mjs +29 -0
  133. package/language/kinds.d.ts +65 -0
  134. package/language/kinds.js +64 -0
  135. package/language/kinds.mjs +55 -0
  136. package/language/lexer.d.ts +45 -0
  137. package/language/lexer.js +1006 -0
  138. package/language/lexer.mjs +902 -0
  139. package/language/location.d.ts +16 -0
  140. package/language/location.js +38 -0
  141. package/language/location.mjs +30 -0
  142. package/language/parser.d.ts +554 -0
  143. package/language/parser.js +1567 -0
  144. package/language/parser.mjs +1524 -0
  145. package/language/predicates.d.ts +33 -0
  146. package/language/predicates.js +109 -0
  147. package/language/predicates.mjs +81 -0
  148. package/language/printLocation.d.ts +14 -0
  149. package/language/printLocation.js +74 -0
  150. package/language/printLocation.mjs +66 -0
  151. package/language/printString.d.ts +5 -0
  152. package/language/printString.js +183 -0
  153. package/language/printString.mjs +176 -0
  154. package/language/printer.d.ts +6 -0
  155. package/language/printer.js +351 -0
  156. package/language/printer.mjs +339 -0
  157. package/language/source.d.ts +25 -0
  158. package/language/source.js +65 -0
  159. package/language/source.mjs +50 -0
  160. package/language/tokenKind.d.ts +34 -0
  161. package/language/tokenKind.js +44 -0
  162. package/language/tokenKind.mjs +35 -0
  163. package/language/visitor.d.ts +194 -0
  164. package/language/visitor.js +377 -0
  165. package/language/visitor.mjs +361 -0
  166. package/package.json +40 -0
  167. package/subscription/index.d.ts +19 -0
  168. package/subscription/index.js +19 -0
  169. package/subscription/index.mjs +19 -0
  170. package/type/assertName.d.ts +10 -0
  171. package/type/assertName.js +59 -0
  172. package/type/assertName.mjs +44 -0
  173. package/type/definition.d.ts +917 -0
  174. package/type/definition.js +1329 -0
  175. package/type/definition.mjs +1167 -0
  176. package/type/directives.d.ts +86 -0
  177. package/type/directives.js +224 -0
  178. package/type/directives.mjs +190 -0
  179. package/type/index.d.ts +150 -0
  180. package/type/index.js +547 -0
  181. package/type/index.mjs +103 -0
  182. package/type/introspection.d.ts +29 -0
  183. package/type/introspection.js +617 -0
  184. package/type/introspection.mjs +550 -0
  185. package/type/scalars.d.ts +19 -0
  186. package/type/scalars.js +359 -0
  187. package/type/scalars.mjs +299 -0
  188. package/type/schema.d.ts +170 -0
  189. package/type/schema.js +402 -0
  190. package/type/schema.mjs +381 -0
  191. package/type/validate.d.ts +17 -0
  192. package/type/validate.js +672 -0
  193. package/type/validate.mjs +647 -0
  194. package/utilities/TypeInfo.d.ts +67 -0
  195. package/utilities/TypeInfo.js +418 -0
  196. package/utilities/TypeInfo.mjs +395 -0
  197. package/utilities/assertValidName.d.ts +13 -0
  198. package/utilities/assertValidName.js +51 -0
  199. package/utilities/assertValidName.mjs +40 -0
  200. package/utilities/astFromValue.d.ts +28 -0
  201. package/utilities/astFromValue.js +190 -0
  202. package/utilities/astFromValue.mjs +177 -0
  203. package/utilities/buildASTSchema.d.ts +35 -0
  204. package/utilities/buildASTSchema.js +115 -0
  205. package/utilities/buildASTSchema.mjs +97 -0
  206. package/utilities/buildClientSchema.d.ts +19 -0
  207. package/utilities/buildClientSchema.js +386 -0
  208. package/utilities/buildClientSchema.mjs +363 -0
  209. package/utilities/coerceInputValue.d.ts +16 -0
  210. package/utilities/coerceInputValue.js +191 -0
  211. package/utilities/coerceInputValue.mjs +172 -0
  212. package/utilities/concatAST.d.ts +9 -0
  213. package/utilities/concatAST.js +26 -0
  214. package/utilities/concatAST.mjs +19 -0
  215. package/utilities/extendSchema.d.ts +40 -0
  216. package/utilities/extendSchema.js +798 -0
  217. package/utilities/extendSchema.mjs +789 -0
  218. package/utilities/findBreakingChanges.d.ts +51 -0
  219. package/utilities/findBreakingChanges.js +547 -0
  220. package/utilities/findBreakingChanges.mjs +516 -0
  221. package/utilities/getIntrospectionQuery.d.ts +182 -0
  222. package/utilities/getIntrospectionQuery.js +134 -0
  223. package/utilities/getIntrospectionQuery.mjs +127 -0
  224. package/utilities/getOperationAST.d.ts +11 -0
  225. package/utilities/getOperationAST.js +43 -0
  226. package/utilities/getOperationAST.mjs +36 -0
  227. package/utilities/getOperationRootType.d.ts +15 -0
  228. package/utilities/getOperationRootType.js +59 -0
  229. package/utilities/getOperationRootType.mjs +52 -0
  230. package/utilities/index.d.ts +61 -0
  231. package/utilities/index.js +233 -0
  232. package/utilities/index.mjs +55 -0
  233. package/utilities/introspectionFromSchema.d.ts +18 -0
  234. package/utilities/introspectionFromSchema.js +42 -0
  235. package/utilities/introspectionFromSchema.mjs +30 -0
  236. package/utilities/lexicographicSortSchema.d.ts +9 -0
  237. package/utilities/lexicographicSortSchema.js +177 -0
  238. package/utilities/lexicographicSortSchema.mjs +172 -0
  239. package/utilities/printSchema.d.ts +5 -0
  240. package/utilities/printSchema.js +333 -0
  241. package/utilities/printSchema.mjs +309 -0
  242. package/utilities/separateOperations.d.ts +11 -0
  243. package/utilities/separateOperations.js +88 -0
  244. package/utilities/separateOperations.mjs +80 -0
  245. package/utilities/sortValueNode.d.ts +9 -0
  246. package/utilities/sortValueNode.js +47 -0
  247. package/utilities/sortValueNode.mjs +39 -0
  248. package/utilities/stripIgnoredCharacters.d.ts +62 -0
  249. package/utilities/stripIgnoredCharacters.js +121 -0
  250. package/utilities/stripIgnoredCharacters.mjs +104 -0
  251. package/utilities/typeComparators.d.ts +32 -0
  252. package/utilities/typeComparators.js +116 -0
  253. package/utilities/typeComparators.mjs +106 -0
  254. package/utilities/typeFromAST.d.ts +32 -0
  255. package/utilities/typeFromAST.js +27 -0
  256. package/utilities/typeFromAST.mjs +18 -0
  257. package/utilities/typedQueryDocumentNode.d.ts +22 -0
  258. package/utilities/typedQueryDocumentNode.js +5 -0
  259. package/utilities/typedQueryDocumentNode.mjs +1 -0
  260. package/utilities/valueFromAST.d.ts +29 -0
  261. package/utilities/valueFromAST.js +185 -0
  262. package/utilities/valueFromAST.mjs +172 -0
  263. package/utilities/valueFromASTUntyped.d.ts +23 -0
  264. package/utilities/valueFromASTUntyped.js +61 -0
  265. package/utilities/valueFromASTUntyped.mjs +53 -0
  266. package/validation/ValidationContext.d.ts +95 -0
  267. package/validation/ValidationContext.js +232 -0
  268. package/validation/ValidationContext.mjs +212 -0
  269. package/validation/index.d.ts +40 -0
  270. package/validation/index.js +317 -0
  271. package/validation/index.mjs +68 -0
  272. package/validation/rules/ExecutableDefinitionsRule.d.ts +13 -0
  273. package/validation/rules/ExecutableDefinitionsRule.js +44 -0
  274. package/validation/rules/ExecutableDefinitionsRule.mjs +35 -0
  275. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +13 -0
  276. package/validation/rules/FieldsOnCorrectTypeRule.js +143 -0
  277. package/validation/rules/FieldsOnCorrectTypeRule.mjs +125 -0
  278. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +14 -0
  279. package/validation/rules/FragmentsOnCompositeTypesRule.js +65 -0
  280. package/validation/rules/FragmentsOnCompositeTypesRule.mjs +49 -0
  281. package/validation/rules/KnownArgumentNamesRule.d.ts +23 -0
  282. package/validation/rules/KnownArgumentNamesRule.js +116 -0
  283. package/validation/rules/KnownArgumentNamesRule.mjs +98 -0
  284. package/validation/rules/KnownDirectivesRule.d.ts +16 -0
  285. package/validation/rules/KnownDirectivesRule.js +163 -0
  286. package/validation/rules/KnownDirectivesRule.mjs +146 -0
  287. package/validation/rules/KnownFragmentNamesRule.d.ts +13 -0
  288. package/validation/rules/KnownFragmentNamesRule.js +34 -0
  289. package/validation/rules/KnownFragmentNamesRule.mjs +24 -0
  290. package/validation/rules/KnownTypeNamesRule.d.ts +16 -0
  291. package/validation/rules/KnownTypeNamesRule.js +87 -0
  292. package/validation/rules/KnownTypeNamesRule.mjs +75 -0
  293. package/validation/rules/LoneAnonymousOperationRule.d.ts +13 -0
  294. package/validation/rules/LoneAnonymousOperationRule.js +40 -0
  295. package/validation/rules/LoneAnonymousOperationRule.mjs +32 -0
  296. package/validation/rules/LoneSchemaDefinitionRule.d.ts +10 -0
  297. package/validation/rules/LoneSchemaDefinitionRule.js +63 -0
  298. package/validation/rules/LoneSchemaDefinitionRule.mjs +53 -0
  299. package/validation/rules/NoFragmentCyclesRule.d.ts +13 -0
  300. package/validation/rules/NoFragmentCyclesRule.js +83 -0
  301. package/validation/rules/NoFragmentCyclesRule.mjs +76 -0
  302. package/validation/rules/NoUndefinedVariablesRule.d.ts +13 -0
  303. package/validation/rules/NoUndefinedVariablesRule.js +50 -0
  304. package/validation/rules/NoUndefinedVariablesRule.mjs +43 -0
  305. package/validation/rules/NoUnusedFragmentsRule.d.ts +13 -0
  306. package/validation/rules/NoUnusedFragmentsRule.js +59 -0
  307. package/validation/rules/NoUnusedFragmentsRule.mjs +52 -0
  308. package/validation/rules/NoUnusedVariablesRule.d.ts +13 -0
  309. package/validation/rules/NoUnusedVariablesRule.js +55 -0
  310. package/validation/rules/NoUnusedVariablesRule.mjs +48 -0
  311. package/validation/rules/OverlappingFieldsCanBeMergedRule-old.js +805 -0
  312. package/validation/rules/OverlappingFieldsCanBeMergedRule-old.mjs +788 -0
  313. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +14 -0
  314. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +805 -0
  315. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +788 -0
  316. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +12 -0
  317. package/validation/rules/PossibleFragmentSpreadsRule.js +91 -0
  318. package/validation/rules/PossibleFragmentSpreadsRule.mjs +69 -0
  319. package/validation/rules/PossibleTypeExtensionsRule.d.ts +10 -0
  320. package/validation/rules/PossibleTypeExtensionsRule.js +167 -0
  321. package/validation/rules/PossibleTypeExtensionsRule.mjs +147 -0
  322. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +20 -0
  323. package/validation/rules/ProvidedRequiredArgumentsRule.js +158 -0
  324. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +138 -0
  325. package/validation/rules/ScalarLeafsRule.d.ts +9 -0
  326. package/validation/rules/ScalarLeafsRule.js +51 -0
  327. package/validation/rules/ScalarLeafsRule.mjs +42 -0
  328. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +13 -0
  329. package/validation/rules/SingleFieldSubscriptionsRule.js +82 -0
  330. package/validation/rules/SingleFieldSubscriptionsRule.mjs +73 -0
  331. package/validation/rules/UniqueArgumentDefinitionNamesRule.d.ts +11 -0
  332. package/validation/rules/UniqueArgumentDefinitionNamesRule.js +90 -0
  333. package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +79 -0
  334. package/validation/rules/UniqueArgumentNamesRule.d.ts +13 -0
  335. package/validation/rules/UniqueArgumentNamesRule.js +53 -0
  336. package/validation/rules/UniqueArgumentNamesRule.mjs +42 -0
  337. package/validation/rules/UniqueDirectiveNamesRule.d.ts +10 -0
  338. package/validation/rules/UniqueDirectiveNamesRule.js +50 -0
  339. package/validation/rules/UniqueDirectiveNamesRule.mjs +43 -0
  340. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +16 -0
  341. package/validation/rules/UniqueDirectivesPerLocationRule.js +93 -0
  342. package/validation/rules/UniqueDirectivesPerLocationRule.mjs +83 -0
  343. package/validation/rules/UniqueEnumValueNamesRule.d.ts +10 -0
  344. package/validation/rules/UniqueEnumValueNamesRule.js +71 -0
  345. package/validation/rules/UniqueEnumValueNamesRule.mjs +60 -0
  346. package/validation/rules/UniqueFieldDefinitionNamesRule.d.ts +10 -0
  347. package/validation/rules/UniqueFieldDefinitionNamesRule.js +83 -0
  348. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +75 -0
  349. package/validation/rules/UniqueFragmentNamesRule.d.ts +12 -0
  350. package/validation/rules/UniqueFragmentNamesRule.js +39 -0
  351. package/validation/rules/UniqueFragmentNamesRule.mjs +32 -0
  352. package/validation/rules/UniqueInputFieldNamesRule.d.ts +13 -0
  353. package/validation/rules/UniqueInputFieldNamesRule.js +52 -0
  354. package/validation/rules/UniqueInputFieldNamesRule.mjs +44 -0
  355. package/validation/rules/UniqueOperationNamesRule.d.ts +12 -0
  356. package/validation/rules/UniqueOperationNamesRule.js +41 -0
  357. package/validation/rules/UniqueOperationNamesRule.mjs +34 -0
  358. package/validation/rules/UniqueOperationTypesRule.d.ts +10 -0
  359. package/validation/rules/UniqueOperationTypesRule.js +67 -0
  360. package/validation/rules/UniqueOperationTypesRule.mjs +60 -0
  361. package/validation/rules/UniqueTypeNamesRule.d.ts +10 -0
  362. package/validation/rules/UniqueTypeNamesRule.js +53 -0
  363. package/validation/rules/UniqueTypeNamesRule.mjs +46 -0
  364. package/validation/rules/UniqueVariableNamesRule.d.ts +10 -0
  365. package/validation/rules/UniqueVariableNamesRule.js +47 -0
  366. package/validation/rules/UniqueVariableNamesRule.mjs +39 -0
  367. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +13 -0
  368. package/validation/rules/ValuesOfCorrectTypeRule.js +183 -0
  369. package/validation/rules/ValuesOfCorrectTypeRule.mjs +164 -0
  370. package/validation/rules/VariablesAreInputTypesRule.d.ts +13 -0
  371. package/validation/rules/VariablesAreInputTypesRule.js +44 -0
  372. package/validation/rules/VariablesAreInputTypesRule.mjs +31 -0
  373. package/validation/rules/VariablesInAllowedPositionRule.d.ts +12 -0
  374. package/validation/rules/VariablesInAllowedPositionRule.js +114 -0
  375. package/validation/rules/VariablesInAllowedPositionRule.mjs +95 -0
  376. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +15 -0
  377. package/validation/rules/custom/NoDeprecatedCustomRule.js +121 -0
  378. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +107 -0
  379. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +15 -0
  380. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +39 -0
  381. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +30 -0
  382. package/validation/specifiedRules.d.ts +12 -0
  383. package/validation/specifiedRules.js +160 -0
  384. package/validation/specifiedRules.mjs +123 -0
  385. package/validation/validate.d.ts +61 -0
  386. package/validation/validate.js +151 -0
  387. package/validation/validate.mjs +133 -0
  388. package/version.d.ts +13 -0
  389. package/version.js +25 -0
  390. package/version.mjs +17 -0
@@ -0,0 +1,988 @@
1
+ import { devAssert } from '../jsutils/devAssert.mjs';
2
+ import { inspect } from '../jsutils/inspect.mjs';
3
+ import { invariant } from '../jsutils/invariant.mjs';
4
+ import { isIterableObject } from '../jsutils/isIterableObject.mjs';
5
+ import { isObjectLike } from '../jsutils/isObjectLike.mjs';
6
+ import { isPromise } from '../jsutils/isPromise.mjs';
7
+ import { memoize3 } from '../jsutils/memoize3.mjs';
8
+ import { addPath, pathToArray } from '../jsutils/Path.mjs';
9
+ import { promiseForObject } from '../jsutils/promiseForObject.mjs';
10
+ import { promiseReduce } from '../jsutils/promiseReduce.mjs';
11
+ import { GraphQLError } from '../error/GraphQLError.mjs';
12
+ import { locatedError } from '../error/locatedError.mjs';
13
+ import { OperationTypeNode } from '../language/ast.mjs';
14
+ import { Kind } from '../language/kinds.mjs';
15
+ import {
16
+ isAbstractType,
17
+ isLeafType,
18
+ isListType,
19
+ isNonNullType,
20
+ isObjectType,
21
+ } from '../type/definition.mjs';
22
+ import {
23
+ SchemaMetaFieldDef,
24
+ TypeMetaFieldDef,
25
+ TypeNameMetaFieldDef,
26
+ } from '../type/introspection.mjs';
27
+ import { assertValidSchema } from '../type/validate.mjs';
28
+ import {
29
+ collectFields,
30
+ collectSubfields as _collectSubfields,
31
+ } from './collectFields.mjs';
32
+ import { getArgumentValues, getVariableValues } from './values.mjs';
33
+ /**
34
+ * A memoized collection of relevant subfields with regard to the return
35
+ * type. Memoizing ensures the subfields are not repeatedly calculated, which
36
+ * saves overhead when resolving lists of values.
37
+ */
38
+
39
+ const collectSubfields = memoize3((exeContext, returnType, fieldNodes) =>
40
+ _collectSubfields(
41
+ exeContext.schema,
42
+ exeContext.fragments,
43
+ exeContext.variableValues,
44
+ returnType,
45
+ fieldNodes,
46
+ ),
47
+ );
48
+ /**
49
+ * Terminology
50
+ *
51
+ * "Definitions" are the generic name for top-level statements in the document.
52
+ * Examples of this include:
53
+ * 1) Operations (such as a query)
54
+ * 2) Fragments
55
+ *
56
+ * "Operations" are a generic name for requests in the document.
57
+ * Examples of this include:
58
+ * 1) query,
59
+ * 2) mutation
60
+ *
61
+ * "Selections" are the definitions that can appear legally and at
62
+ * single level of the query. These include:
63
+ * 1) field references e.g `a`
64
+ * 2) fragment "spreads" e.g. `...c`
65
+ * 3) inline fragment "spreads" e.g. `...on Type { a }`
66
+ */
67
+
68
+ /**
69
+ * Data that must be available at all points during query execution.
70
+ *
71
+ * Namely, schema of the type system that is currently executing,
72
+ * and the fragments defined in the query document
73
+ */
74
+
75
+ /**
76
+ * Implements the "Executing requests" section of the GraphQL specification.
77
+ *
78
+ * Returns either a synchronous ExecutionResult (if all encountered resolvers
79
+ * are synchronous), or a Promise of an ExecutionResult that will eventually be
80
+ * resolved and never rejected.
81
+ *
82
+ * If the arguments to this function do not result in a legal execution context,
83
+ * a GraphQLError will be thrown immediately explaining the invalid input.
84
+ */
85
+ export function execute(args) {
86
+ // Temporary for v15 to v16 migration. Remove in v17
87
+ arguments.length < 2 ||
88
+ devAssert(
89
+ false,
90
+ 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
91
+ );
92
+ const { schema, document, variableValues, rootValue } = args; // If arguments are missing or incorrect, throw an error.
93
+
94
+ assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
95
+ // a "Response" with only errors is returned.
96
+
97
+ const exeContext = buildExecutionContext(args); // Return early errors if execution context failed.
98
+
99
+ if (!('schema' in exeContext)) {
100
+ return {
101
+ errors: exeContext,
102
+ };
103
+ } // Return a Promise that will eventually resolve to the data described by
104
+ // The "Response" section of the GraphQL specification.
105
+ //
106
+ // If errors are encountered while executing a GraphQL field, only that
107
+ // field and its descendants will be omitted, and sibling fields will still
108
+ // be executed. An execution which encounters errors will still result in a
109
+ // resolved Promise.
110
+ //
111
+ // Errors from sub-fields of a NonNull type may propagate to the top level,
112
+ // at which point we still log the error and null the parent field, which
113
+ // in this case is the entire response.
114
+
115
+ try {
116
+ const { operation } = exeContext;
117
+ const result = executeOperation(exeContext, operation, rootValue);
118
+
119
+ if (isPromise(result)) {
120
+ return result.then(
121
+ (data) => buildResponse(data, exeContext.errors),
122
+ (error) => {
123
+ exeContext.errors.push(error);
124
+ return buildResponse(null, exeContext.errors);
125
+ },
126
+ );
127
+ }
128
+
129
+ return buildResponse(result, exeContext.errors);
130
+ } catch (error) {
131
+ exeContext.errors.push(error);
132
+ return buildResponse(null, exeContext.errors);
133
+ }
134
+ }
135
+ /**
136
+ * Also implements the "Executing requests" section of the GraphQL specification.
137
+ * However, it guarantees to complete synchronously (or throw an error) assuming
138
+ * that all field resolvers are also synchronous.
139
+ */
140
+
141
+ export function executeSync(args) {
142
+ const result = execute(args); // Assert that the execution was synchronous.
143
+
144
+ if (isPromise(result)) {
145
+ throw new Error('GraphQL execution failed to complete synchronously.');
146
+ }
147
+
148
+ return result;
149
+ }
150
+ /**
151
+ * Given a completed execution context and data, build the `{ errors, data }`
152
+ * response defined by the "Response" section of the GraphQL specification.
153
+ */
154
+
155
+ function buildResponse(data, errors) {
156
+ return errors.length === 0
157
+ ? {
158
+ data,
159
+ }
160
+ : {
161
+ errors,
162
+ data,
163
+ };
164
+ }
165
+ /**
166
+ * Essential assertions before executing to provide developer feedback for
167
+ * improper use of the GraphQL library.
168
+ *
169
+ * @internal
170
+ */
171
+
172
+ export function assertValidExecutionArguments(
173
+ schema,
174
+ document,
175
+ rawVariableValues,
176
+ ) {
177
+ document || devAssert(false, 'Must provide document.'); // If the schema used for execution is invalid, throw an error.
178
+
179
+ assertValidSchema(schema); // Variables, if provided, must be an object.
180
+
181
+ rawVariableValues == null ||
182
+ isObjectLike(rawVariableValues) ||
183
+ devAssert(
184
+ false,
185
+ 'Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided.',
186
+ );
187
+ }
188
+ /**
189
+ * Constructs a ExecutionContext object from the arguments passed to
190
+ * execute, which we will pass throughout the other execution methods.
191
+ *
192
+ * Throws a GraphQLError if a valid execution context cannot be created.
193
+ *
194
+ * @internal
195
+ */
196
+
197
+ export function buildExecutionContext(args) {
198
+ var _definition$name, _operation$variableDe;
199
+
200
+ const {
201
+ schema,
202
+ document,
203
+ rootValue,
204
+ contextValue,
205
+ variableValues: rawVariableValues,
206
+ operationName,
207
+ fieldResolver,
208
+ typeResolver,
209
+ subscribeFieldResolver,
210
+ } = args;
211
+ let operation;
212
+ const fragments = Object.create(null);
213
+
214
+ for (const definition of document.definitions) {
215
+ switch (definition.kind) {
216
+ case Kind.OPERATION_DEFINITION:
217
+ if (operationName == null) {
218
+ if (operation !== undefined) {
219
+ return [
220
+ new GraphQLError(
221
+ 'Must provide operation name if query contains multiple operations.',
222
+ ),
223
+ ];
224
+ }
225
+
226
+ operation = definition;
227
+ } else if (
228
+ ((_definition$name = definition.name) === null ||
229
+ _definition$name === void 0
230
+ ? void 0
231
+ : _definition$name.value) === operationName
232
+ ) {
233
+ operation = definition;
234
+ }
235
+
236
+ break;
237
+
238
+ case Kind.FRAGMENT_DEFINITION:
239
+ fragments[definition.name.value] = definition;
240
+ break;
241
+
242
+ default: // ignore non-executable definitions
243
+ }
244
+ }
245
+
246
+ if (!operation) {
247
+ if (operationName != null) {
248
+ return [new GraphQLError(`Unknown operation named "${operationName}".`)];
249
+ }
250
+
251
+ return [new GraphQLError('Must provide an operation.')];
252
+ } // FIXME: https://github.com/graphql/graphql-js/issues/2203
253
+
254
+ /* c8 ignore next */
255
+
256
+ const variableDefinitions =
257
+ (_operation$variableDe = operation.variableDefinitions) !== null &&
258
+ _operation$variableDe !== void 0
259
+ ? _operation$variableDe
260
+ : [];
261
+ const coercedVariableValues = getVariableValues(
262
+ schema,
263
+ variableDefinitions,
264
+ rawVariableValues !== null && rawVariableValues !== void 0
265
+ ? rawVariableValues
266
+ : {},
267
+ {
268
+ maxErrors: 50,
269
+ },
270
+ );
271
+
272
+ if (coercedVariableValues.errors) {
273
+ return coercedVariableValues.errors;
274
+ }
275
+
276
+ return {
277
+ schema,
278
+ fragments,
279
+ rootValue,
280
+ contextValue,
281
+ operation,
282
+ variableValues: coercedVariableValues.coerced,
283
+ fieldResolver:
284
+ fieldResolver !== null && fieldResolver !== void 0
285
+ ? fieldResolver
286
+ : defaultFieldResolver,
287
+ typeResolver:
288
+ typeResolver !== null && typeResolver !== void 0
289
+ ? typeResolver
290
+ : defaultTypeResolver,
291
+ subscribeFieldResolver:
292
+ subscribeFieldResolver !== null && subscribeFieldResolver !== void 0
293
+ ? subscribeFieldResolver
294
+ : defaultFieldResolver,
295
+ errors: [],
296
+ };
297
+ }
298
+ /**
299
+ * Implements the "Executing operations" section of the spec.
300
+ */
301
+
302
+ function executeOperation(exeContext, operation, rootValue) {
303
+ const rootType = exeContext.schema.getRootType(operation.operation);
304
+
305
+ if (rootType == null) {
306
+ throw new GraphQLError(
307
+ `Schema is not configured to execute ${operation.operation} operation.`,
308
+ operation,
309
+ );
310
+ }
311
+
312
+ const rootFields = collectFields(
313
+ exeContext.schema,
314
+ exeContext.fragments,
315
+ exeContext.variableValues,
316
+ rootType,
317
+ operation.selectionSet,
318
+ );
319
+ const path = undefined;
320
+
321
+ switch (operation.operation) {
322
+ case OperationTypeNode.QUERY:
323
+ return executeFields(exeContext, rootType, rootValue, path, rootFields);
324
+
325
+ case OperationTypeNode.MUTATION:
326
+ return executeFieldsSerially(
327
+ exeContext,
328
+ rootType,
329
+ rootValue,
330
+ path,
331
+ rootFields,
332
+ );
333
+
334
+ case OperationTypeNode.SUBSCRIPTION:
335
+ // TODO: deprecate `subscribe` and move all logic here
336
+ // Temporary solution until we finish merging execute and subscribe together
337
+ return executeFields(exeContext, rootType, rootValue, path, rootFields);
338
+ }
339
+ }
340
+ /**
341
+ * Implements the "Executing selection sets" section of the spec
342
+ * for fields that must be executed serially.
343
+ */
344
+
345
+ function executeFieldsSerially(
346
+ exeContext,
347
+ parentType,
348
+ sourceValue,
349
+ path,
350
+ fields,
351
+ ) {
352
+ return promiseReduce(
353
+ fields.entries(),
354
+ (results, [responseName, fieldNodes]) => {
355
+ const fieldPath = addPath(path, responseName, parentType.name);
356
+ const result = executeField(
357
+ exeContext,
358
+ parentType,
359
+ sourceValue,
360
+ fieldNodes,
361
+ fieldPath,
362
+ );
363
+
364
+ if (result === undefined) {
365
+ return results;
366
+ }
367
+
368
+ if (isPromise(result)) {
369
+ return result.then((resolvedResult) => {
370
+ results[responseName] = resolvedResult;
371
+ return results;
372
+ });
373
+ }
374
+
375
+ results[responseName] = result;
376
+ return results;
377
+ },
378
+ Object.create(null),
379
+ );
380
+ }
381
+ /**
382
+ * Implements the "Executing selection sets" section of the spec
383
+ * for fields that may be executed in parallel.
384
+ */
385
+
386
+ function executeFields(exeContext, parentType, sourceValue, path, fields) {
387
+ const results = Object.create(null);
388
+ let containsPromise = false;
389
+
390
+ for (const [responseName, fieldNodes] of fields.entries()) {
391
+ const fieldPath = addPath(path, responseName, parentType.name);
392
+ const result = executeField(
393
+ exeContext,
394
+ parentType,
395
+ sourceValue,
396
+ fieldNodes,
397
+ fieldPath,
398
+ );
399
+
400
+ if (result !== undefined) {
401
+ results[responseName] = result;
402
+
403
+ if (isPromise(result)) {
404
+ containsPromise = true;
405
+ }
406
+ }
407
+ } // If there are no promises, we can just return the object
408
+
409
+ if (!containsPromise) {
410
+ return results;
411
+ } // Otherwise, results is a map from field name to the result of resolving that
412
+ // field, which is possibly a promise. Return a promise that will return this
413
+ // same map, but with any promises replaced with the values they resolved to.
414
+
415
+ return promiseForObject(results);
416
+ }
417
+ /**
418
+ * Implements the "Executing fields" section of the spec
419
+ * In particular, this function figures out the value that the field returns by
420
+ * calling its resolve function, then calls completeValue to complete promises,
421
+ * serialize scalars, or execute the sub-selection-set for objects.
422
+ */
423
+
424
+ function executeField(exeContext, parentType, source, fieldNodes, path) {
425
+ var _fieldDef$resolve;
426
+
427
+ const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
428
+
429
+ if (!fieldDef) {
430
+ return;
431
+ }
432
+
433
+ const returnType = fieldDef.type;
434
+ const resolveFn =
435
+ (_fieldDef$resolve = fieldDef.resolve) !== null &&
436
+ _fieldDef$resolve !== void 0
437
+ ? _fieldDef$resolve
438
+ : exeContext.fieldResolver;
439
+ const info = buildResolveInfo(
440
+ exeContext,
441
+ fieldDef,
442
+ fieldNodes,
443
+ parentType,
444
+ path,
445
+ ); // Get the resolve function, regardless of if its result is normal or abrupt (error).
446
+
447
+ try {
448
+ // Build a JS object of arguments from the field.arguments AST, using the
449
+ // variables scope to fulfill any variable references.
450
+ // TODO: find a way to memoize, in case this field is within a List type.
451
+ const args = getArgumentValues(
452
+ fieldDef,
453
+ fieldNodes[0],
454
+ exeContext.variableValues,
455
+ ); // The resolve function's optional third argument is a context value that
456
+ // is provided to every resolve function within an execution. It is commonly
457
+ // used to represent an authenticated user, or request-specific caches.
458
+
459
+ const contextValue = exeContext.contextValue;
460
+ const result = resolveFn(source, args, contextValue, info);
461
+ let completed;
462
+
463
+ if (isPromise(result)) {
464
+ completed = result.then((resolved) =>
465
+ completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
466
+ );
467
+ } else {
468
+ completed = completeValue(
469
+ exeContext,
470
+ returnType,
471
+ fieldNodes,
472
+ info,
473
+ path,
474
+ result,
475
+ );
476
+ }
477
+
478
+ if (isPromise(completed)) {
479
+ // Note: we don't rely on a `catch` method, but we do expect "thenable"
480
+ // to take a second callback for the error case.
481
+ return completed.then(undefined, (rawError) => {
482
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
483
+ return handleFieldError(error, returnType, exeContext);
484
+ });
485
+ }
486
+
487
+ return completed;
488
+ } catch (rawError) {
489
+ const error = locatedError(rawError, fieldNodes, pathToArray(path));
490
+ return handleFieldError(error, returnType, exeContext);
491
+ }
492
+ }
493
+ /**
494
+ * @internal
495
+ */
496
+
497
+ export function buildResolveInfo(
498
+ exeContext,
499
+ fieldDef,
500
+ fieldNodes,
501
+ parentType,
502
+ path,
503
+ ) {
504
+ // The resolve function's optional fourth argument is a collection of
505
+ // information about the current execution state.
506
+ return {
507
+ fieldName: fieldDef.name,
508
+ fieldNodes,
509
+ returnType: fieldDef.type,
510
+ parentType,
511
+ path,
512
+ schema: exeContext.schema,
513
+ fragments: exeContext.fragments,
514
+ rootValue: exeContext.rootValue,
515
+ operation: exeContext.operation,
516
+ variableValues: exeContext.variableValues,
517
+ };
518
+ }
519
+
520
+ function handleFieldError(error, returnType, exeContext) {
521
+ // If the field type is non-nullable, then it is resolved without any
522
+ // protection from errors, however it still properly locates the error.
523
+ if (isNonNullType(returnType)) {
524
+ throw error;
525
+ } // Otherwise, error protection is applied, logging the error and resolving
526
+ // a null value for this field if one is encountered.
527
+
528
+ exeContext.errors.push(error);
529
+ return null;
530
+ }
531
+ /**
532
+ * Implements the instructions for completeValue as defined in the
533
+ * "Value Completion" section of the spec.
534
+ *
535
+ * If the field type is Non-Null, then this recursively completes the value
536
+ * for the inner type. It throws a field error if that completion returns null,
537
+ * as per the "Nullability" section of the spec.
538
+ *
539
+ * If the field type is a List, then this recursively completes the value
540
+ * for the inner type on each item in the list.
541
+ *
542
+ * If the field type is a Scalar or Enum, ensures the completed value is a legal
543
+ * value of the type by calling the `serialize` method of GraphQL type
544
+ * definition.
545
+ *
546
+ * If the field is an abstract type, determine the runtime type of the value
547
+ * and then complete based on that type
548
+ *
549
+ * Otherwise, the field type expects a sub-selection set, and will complete the
550
+ * value by executing all sub-selections.
551
+ */
552
+
553
+ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
554
+ // If result is an Error, throw a located error.
555
+ if (result instanceof Error) {
556
+ throw result;
557
+ } // If field type is NonNull, complete for inner type, and throw field error
558
+ // if result is null.
559
+
560
+ if (isNonNullType(returnType)) {
561
+ const completed = completeValue(
562
+ exeContext,
563
+ returnType.ofType,
564
+ fieldNodes,
565
+ info,
566
+ path,
567
+ result,
568
+ );
569
+
570
+ if (completed === null) {
571
+ throw new Error(
572
+ `Cannot return null for non-nullable field ${info.parentType.name}.${info.fieldName}.`,
573
+ );
574
+ }
575
+
576
+ return completed;
577
+ } // If result value is null or undefined then return null.
578
+
579
+ if (result == null) {
580
+ return null;
581
+ } // If field type is List, complete each item in the list with the inner type
582
+
583
+ if (isListType(returnType)) {
584
+ return completeListValue(
585
+ exeContext,
586
+ returnType,
587
+ fieldNodes,
588
+ info,
589
+ path,
590
+ result,
591
+ );
592
+ } // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
593
+ // returning null if serialization is not possible.
594
+
595
+ if (isLeafType(returnType)) {
596
+ return completeLeafValue(returnType, result);
597
+ } // If field type is an abstract type, Interface or Union, determine the
598
+ // runtime Object type and complete for that type.
599
+
600
+ if (isAbstractType(returnType)) {
601
+ return completeAbstractValue(
602
+ exeContext,
603
+ returnType,
604
+ fieldNodes,
605
+ info,
606
+ path,
607
+ result,
608
+ );
609
+ } // If field type is Object, execute and complete all sub-selections.
610
+
611
+ if (isObjectType(returnType)) {
612
+ return completeObjectValue(
613
+ exeContext,
614
+ returnType,
615
+ fieldNodes,
616
+ info,
617
+ path,
618
+ result,
619
+ );
620
+ }
621
+ /* c8 ignore next 6 */
622
+ // Not reachable, all possible output types have been considered.
623
+
624
+ false ||
625
+ invariant(
626
+ false,
627
+ 'Cannot complete value of unexpected output type: ' + inspect(returnType),
628
+ );
629
+ }
630
+ /**
631
+ * Complete a list value by completing each item in the list with the
632
+ * inner type
633
+ */
634
+
635
+ function completeListValue(
636
+ exeContext,
637
+ returnType,
638
+ fieldNodes,
639
+ info,
640
+ path,
641
+ result,
642
+ ) {
643
+ if (!isIterableObject(result)) {
644
+ throw new GraphQLError(
645
+ `Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
646
+ );
647
+ } // This is specified as a simple map, however we're optimizing the path
648
+ // where the list contains no Promises by avoiding creating another Promise.
649
+
650
+ const itemType = returnType.ofType;
651
+ let containsPromise = false;
652
+ const completedResults = Array.from(result, (item, index) => {
653
+ // No need to modify the info object containing the path,
654
+ // since from here on it is not ever accessed by resolver functions.
655
+ const itemPath = addPath(path, index, undefined);
656
+
657
+ try {
658
+ let completedItem;
659
+
660
+ if (isPromise(item)) {
661
+ completedItem = item.then((resolved) =>
662
+ completeValue(
663
+ exeContext,
664
+ itemType,
665
+ fieldNodes,
666
+ info,
667
+ itemPath,
668
+ resolved,
669
+ ),
670
+ );
671
+ } else {
672
+ completedItem = completeValue(
673
+ exeContext,
674
+ itemType,
675
+ fieldNodes,
676
+ info,
677
+ itemPath,
678
+ item,
679
+ );
680
+ }
681
+
682
+ if (isPromise(completedItem)) {
683
+ containsPromise = true; // Note: we don't rely on a `catch` method, but we do expect "thenable"
684
+ // to take a second callback for the error case.
685
+
686
+ return completedItem.then(undefined, (rawError) => {
687
+ const error = locatedError(
688
+ rawError,
689
+ fieldNodes,
690
+ pathToArray(itemPath),
691
+ );
692
+ return handleFieldError(error, itemType, exeContext);
693
+ });
694
+ }
695
+
696
+ return completedItem;
697
+ } catch (rawError) {
698
+ const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
699
+ return handleFieldError(error, itemType, exeContext);
700
+ }
701
+ });
702
+ return containsPromise ? Promise.all(completedResults) : completedResults;
703
+ }
704
+ /**
705
+ * Complete a Scalar or Enum by serializing to a valid value, returning
706
+ * null if serialization is not possible.
707
+ */
708
+
709
+ function completeLeafValue(returnType, result) {
710
+ const serializedResult = returnType.serialize(result);
711
+
712
+ if (serializedResult == null) {
713
+ throw new Error(
714
+ `Expected \`${inspect(returnType)}.serialize(${inspect(result)})\` to ` +
715
+ `return non-nullable value, returned: ${inspect(serializedResult)}`,
716
+ );
717
+ }
718
+
719
+ return serializedResult;
720
+ }
721
+ /**
722
+ * Complete a value of an abstract type by determining the runtime object type
723
+ * of that value, then complete the value for that type.
724
+ */
725
+
726
+ function completeAbstractValue(
727
+ exeContext,
728
+ returnType,
729
+ fieldNodes,
730
+ info,
731
+ path,
732
+ result,
733
+ ) {
734
+ var _returnType$resolveTy;
735
+
736
+ const resolveTypeFn =
737
+ (_returnType$resolveTy = returnType.resolveType) !== null &&
738
+ _returnType$resolveTy !== void 0
739
+ ? _returnType$resolveTy
740
+ : exeContext.typeResolver;
741
+ const contextValue = exeContext.contextValue;
742
+ const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
743
+
744
+ if (isPromise(runtimeType)) {
745
+ return runtimeType.then((resolvedRuntimeType) =>
746
+ completeObjectValue(
747
+ exeContext,
748
+ ensureValidRuntimeType(
749
+ resolvedRuntimeType,
750
+ exeContext,
751
+ returnType,
752
+ fieldNodes,
753
+ info,
754
+ result,
755
+ ),
756
+ fieldNodes,
757
+ info,
758
+ path,
759
+ result,
760
+ ),
761
+ );
762
+ }
763
+
764
+ return completeObjectValue(
765
+ exeContext,
766
+ ensureValidRuntimeType(
767
+ runtimeType,
768
+ exeContext,
769
+ returnType,
770
+ fieldNodes,
771
+ info,
772
+ result,
773
+ ),
774
+ fieldNodes,
775
+ info,
776
+ path,
777
+ result,
778
+ );
779
+ }
780
+
781
+ function ensureValidRuntimeType(
782
+ runtimeTypeName,
783
+ exeContext,
784
+ returnType,
785
+ fieldNodes,
786
+ info,
787
+ result,
788
+ ) {
789
+ if (runtimeTypeName == null) {
790
+ throw new GraphQLError(
791
+ `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.`,
792
+ fieldNodes,
793
+ );
794
+ } // releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType`
795
+ // TODO: remove in 17.0.0 release
796
+
797
+ if (isObjectType(runtimeTypeName)) {
798
+ throw new GraphQLError(
799
+ 'Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.',
800
+ );
801
+ }
802
+
803
+ if (typeof runtimeTypeName !== 'string') {
804
+ throw new GraphQLError(
805
+ `Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
806
+ `value ${inspect(result)}, received "${inspect(runtimeTypeName)}".`,
807
+ );
808
+ }
809
+
810
+ const runtimeType = exeContext.schema.getType(runtimeTypeName);
811
+
812
+ if (runtimeType == null) {
813
+ throw new GraphQLError(
814
+ `Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`,
815
+ fieldNodes,
816
+ );
817
+ }
818
+
819
+ if (!isObjectType(runtimeType)) {
820
+ throw new GraphQLError(
821
+ `Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`,
822
+ fieldNodes,
823
+ );
824
+ }
825
+
826
+ if (!exeContext.schema.isSubType(returnType, runtimeType)) {
827
+ throw new GraphQLError(
828
+ `Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`,
829
+ fieldNodes,
830
+ );
831
+ }
832
+
833
+ return runtimeType;
834
+ }
835
+ /**
836
+ * Complete an Object value by executing all sub-selections.
837
+ */
838
+
839
+ function completeObjectValue(
840
+ exeContext,
841
+ returnType,
842
+ fieldNodes,
843
+ info,
844
+ path,
845
+ result,
846
+ ) {
847
+ // Collect sub-fields to execute to complete this value.
848
+ const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes); // If there is an isTypeOf predicate function, call it with the
849
+ // current result. If isTypeOf returns false, then raise an error rather
850
+ // than continuing execution.
851
+
852
+ if (returnType.isTypeOf) {
853
+ const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
854
+
855
+ if (isPromise(isTypeOf)) {
856
+ return isTypeOf.then((resolvedIsTypeOf) => {
857
+ if (!resolvedIsTypeOf) {
858
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
859
+ }
860
+
861
+ return executeFields(
862
+ exeContext,
863
+ returnType,
864
+ result,
865
+ path,
866
+ subFieldNodes,
867
+ );
868
+ });
869
+ }
870
+
871
+ if (!isTypeOf) {
872
+ throw invalidReturnTypeError(returnType, result, fieldNodes);
873
+ }
874
+ }
875
+
876
+ return executeFields(exeContext, returnType, result, path, subFieldNodes);
877
+ }
878
+
879
+ function invalidReturnTypeError(returnType, result, fieldNodes) {
880
+ return new GraphQLError(
881
+ `Expected value of type "${returnType.name}" but got: ${inspect(result)}.`,
882
+ fieldNodes,
883
+ );
884
+ }
885
+ /**
886
+ * If a resolveType function is not given, then a default resolve behavior is
887
+ * used which attempts two strategies:
888
+ *
889
+ * First, See if the provided value has a `__typename` field defined, if so, use
890
+ * that value as name of the resolved type.
891
+ *
892
+ * Otherwise, test each possible type for the abstract type by calling
893
+ * isTypeOf for the object being coerced, returning the first type that matches.
894
+ */
895
+
896
+ export const defaultTypeResolver = function (
897
+ value,
898
+ contextValue,
899
+ info,
900
+ abstractType,
901
+ ) {
902
+ // First, look for `__typename`.
903
+ if (isObjectLike(value) && typeof value.__typename === 'string') {
904
+ return value.__typename;
905
+ } // Otherwise, test each possible type.
906
+
907
+ const possibleTypes = info.schema.getPossibleTypes(abstractType);
908
+ const promisedIsTypeOfResults = [];
909
+
910
+ for (let i = 0; i < possibleTypes.length; i++) {
911
+ const type = possibleTypes[i];
912
+
913
+ if (type.isTypeOf) {
914
+ const isTypeOfResult = type.isTypeOf(value, contextValue, info);
915
+
916
+ if (isPromise(isTypeOfResult)) {
917
+ promisedIsTypeOfResults[i] = isTypeOfResult;
918
+ } else if (isTypeOfResult) {
919
+ return type.name;
920
+ }
921
+ }
922
+ }
923
+
924
+ if (promisedIsTypeOfResults.length) {
925
+ return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
926
+ for (let i = 0; i < isTypeOfResults.length; i++) {
927
+ if (isTypeOfResults[i]) {
928
+ return possibleTypes[i].name;
929
+ }
930
+ }
931
+ });
932
+ }
933
+ };
934
+ /**
935
+ * If a resolve function is not given, then a default resolve behavior is used
936
+ * which takes the property of the source object of the same name as the field
937
+ * and returns it as the result, or if it's a function, returns the result
938
+ * of calling that function while passing along args and context value.
939
+ */
940
+
941
+ export const defaultFieldResolver = function (
942
+ source,
943
+ args,
944
+ contextValue,
945
+ info,
946
+ ) {
947
+ // ensure source is a value for which property access is acceptable.
948
+ if (isObjectLike(source) || typeof source === 'function') {
949
+ const property = source[info.fieldName];
950
+
951
+ if (typeof property === 'function') {
952
+ return source[info.fieldName](args, contextValue, info);
953
+ }
954
+
955
+ return property;
956
+ }
957
+ };
958
+ /**
959
+ * This method looks up the field on the given type definition.
960
+ * It has special casing for the three introspection fields,
961
+ * __schema, __type and __typename. __typename is special because
962
+ * it can always be queried as a field, even in situations where no
963
+ * other fields are allowed, like on a Union. __schema and __type
964
+ * could get automatically added to the query type, but that would
965
+ * require mutating type definitions, which would cause issues.
966
+ *
967
+ * @internal
968
+ */
969
+
970
+ export function getFieldDef(schema, parentType, fieldNode) {
971
+ const fieldName = fieldNode.name.value;
972
+
973
+ if (
974
+ fieldName === SchemaMetaFieldDef.name &&
975
+ schema.getQueryType() === parentType
976
+ ) {
977
+ return SchemaMetaFieldDef;
978
+ } else if (
979
+ fieldName === TypeMetaFieldDef.name &&
980
+ schema.getQueryType() === parentType
981
+ ) {
982
+ return TypeMetaFieldDef;
983
+ } else if (fieldName === TypeNameMetaFieldDef.name) {
984
+ return TypeNameMetaFieldDef;
985
+ }
986
+
987
+ return parentType.getFields()[fieldName];
988
+ }