graphql 14.4.2 → 14.5.3

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/README.md +5 -10
  2. package/error/GraphQLError.d.ts +87 -0
  3. package/error/GraphQLError.js +7 -45
  4. package/error/GraphQLError.js.flow +1 -0
  5. package/error/GraphQLError.mjs +7 -45
  6. package/error/formatError.d.ts +39 -0
  7. package/error/formatError.js +5 -2
  8. package/error/formatError.js.flow +27 -3
  9. package/error/formatError.mjs +5 -2
  10. package/error/index.d.ts +4 -0
  11. package/error/locatedError.d.ts +13 -0
  12. package/error/locatedError.js.flow +2 -1
  13. package/error/locatedError.mjs +1 -1
  14. package/error/syntaxError.d.ts +12 -0
  15. package/error/syntaxError.js.flow +1 -0
  16. package/execution/execute.d.ts +190 -0
  17. package/execution/execute.js +55 -89
  18. package/execution/execute.js.flow +95 -133
  19. package/execution/execute.mjs +75 -80
  20. package/execution/index.d.ts +11 -0
  21. package/execution/index.js +8 -6
  22. package/execution/index.js.flow +3 -6
  23. package/execution/index.mjs +2 -1
  24. package/execution/values.d.ts +68 -0
  25. package/execution/values.js +119 -128
  26. package/execution/values.js.flow +150 -127
  27. package/execution/values.mjs +117 -125
  28. package/graphql.d.ts +88 -0
  29. package/graphql.js +5 -5
  30. package/graphql.js.flow +9 -5
  31. package/graphql.mjs +41 -1
  32. package/index.d.ts +446 -0
  33. package/index.js +6 -0
  34. package/index.js.flow +3 -1
  35. package/index.mjs +2 -1
  36. package/jsutils/ObjMap.js.flow +6 -0
  37. package/jsutils/Path.d.ts +14 -0
  38. package/jsutils/Path.js +33 -0
  39. package/jsutils/Path.js.flow +26 -0
  40. package/jsutils/Path.mjs +24 -0
  41. package/jsutils/PromiseOrValue.d.ts +1 -0
  42. package/jsutils/dedent.js +6 -24
  43. package/jsutils/dedent.mjs +6 -24
  44. package/jsutils/defineToStringTag.js.flow +1 -1
  45. package/jsutils/devAssert.js +14 -0
  46. package/jsutils/devAssert.js.flow +8 -0
  47. package/jsutils/devAssert.mjs +7 -0
  48. package/jsutils/inspect.js +1 -1
  49. package/jsutils/inspect.js.flow +1 -1
  50. package/jsutils/inspect.mjs +1 -1
  51. package/jsutils/invariant.js +1 -2
  52. package/jsutils/invariant.js.flow +2 -3
  53. package/jsutils/invariant.mjs +1 -2
  54. package/jsutils/mapValue.js +6 -24
  55. package/jsutils/mapValue.js.flow +2 -1
  56. package/jsutils/mapValue.mjs +6 -24
  57. package/jsutils/printPathArray.js +15 -0
  58. package/jsutils/printPathArray.js.flow +14 -0
  59. package/jsutils/printPathArray.mjs +8 -0
  60. package/jsutils/suggestionList.js +14 -34
  61. package/jsutils/suggestionList.js.flow +4 -6
  62. package/jsutils/suggestionList.mjs +14 -34
  63. package/jsutils/toObjMap.js +28 -0
  64. package/jsutils/toObjMap.js.flow +26 -0
  65. package/jsutils/toObjMap.mjs +18 -0
  66. package/language/ast.d.ts +573 -0
  67. package/language/blockString.d.ts +21 -0
  68. package/language/directiveLocation.d.ts +35 -0
  69. package/language/index.d.ts +96 -0
  70. package/language/kinds.d.ts +77 -0
  71. package/language/lexer.d.ts +60 -0
  72. package/language/lexer.js +2 -12
  73. package/language/lexer.js.flow +6 -12
  74. package/language/lexer.mjs +1 -9
  75. package/language/location.d.ts +15 -0
  76. package/language/parser.d.ts +89 -0
  77. package/language/parser.js +1329 -1302
  78. package/language/parser.js.flow +1289 -1298
  79. package/language/parser.mjs +1326 -1297
  80. package/language/predicates.d.ts +36 -0
  81. package/language/predicates.js.flow +1 -1
  82. package/language/printLocation.d.ts +16 -0
  83. package/language/printLocation.js.flow +1 -1
  84. package/language/printer.d.ts +7 -0
  85. package/language/printer.js.flow +1 -1
  86. package/language/source.d.ts +19 -0
  87. package/language/source.js +3 -3
  88. package/language/source.js.flow +3 -3
  89. package/language/source.mjs +3 -3
  90. package/language/tokenKind.d.ts +35 -0
  91. package/language/visitor.d.ts +264 -0
  92. package/language/visitor.js +2 -2
  93. package/language/visitor.js.flow +3 -1
  94. package/language/visitor.mjs +2 -2
  95. package/package.json +1 -1
  96. package/polyfills/find.js +2 -2
  97. package/polyfills/find.js.flow +1 -2
  98. package/polyfills/find.mjs +2 -2
  99. package/polyfills/flatMap.js +3 -3
  100. package/polyfills/flatMap.js.flow +2 -3
  101. package/polyfills/flatMap.mjs +3 -3
  102. package/subscription/asyncIteratorReject.d.ts +6 -0
  103. package/subscription/index.d.ts +5 -0
  104. package/subscription/mapAsyncIterator.d.ts +9 -0
  105. package/subscription/mapAsyncIterator.js.flow +1 -0
  106. package/subscription/subscribe.d.ts +86 -0
  107. package/subscription/subscribe.js +29 -10
  108. package/subscription/subscribe.js.flow +45 -24
  109. package/subscription/subscribe.mjs +27 -9
  110. package/tsutils/Maybe.d.ts +4 -0
  111. package/type/definition.d.ts +805 -0
  112. package/type/definition.js +154 -70
  113. package/type/definition.js.flow +217 -160
  114. package/type/definition.mjs +149 -66
  115. package/type/directives.d.ts +72 -0
  116. package/type/directives.js +20 -12
  117. package/type/directives.js.flow +34 -19
  118. package/type/directives.mjs +17 -10
  119. package/type/index.d.ts +155 -0
  120. package/type/index.js.flow +2 -2
  121. package/type/introspection.d.ts +40 -0
  122. package/type/introspection.js +24 -10
  123. package/type/introspection.js.flow +29 -8
  124. package/type/introspection.mjs +23 -10
  125. package/type/scalars.d.ts +11 -0
  126. package/type/scalars.js +2 -2
  127. package/type/scalars.js.flow +4 -1
  128. package/type/scalars.mjs +2 -2
  129. package/type/schema.d.ts +108 -0
  130. package/type/schema.js +74 -151
  131. package/type/schema.js.flow +75 -73
  132. package/type/schema.mjs +75 -149
  133. package/type/validate.d.ts +19 -0
  134. package/type/validate.js +227 -486
  135. package/type/validate.js.flow +13 -8
  136. package/type/validate.mjs +218 -477
  137. package/utilities/TypeInfo.d.ts +49 -0
  138. package/utilities/TypeInfo.js.flow +9 -6
  139. package/utilities/assertValidName.d.ts +15 -0
  140. package/utilities/assertValidName.js +3 -3
  141. package/utilities/assertValidName.js.flow +3 -2
  142. package/utilities/assertValidName.mjs +2 -2
  143. package/utilities/astFromValue.d.ts +25 -0
  144. package/utilities/astFromValue.js +22 -38
  145. package/utilities/astFromValue.js.flow +7 -4
  146. package/utilities/astFromValue.mjs +19 -36
  147. package/utilities/buildASTSchema.d.ts +114 -0
  148. package/utilities/buildASTSchema.js +37 -68
  149. package/utilities/buildASTSchema.js.flow +32 -30
  150. package/utilities/buildASTSchema.mjs +32 -64
  151. package/utilities/buildClientSchema.d.ts +21 -0
  152. package/utilities/buildClientSchema.js +23 -15
  153. package/utilities/buildClientSchema.js.flow +17 -16
  154. package/utilities/buildClientSchema.mjs +20 -12
  155. package/utilities/coerceInputValue.d.ts +17 -0
  156. package/utilities/coerceInputValue.js +161 -0
  157. package/utilities/coerceInputValue.js.flow +214 -0
  158. package/utilities/coerceInputValue.mjs +142 -0
  159. package/utilities/coerceValue.d.ts +23 -0
  160. package/utilities/coerceValue.js +21 -199
  161. package/utilities/coerceValue.js.flow +31 -223
  162. package/utilities/coerceValue.mjs +20 -195
  163. package/utilities/concatAST.d.ts +8 -0
  164. package/utilities/concatAST.js.flow +1 -0
  165. package/utilities/extendSchema.d.ts +45 -0
  166. package/utilities/extendSchema.js +64 -131
  167. package/utilities/extendSchema.js.flow +27 -24
  168. package/utilities/extendSchema.mjs +61 -129
  169. package/utilities/findBreakingChanges.d.ts +64 -0
  170. package/utilities/findBreakingChanges.js +194 -619
  171. package/utilities/findBreakingChanges.js.flow +8 -5
  172. package/utilities/findBreakingChanges.mjs +194 -619
  173. package/utilities/findDeprecatedUsages.d.ts +13 -0
  174. package/utilities/findDeprecatedUsages.js.flow +4 -1
  175. package/utilities/getOperationAST.d.ts +12 -0
  176. package/utilities/getOperationAST.js +13 -31
  177. package/utilities/getOperationAST.mjs +13 -31
  178. package/utilities/getOperationRootType.d.ts +14 -0
  179. package/utilities/getOperationRootType.js.flow +2 -0
  180. package/utilities/index.d.ts +127 -0
  181. package/utilities/index.js +8 -0
  182. package/utilities/index.js.flow +4 -1
  183. package/utilities/index.mjs +3 -1
  184. package/utilities/introspectionFromSchema.d.ts +16 -0
  185. package/utilities/introspectionFromSchema.js +5 -3
  186. package/utilities/introspectionFromSchema.js.flow +4 -2
  187. package/utilities/introspectionFromSchema.mjs +4 -2
  188. package/utilities/introspectionQuery.d.ts +177 -0
  189. package/utilities/isValidJSValue.d.ts +8 -0
  190. package/utilities/isValidJSValue.js +1 -1
  191. package/utilities/isValidJSValue.js.flow +3 -2
  192. package/utilities/isValidJSValue.mjs +2 -2
  193. package/utilities/isValidLiteralValue.d.ts +15 -0
  194. package/utilities/isValidLiteralValue.js +4 -4
  195. package/utilities/isValidLiteralValue.js.flow +8 -4
  196. package/utilities/isValidLiteralValue.mjs +2 -2
  197. package/utilities/lexicographicSortSchema.d.ts +6 -0
  198. package/utilities/lexicographicSortSchema.js +11 -8
  199. package/utilities/lexicographicSortSchema.js.flow +5 -3
  200. package/utilities/lexicographicSortSchema.mjs +9 -7
  201. package/utilities/schemaPrinter.d.ts +30 -0
  202. package/utilities/schemaPrinter.js +15 -32
  203. package/utilities/schemaPrinter.js.flow +14 -10
  204. package/utilities/schemaPrinter.mjs +14 -32
  205. package/utilities/separateOperations.d.ts +11 -0
  206. package/utilities/separateOperations.js +6 -6
  207. package/utilities/separateOperations.js.flow +2 -1
  208. package/utilities/separateOperations.mjs +6 -6
  209. package/utilities/stripIgnoredCharacters.d.ts +55 -0
  210. package/utilities/stripIgnoredCharacters.js.flow +1 -0
  211. package/utilities/typeComparators.d.ts +32 -0
  212. package/utilities/typeComparators.js.flow +1 -1
  213. package/utilities/typeComparators.mjs +1 -1
  214. package/utilities/typeFromAST.d.ts +29 -0
  215. package/utilities/typeFromAST.js +5 -3
  216. package/utilities/typeFromAST.js.flow +5 -3
  217. package/utilities/typeFromAST.mjs +14 -3
  218. package/utilities/valueFromAST.d.ts +29 -0
  219. package/utilities/valueFromAST.js +40 -74
  220. package/utilities/valueFromAST.js.flow +7 -4
  221. package/utilities/valueFromAST.mjs +39 -74
  222. package/utilities/valueFromASTUntyped.d.ts +23 -0
  223. package/utilities/valueFromASTUntyped.js +4 -3
  224. package/utilities/valueFromASTUntyped.js.flow +3 -2
  225. package/utilities/valueFromASTUntyped.mjs +3 -3
  226. package/validation/ValidationContext.d.ts +96 -0
  227. package/validation/ValidationContext.js +38 -86
  228. package/validation/ValidationContext.js.flow +22 -7
  229. package/validation/ValidationContext.mjs +37 -85
  230. package/validation/index.d.ts +126 -0
  231. package/validation/rules/ExecutableDefinitions.d.ts +14 -0
  232. package/validation/rules/ExecutableDefinitions.js +4 -23
  233. package/validation/rules/ExecutableDefinitions.js.flow +4 -2
  234. package/validation/rules/ExecutableDefinitions.mjs +4 -23
  235. package/validation/rules/FieldsOnCorrectType.d.ts +17 -0
  236. package/validation/rules/FieldsOnCorrectType.js +21 -57
  237. package/validation/rules/FieldsOnCorrectType.js.flow +7 -3
  238. package/validation/rules/FieldsOnCorrectType.mjs +21 -57
  239. package/validation/rules/FragmentsOnCompositeTypes.d.ts +20 -0
  240. package/validation/rules/FragmentsOnCompositeTypes.js.flow +5 -1
  241. package/validation/rules/KnownArgumentNames.d.ts +28 -0
  242. package/validation/rules/KnownArgumentNames.js +26 -79
  243. package/validation/rules/KnownArgumentNames.js.flow +10 -6
  244. package/validation/rules/KnownArgumentNames.mjs +22 -75
  245. package/validation/rules/KnownDirectives.d.ts +19 -0
  246. package/validation/rules/KnownDirectives.js +12 -48
  247. package/validation/rules/KnownDirectives.js.flow +8 -5
  248. package/validation/rules/KnownDirectives.mjs +12 -48
  249. package/validation/rules/KnownFragmentNames.d.ts +12 -0
  250. package/validation/rules/KnownFragmentNames.js.flow +2 -1
  251. package/validation/rules/KnownTypeNames.d.ts +15 -0
  252. package/validation/rules/KnownTypeNames.js +6 -24
  253. package/validation/rules/KnownTypeNames.js.flow +10 -6
  254. package/validation/rules/KnownTypeNames.mjs +6 -24
  255. package/validation/rules/LoneAnonymousOperation.d.ts +14 -0
  256. package/validation/rules/LoneAnonymousOperation.js.flow +3 -1
  257. package/validation/rules/LoneSchemaDefinition.d.ts +13 -0
  258. package/validation/rules/LoneSchemaDefinition.js.flow +2 -1
  259. package/validation/rules/NoFragmentCycles.d.ts +9 -0
  260. package/validation/rules/NoFragmentCycles.js +17 -35
  261. package/validation/rules/NoFragmentCycles.js.flow +4 -2
  262. package/validation/rules/NoFragmentCycles.mjs +17 -35
  263. package/validation/rules/NoUndefinedVariables.d.ts +16 -0
  264. package/validation/rules/NoUndefinedVariables.js +6 -24
  265. package/validation/rules/NoUndefinedVariables.js.flow +2 -1
  266. package/validation/rules/NoUndefinedVariables.mjs +6 -24
  267. package/validation/rules/NoUnusedFragments.d.ts +12 -0
  268. package/validation/rules/NoUnusedFragments.js +7 -25
  269. package/validation/rules/NoUnusedFragments.js.flow +2 -1
  270. package/validation/rules/NoUnusedFragments.mjs +7 -25
  271. package/validation/rules/NoUnusedVariables.d.ts +16 -0
  272. package/validation/rules/NoUnusedVariables.js +6 -24
  273. package/validation/rules/NoUnusedVariables.js.flow +2 -1
  274. package/validation/rules/NoUnusedVariables.mjs +6 -24
  275. package/validation/rules/OverlappingFieldsCanBeMerged.d.ts +24 -0
  276. package/validation/rules/OverlappingFieldsCanBeMerged.js +27 -46
  277. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +17 -8
  278. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +25 -44
  279. package/validation/rules/PossibleFragmentSpreads.d.ts +22 -0
  280. package/validation/rules/PossibleFragmentSpreads.js +2 -2
  281. package/validation/rules/PossibleFragmentSpreads.js.flow +8 -3
  282. package/validation/rules/PossibleFragmentSpreads.mjs +2 -2
  283. package/validation/rules/PossibleTypeExtensions.d.ts +21 -0
  284. package/validation/rules/PossibleTypeExtensions.js +4 -22
  285. package/validation/rules/PossibleTypeExtensions.js.flow +6 -2
  286. package/validation/rules/PossibleTypeExtensions.mjs +4 -22
  287. package/validation/rules/ProvidedRequiredArguments.d.ts +29 -0
  288. package/validation/rules/ProvidedRequiredArguments.js +27 -79
  289. package/validation/rules/ProvidedRequiredArguments.js.flow +12 -8
  290. package/validation/rules/ProvidedRequiredArguments.mjs +25 -77
  291. package/validation/rules/ScalarLeafs.d.ts +20 -0
  292. package/validation/rules/ScalarLeafs.js.flow +6 -2
  293. package/validation/rules/SingleFieldSubscriptions.d.ts +14 -0
  294. package/validation/rules/SingleFieldSubscriptions.js.flow +4 -2
  295. package/validation/rules/UniqueArgumentNames.d.ts +12 -0
  296. package/validation/rules/UniqueArgumentNames.js.flow +2 -1
  297. package/validation/rules/UniqueDirectiveNames.d.ts +13 -0
  298. package/validation/rules/UniqueDirectiveNames.js.flow +2 -1
  299. package/validation/rules/UniqueDirectivesPerLocation.d.ts +14 -0
  300. package/validation/rules/UniqueDirectivesPerLocation.js +15 -69
  301. package/validation/rules/UniqueDirectivesPerLocation.js.flow +7 -4
  302. package/validation/rules/UniqueDirectivesPerLocation.mjs +15 -69
  303. package/validation/rules/UniqueEnumValueNames.d.ts +19 -0
  304. package/validation/rules/UniqueEnumValueNames.js +10 -28
  305. package/validation/rules/UniqueEnumValueNames.js.flow +2 -1
  306. package/validation/rules/UniqueEnumValueNames.mjs +10 -28
  307. package/validation/rules/UniqueFieldDefinitionNames.d.ts +21 -0
  308. package/validation/rules/UniqueFieldDefinitionNames.js +9 -27
  309. package/validation/rules/UniqueFieldDefinitionNames.js.flow +2 -1
  310. package/validation/rules/UniqueFieldDefinitionNames.mjs +9 -27
  311. package/validation/rules/UniqueFragmentNames.d.ts +11 -0
  312. package/validation/rules/UniqueFragmentNames.js.flow +2 -1
  313. package/validation/rules/UniqueInputFieldNames.d.ts +14 -0
  314. package/validation/rules/UniqueInputFieldNames.js.flow +2 -1
  315. package/validation/rules/UniqueOperationNames.d.ts +11 -0
  316. package/validation/rules/UniqueOperationNames.js.flow +2 -1
  317. package/validation/rules/UniqueOperationTypes.d.ts +13 -0
  318. package/validation/rules/UniqueOperationTypes.js +11 -30
  319. package/validation/rules/UniqueOperationTypes.js.flow +2 -1
  320. package/validation/rules/UniqueOperationTypes.mjs +10 -29
  321. package/validation/rules/UniqueTypeNames.d.ts +13 -0
  322. package/validation/rules/UniqueTypeNames.js.flow +3 -1
  323. package/validation/rules/UniqueVariableNames.d.ts +11 -0
  324. package/validation/rules/UniqueVariableNames.js.flow +4 -2
  325. package/validation/rules/ValuesOfCorrectType.d.ts +34 -0
  326. package/validation/rules/ValuesOfCorrectType.js +16 -34
  327. package/validation/rules/ValuesOfCorrectType.js.flow +11 -6
  328. package/validation/rules/ValuesOfCorrectType.mjs +12 -30
  329. package/validation/rules/VariablesAreInputTypes.d.ts +15 -0
  330. package/validation/rules/VariablesAreInputTypes.js.flow +6 -2
  331. package/validation/rules/VariablesInAllowedPosition.d.ts +15 -0
  332. package/validation/rules/VariablesInAllowedPosition.js +22 -40
  333. package/validation/rules/VariablesInAllowedPosition.js.flow +8 -3
  334. package/validation/rules/VariablesInAllowedPosition.mjs +18 -36
  335. package/validation/specifiedRules.d.ts +98 -0
  336. package/validation/validate.d.ts +56 -0
  337. package/validation/validate.js +35 -7
  338. package/validation/validate.js.flow +51 -9
  339. package/validation/validate.mjs +30 -7
  340. package/version.d.ts +14 -0
  341. package/version.js +3 -3
  342. package/version.js.flow +3 -3
  343. package/version.mjs +3 -3
package/README.md CHANGED
@@ -11,7 +11,6 @@ https://graphql.org/graphql-js/.
11
11
 
12
12
  Looking for help? Find resources [from the community](https://graphql.org/community/).
13
13
 
14
-
15
14
  ## Getting Started
16
15
 
17
16
  An overview of GraphQL in general is available in the
@@ -47,7 +46,7 @@ import {
47
46
  graphql,
48
47
  GraphQLSchema,
49
48
  GraphQLObjectType,
50
- GraphQLString
49
+ GraphQLString,
51
50
  } from 'graphql';
52
51
 
53
52
  var schema = new GraphQLSchema({
@@ -58,10 +57,10 @@ var schema = new GraphQLSchema({
58
57
  type: GraphQLString,
59
58
  resolve() {
60
59
  return 'world';
61
- }
62
- }
63
- }
64
- })
60
+ },
61
+ },
62
+ },
63
+ }),
65
64
  });
66
65
  ```
67
66
 
@@ -76,13 +75,11 @@ Then, serve the result of a query against that type schema.
76
75
  var query = '{ hello }';
77
76
 
78
77
  graphql(schema, query).then(result => {
79
-
80
78
  // Prints
81
79
  // {
82
80
  // data: { hello: "world" }
83
81
  // }
84
82
  console.log(result);
85
-
86
83
  });
87
84
  ```
88
85
 
@@ -94,7 +91,6 @@ it, reporting errors otherwise.
94
91
  var query = '{ boyhowdy }';
95
92
 
96
93
  graphql(schema, query).then(result => {
97
-
98
94
  // Prints
99
95
  // {
100
96
  // errors: [
@@ -103,7 +99,6 @@ graphql(schema, query).then(result => {
103
99
  // ]
104
100
  // }
105
101
  console.log(result);
106
-
107
102
  });
108
103
  ```
109
104
 
@@ -0,0 +1,87 @@
1
+ import Maybe from '../tsutils/Maybe';
2
+
3
+ import { ASTNode } from '../language/ast';
4
+ import { Source } from '../language/source';
5
+ import { SourceLocation, getLocation } from '../language/location';
6
+
7
+ /**
8
+ * A GraphQLError describes an Error found during the parse, validate, or
9
+ * execute phases of performing a GraphQL operation. In addition to a message
10
+ * and stack trace, it also includes information about the locations in a
11
+ * GraphQL document and/or execution result that correspond to the Error.
12
+ */
13
+ export class GraphQLError extends Error {
14
+ constructor(
15
+ message: string,
16
+ nodes?: ReadonlyArray<ASTNode> | ASTNode | undefined,
17
+ source?: Maybe<Source>,
18
+ positions?: Maybe<ReadonlyArray<number>>,
19
+ path?: Maybe<ReadonlyArray<string | number>>,
20
+ originalError?: Maybe<Error>,
21
+ extensions?: Maybe<{ [key: string]: any }>,
22
+ );
23
+
24
+ /**
25
+ * A message describing the Error for debugging purposes.
26
+ *
27
+ * Enumerable, and appears in the result of JSON.stringify().
28
+ *
29
+ * Note: should be treated as readonly, despite invariant usage.
30
+ */
31
+ message: string;
32
+
33
+ /**
34
+ * An array of { line, column } locations within the source GraphQL document
35
+ * which correspond to this error.
36
+ *
37
+ * Errors during validation often contain multiple locations, for example to
38
+ * point out two things with the same name. Errors during execution include a
39
+ * single location, the field which produced the error.
40
+ *
41
+ * Enumerable, and appears in the result of JSON.stringify().
42
+ */
43
+ readonly locations: ReadonlyArray<SourceLocation> | undefined;
44
+
45
+ /**
46
+ * An array describing the JSON-path into the execution response which
47
+ * corresponds to this error. Only included for errors during execution.
48
+ *
49
+ * Enumerable, and appears in the result of JSON.stringify().
50
+ */
51
+ readonly path: ReadonlyArray<string | number> | undefined;
52
+
53
+ /**
54
+ * An array of GraphQL AST Nodes corresponding to this error.
55
+ */
56
+ readonly nodes: ReadonlyArray<ASTNode> | undefined;
57
+
58
+ /**
59
+ * The source GraphQL document corresponding to this error.
60
+ *
61
+ * Note that if this Error represents more than one node, the source may not
62
+ * represent nodes after the first node.
63
+ */
64
+ readonly source: Source | undefined;
65
+
66
+ /**
67
+ * An array of character offsets within the source GraphQL document
68
+ * which correspond to this error.
69
+ */
70
+ readonly positions: ReadonlyArray<number> | undefined;
71
+
72
+ /**
73
+ * The original error thrown from a field resolver during execution.
74
+ */
75
+ readonly originalError: Maybe<Error>;
76
+
77
+ /**
78
+ * Extension fields to add to the formatted error.
79
+ */
80
+ readonly extensions: { [key: string]: any } | undefined;
81
+ }
82
+
83
+ /**
84
+ * Prints a GraphQLError to a string, representing useful location information
85
+ * about the error's position in the source.
86
+ */
87
+ export function printError(error: GraphQLError): string;
@@ -158,55 +158,17 @@ function printError(error) {
158
158
  var output = error.message;
159
159
 
160
160
  if (error.nodes) {
161
- var _iteratorNormalCompletion = true;
162
- var _didIteratorError = false;
163
- var _iteratorError = undefined;
161
+ for (var _i2 = 0, _error$nodes2 = error.nodes; _i2 < _error$nodes2.length; _i2++) {
162
+ var node = _error$nodes2[_i2];
164
163
 
165
- try {
166
- for (var _iterator = error.nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
167
- var node = _step.value;
168
-
169
- if (node.loc) {
170
- output += '\n\n' + (0, _printLocation.printLocation)(node.loc);
171
- }
172
- }
173
- } catch (err) {
174
- _didIteratorError = true;
175
- _iteratorError = err;
176
- } finally {
177
- try {
178
- if (!_iteratorNormalCompletion && _iterator.return != null) {
179
- _iterator.return();
180
- }
181
- } finally {
182
- if (_didIteratorError) {
183
- throw _iteratorError;
184
- }
164
+ if (node.loc) {
165
+ output += '\n\n' + (0, _printLocation.printLocation)(node.loc);
185
166
  }
186
167
  }
187
168
  } else if (error.source && error.locations) {
188
- var _iteratorNormalCompletion2 = true;
189
- var _didIteratorError2 = false;
190
- var _iteratorError2 = undefined;
191
-
192
- try {
193
- for (var _iterator2 = error.locations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
194
- var location = _step2.value;
195
- output += '\n\n' + (0, _printLocation.printSourceLocation)(error.source, location);
196
- }
197
- } catch (err) {
198
- _didIteratorError2 = true;
199
- _iteratorError2 = err;
200
- } finally {
201
- try {
202
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
203
- _iterator2.return();
204
- }
205
- } finally {
206
- if (_didIteratorError2) {
207
- throw _iteratorError2;
208
- }
209
- }
169
+ for (var _i4 = 0, _error$locations2 = error.locations; _i4 < _error$locations2.length; _i4++) {
170
+ var location = _error$locations2[_i4];
171
+ output += '\n\n' + (0, _printLocation.printSourceLocation)(error.source, location);
210
172
  }
211
173
  }
212
174
 
@@ -1,6 +1,7 @@
1
1
  // @flow strict
2
2
 
3
3
  import isObjectLike from '../jsutils/isObjectLike';
4
+
4
5
  import { type ASTNode } from '../language/ast';
5
6
  import { type Source } from '../language/source';
6
7
  import { type SourceLocation, getLocation } from '../language/location';
@@ -151,55 +151,17 @@ export function printError(error) {
151
151
  var output = error.message;
152
152
 
153
153
  if (error.nodes) {
154
- var _iteratorNormalCompletion = true;
155
- var _didIteratorError = false;
156
- var _iteratorError = undefined;
154
+ for (var _i2 = 0, _error$nodes2 = error.nodes; _i2 < _error$nodes2.length; _i2++) {
155
+ var node = _error$nodes2[_i2];
157
156
 
158
- try {
159
- for (var _iterator = error.nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
160
- var node = _step.value;
161
-
162
- if (node.loc) {
163
- output += '\n\n' + printLocation(node.loc);
164
- }
165
- }
166
- } catch (err) {
167
- _didIteratorError = true;
168
- _iteratorError = err;
169
- } finally {
170
- try {
171
- if (!_iteratorNormalCompletion && _iterator.return != null) {
172
- _iterator.return();
173
- }
174
- } finally {
175
- if (_didIteratorError) {
176
- throw _iteratorError;
177
- }
157
+ if (node.loc) {
158
+ output += '\n\n' + printLocation(node.loc);
178
159
  }
179
160
  }
180
161
  } else if (error.source && error.locations) {
181
- var _iteratorNormalCompletion2 = true;
182
- var _didIteratorError2 = false;
183
- var _iteratorError2 = undefined;
184
-
185
- try {
186
- for (var _iterator2 = error.locations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
187
- var location = _step2.value;
188
- output += '\n\n' + printSourceLocation(error.source, location);
189
- }
190
- } catch (err) {
191
- _didIteratorError2 = true;
192
- _iteratorError2 = err;
193
- } finally {
194
- try {
195
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
196
- _iterator2.return();
197
- }
198
- } finally {
199
- if (_didIteratorError2) {
200
- throw _iteratorError2;
201
- }
202
- }
162
+ for (var _i4 = 0, _error$locations2 = error.locations; _i4 < _error$locations2.length; _i4++) {
163
+ var location = _error$locations2[_i4];
164
+ output += '\n\n' + printSourceLocation(error.source, location);
203
165
  }
204
166
  }
205
167
 
@@ -0,0 +1,39 @@
1
+ import { SourceLocation } from '../language/location';
2
+ import { GraphQLError } from './GraphQLError';
3
+
4
+ /**
5
+ * Given a GraphQLError, format it according to the rules described by the
6
+ * Response Format, Errors section of the GraphQL Specification.
7
+ */
8
+ export function formatError(error: GraphQLError): GraphQLFormattedError;
9
+
10
+ /**
11
+ * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
12
+ */
13
+ export interface GraphQLFormattedError<
14
+ TExtensions extends Record<string, any> = Record<string, any>
15
+ > {
16
+ /**
17
+ * A short, human-readable summary of the problem that **SHOULD NOT** change
18
+ * from occurrence to occurrence of the problem, except for purposes of
19
+ * localization.
20
+ */
21
+ readonly message: string;
22
+ /**
23
+ * If an error can be associated to a particular point in the requested
24
+ * GraphQL document, it should contain a list of locations.
25
+ */
26
+ readonly locations?: ReadonlyArray<SourceLocation>;
27
+ /**
28
+ * If an error can be associated to a particular field in the GraphQL result,
29
+ * it _must_ contain an entry with the key `path` that details the path of
30
+ * the response field which experienced the error. This allows clients to
31
+ * identify whether a null result is intentional or caused by a runtime error.
32
+ */
33
+ readonly path?: ReadonlyArray<string | number>;
34
+ /**
35
+ * Reserved for implementors to extend the protocol however they see fit,
36
+ * and hence there are no additional restrictions on its contents.
37
+ */
38
+ readonly extensions?: TExtensions;
39
+ }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.formatError = formatError;
7
7
 
8
- var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
8
+ var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
@@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
14
  * Response Format, Errors section of the GraphQL Specification.
15
15
  */
16
16
  function formatError(error) {
17
- !error ? (0, _invariant.default)(0, 'Received null or undefined error.') : void 0;
17
+ error || (0, _devAssert.default)(0, 'Received null or undefined error.');
18
18
  var message = error.message || 'An unknown error occurred.';
19
19
  var locations = error.locations;
20
20
  var path = error.path;
@@ -30,3 +30,6 @@ function formatError(error) {
30
30
  path: path
31
31
  };
32
32
  }
33
+ /**
34
+ * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
35
+ */
@@ -1,15 +1,17 @@
1
1
  // @flow strict
2
2
 
3
- import invariant from '../jsutils/invariant';
4
- import { type GraphQLError } from './GraphQLError';
3
+ import devAssert from '../jsutils/devAssert';
4
+
5
5
  import { type SourceLocation } from '../language/location';
6
6
 
7
+ import { type GraphQLError } from './GraphQLError';
8
+
7
9
  /**
8
10
  * Given a GraphQLError, format it according to the rules described by the
9
11
  * Response Format, Errors section of the GraphQL Specification.
10
12
  */
11
13
  export function formatError(error: GraphQLError): GraphQLFormattedError {
12
- invariant(error, 'Received null or undefined error.');
14
+ devAssert(error, 'Received null or undefined error.');
13
15
  const message = error.message || 'An unknown error occurred.';
14
16
  const locations = error.locations;
15
17
  const path = error.path;
@@ -20,9 +22,31 @@ export function formatError(error: GraphQLError): GraphQLFormattedError {
20
22
  : { message, locations, path };
21
23
  }
22
24
 
25
+ /**
26
+ * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
27
+ */
23
28
  export type GraphQLFormattedError = {|
29
+ /**
30
+ * A short, human-readable summary of the problem that **SHOULD NOT** change
31
+ * from occurrence to occurrence of the problem, except for purposes of
32
+ * localization.
33
+ */
24
34
  +message: string,
35
+ /**
36
+ * If an error can be associated to a particular point in the requested
37
+ * GraphQL document, it should contain a list of locations.
38
+ */
25
39
  +locations: $ReadOnlyArray<SourceLocation> | void,
40
+ /**
41
+ * If an error can be associated to a particular field in the GraphQL result,
42
+ * it _must_ contain an entry with the key `path` that details the path of
43
+ * the response field which experienced the error. This allows clients to
44
+ * identify whether a null result is intentional or caused by a runtime error.
45
+ */
26
46
  +path: $ReadOnlyArray<string | number> | void,
47
+ /**
48
+ * Reserved for implementors to extend the protocol however they see fit,
49
+ * and hence there are no additional restrictions on its contents.
50
+ */
27
51
  +extensions?: { [key: string]: mixed, ... },
28
52
  |};
@@ -1,11 +1,11 @@
1
- import invariant from '../jsutils/invariant';
1
+ import devAssert from '../jsutils/devAssert';
2
2
 
3
3
  /**
4
4
  * Given a GraphQLError, format it according to the rules described by the
5
5
  * Response Format, Errors section of the GraphQL Specification.
6
6
  */
7
7
  export function formatError(error) {
8
- !error ? invariant(0, 'Received null or undefined error.') : void 0;
8
+ error || devAssert(0, 'Received null or undefined error.');
9
9
  var message = error.message || 'An unknown error occurred.';
10
10
  var locations = error.locations;
11
11
  var path = error.path;
@@ -21,3 +21,6 @@ export function formatError(error) {
21
21
  path: path
22
22
  };
23
23
  }
24
+ /**
25
+ * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
26
+ */
@@ -0,0 +1,4 @@
1
+ export { GraphQLError, printError } from './GraphQLError';
2
+ export { syntaxError } from './syntaxError';
3
+ export { locatedError } from './locatedError';
4
+ export { formatError, GraphQLFormattedError } from './formatError';
@@ -0,0 +1,13 @@
1
+ import { ASTNode } from '../language/ast';
2
+ import { GraphQLError } from './GraphQLError';
3
+
4
+ /**
5
+ * Given an arbitrary Error, presumably thrown while attempting to execute a
6
+ * GraphQL operation, produce a new GraphQLError aware of the location in the
7
+ * document responsible for the original Error.
8
+ */
9
+ export function locatedError(
10
+ originalError: Error | GraphQLError,
11
+ nodes: ReadonlyArray<ASTNode>,
12
+ path: ReadonlyArray<string | number>,
13
+ ): GraphQLError;
@@ -1,8 +1,9 @@
1
1
  // @flow strict
2
2
 
3
- import { GraphQLError } from './GraphQLError';
4
3
  import { type ASTNode } from '../language/ast';
5
4
 
5
+ import { GraphQLError } from './GraphQLError';
6
+
6
7
  /**
7
8
  * Given an arbitrary Error, presumably thrown while attempting to execute a
8
9
  * GraphQL operation, produce a new GraphQLError aware of the location in the
@@ -1,10 +1,10 @@
1
1
  import { GraphQLError } from './GraphQLError';
2
-
3
2
  /**
4
3
  * Given an arbitrary Error, presumably thrown while attempting to execute a
5
4
  * GraphQL operation, produce a new GraphQLError aware of the location in the
6
5
  * document responsible for the original Error.
7
6
  */
7
+
8
8
  export function locatedError(originalError, nodes, path) {
9
9
  // Note: this uses a brand-check to support GraphQL errors originating from
10
10
  // other contexts.
@@ -0,0 +1,12 @@
1
+ import { Source } from '../language/source';
2
+ import { GraphQLError } from './GraphQLError';
3
+
4
+ /**
5
+ * Produces a GraphQLError representing a syntax error, containing useful
6
+ * descriptive information about the syntax error's position in the source.
7
+ */
8
+ export function syntaxError(
9
+ source: Source,
10
+ position: number,
11
+ description: string,
12
+ ): GraphQLError;
@@ -1,6 +1,7 @@
1
1
  // @flow strict
2
2
 
3
3
  import { type Source } from '../language/source';
4
+
4
5
  import { GraphQLError } from './GraphQLError';
5
6
 
6
7
  /**
@@ -0,0 +1,190 @@
1
+ import Maybe from '../tsutils/Maybe';
2
+ import { PromiseOrValue } from '../jsutils/PromiseOrValue';
3
+ import { Path, addPath, pathToArray } from '../jsutils/Path';
4
+
5
+ import { GraphQLError, locatedError } from '../error';
6
+ import {
7
+ DirectiveNode,
8
+ DocumentNode,
9
+ OperationDefinitionNode,
10
+ SelectionSetNode,
11
+ FieldNode,
12
+ InlineFragmentNode,
13
+ FragmentDefinitionNode,
14
+ } from '../language/ast';
15
+ import { GraphQLSchema } from '../type/schema';
16
+ import {
17
+ GraphQLField,
18
+ GraphQLFieldResolver,
19
+ GraphQLResolveInfo,
20
+ GraphQLTypeResolver,
21
+ GraphQLObjectType,
22
+ } from '../type/definition';
23
+
24
+ /**
25
+ * Data that must be available at all points during query execution.
26
+ *
27
+ * Namely, schema of the type system that is currently executing,
28
+ * and the fragments defined in the query document
29
+ */
30
+ export interface ExecutionContext {
31
+ schema: GraphQLSchema;
32
+ fragments: { [key: string]: FragmentDefinitionNode };
33
+ rootValue: any;
34
+ contextValue: any;
35
+ operation: OperationDefinitionNode;
36
+ variableValues: { [key: string]: any };
37
+ fieldResolver: GraphQLFieldResolver<any, any>;
38
+ errors: GraphQLError[];
39
+ }
40
+
41
+ export interface ExecutionResultDataDefault {
42
+ [key: string]: any;
43
+ }
44
+
45
+ /**
46
+ * The result of GraphQL execution.
47
+ *
48
+ * - `errors` is included when any errors occurred as a non-empty array.
49
+ * - `data` is the result of a successful execution of the query.
50
+ */
51
+ // TS_SPECIFIC: TData and ExecutionResultDataDefault
52
+ export interface ExecutionResult<TData = ExecutionResultDataDefault> {
53
+ errors?: ReadonlyArray<GraphQLError>;
54
+ data?: TData | null;
55
+ }
56
+
57
+ export type ExecutionArgs = {
58
+ schema: GraphQLSchema;
59
+ document: DocumentNode;
60
+ rootValue?: any;
61
+ contextValue?: any;
62
+ variableValues?: Maybe<{ [key: string]: any }>;
63
+ operationName?: Maybe<string>;
64
+ fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
65
+ typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
66
+ };
67
+
68
+ /**
69
+ * Implements the "Evaluating requests" section of the GraphQL specification.
70
+ *
71
+ * Returns either a synchronous ExecutionResult (if all encountered resolvers
72
+ * are synchronous), or a Promise of an ExecutionResult that will eventually be
73
+ * resolved and never rejected.
74
+ *
75
+ * If the arguments to this function do not result in a legal execution context,
76
+ * a GraphQLError will be thrown immediately explaining the invalid input.
77
+ *
78
+ * Accepts either an object with named arguments, or individual arguments.
79
+ */
80
+ export function execute<TData = ExecutionResultDataDefault>(
81
+ args: ExecutionArgs,
82
+ ): PromiseOrValue<ExecutionResult<TData>>;
83
+ export function execute<TData = ExecutionResultDataDefault>(
84
+ schema: GraphQLSchema,
85
+ document: DocumentNode,
86
+ rootValue?: any,
87
+ contextValue?: any,
88
+ variableValues?: Maybe<{ [key: string]: any }>,
89
+ operationName?: Maybe<string>,
90
+ fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
91
+ typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
92
+ ): PromiseOrValue<ExecutionResult<TData>>;
93
+
94
+ /**
95
+ * Essential assertions before executing to provide developer feedback for
96
+ * improper use of the GraphQL library.
97
+ */
98
+ export function assertValidExecutionArguments(
99
+ schema: GraphQLSchema,
100
+ document: DocumentNode,
101
+ rawVariableValues: Maybe<{ [key: string]: any }>,
102
+ ): void;
103
+
104
+ /**
105
+ * Constructs a ExecutionContext object from the arguments passed to
106
+ * execute, which we will pass throughout the other execution methods.
107
+ *
108
+ * Throws a GraphQLError if a valid execution context cannot be created.
109
+ */
110
+ export function buildExecutionContext(
111
+ schema: GraphQLSchema,
112
+ document: DocumentNode,
113
+ rootValue: any,
114
+ contextValue: any,
115
+ rawVariableValues: Maybe<{ [key: string]: any }>,
116
+ operationName: Maybe<string>,
117
+ fieldResolver: Maybe<GraphQLFieldResolver<any, any>>,
118
+ typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
119
+ ): ReadonlyArray<GraphQLError> | ExecutionContext;
120
+
121
+ /**
122
+ * Given a selectionSet, adds all of the fields in that selection to
123
+ * the passed in map of fields, and returns it at the end.
124
+ *
125
+ * CollectFields requires the "runtime type" of an object. For a field which
126
+ * returns an Interface or Union type, the "runtime type" will be the actual
127
+ * Object type returned by that field.
128
+ */
129
+ export function collectFields(
130
+ exeContext: ExecutionContext,
131
+ runtimeType: GraphQLObjectType,
132
+ selectionSet: SelectionSetNode,
133
+ fields: { [key: string]: Array<FieldNode> },
134
+ visitedFragmentNames: { [key: string]: boolean },
135
+ ): { [key: string]: Array<FieldNode> };
136
+
137
+ export function buildResolveInfo(
138
+ exeContext: ExecutionContext,
139
+ fieldDef: GraphQLField<any, any>,
140
+ fieldNodes: ReadonlyArray<FieldNode>,
141
+ parentType: GraphQLObjectType,
142
+ path: Path,
143
+ ): GraphQLResolveInfo;
144
+
145
+ // Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
146
+ // function. Returns the result of resolveFn or the abrupt-return Error object.
147
+ // TS_SPECIFIC: TSource
148
+ export function resolveFieldValueOrError<TSource>(
149
+ exeContext: ExecutionContext,
150
+ fieldDef: GraphQLField<TSource, any>,
151
+ fieldNodes: ReadonlyArray<FieldNode>,
152
+ resolveFn: GraphQLFieldResolver<TSource, any>,
153
+ source: TSource,
154
+ info: GraphQLResolveInfo,
155
+ ): Error | any;
156
+
157
+ /**
158
+ * If a resolveType function is not given, then a default resolve behavior is
159
+ * used which attempts two strategies:
160
+ *
161
+ * First, See if the provided value has a `__typename` field defined, if so, use
162
+ * that value as name of the resolved type.
163
+ *
164
+ * Otherwise, test each possible type for the abstract type by calling
165
+ * isTypeOf for the object being coerced, returning the first type that matches.
166
+ */
167
+ export const defaultTypeResolver: GraphQLTypeResolver<any, any>;
168
+
169
+ /**
170
+ * If a resolve function is not given, then a default resolve behavior is used
171
+ * which takes the property of the source object of the same name as the field
172
+ * and returns it as the result, or if it's a function, returns the result
173
+ * of calling that function while passing along args and context.
174
+ */
175
+ export const defaultFieldResolver: GraphQLFieldResolver<any, any>;
176
+
177
+ /**
178
+ * This method looks up the field on the given type defintion.
179
+ * It has special casing for the two introspection fields, __schema
180
+ * and __typename. __typename is special because it can always be
181
+ * queried as a field, even in situations where no other fields
182
+ * are allowed, like on a Union. __schema could get automatically
183
+ * added to the query type, but that would require mutating type
184
+ * definitions, which would cause issues.
185
+ */
186
+ export function getFieldDef(
187
+ schema: GraphQLSchema,
188
+ parentType: GraphQLObjectType,
189
+ fieldName: string,
190
+ ): Maybe<GraphQLField<any, any>>;