graphql 16.5.0 → 17.0.0-alpha.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 (279) hide show
  1. package/NotSupportedTSVersion.d.ts +1 -1
  2. package/README.md +0 -1
  3. package/error/GraphQLError.d.ts +0 -30
  4. package/error/GraphQLError.js +33 -192
  5. package/error/index.d.ts +1 -1
  6. package/error/index.js +3 -41
  7. package/error/locatedError.js +7 -23
  8. package/error/syntaxError.js +3 -11
  9. package/execution/collectFields.js +24 -74
  10. package/execution/execute.js +201 -395
  11. package/execution/index.js +13 -73
  12. package/execution/mapAsyncIterator.js +3 -24
  13. package/execution/subscribe.js +50 -107
  14. package/execution/values.js +62 -162
  15. package/graphql.js +25 -58
  16. package/index.d.ts +1 -15
  17. package/index.js +288 -1269
  18. package/jsutils/AccumulatorMap.d.ts +7 -0
  19. package/jsutils/AccumulatorMap.js +16 -0
  20. package/jsutils/Maybe.js +1 -5
  21. package/jsutils/ObjMap.js +1 -5
  22. package/jsutils/Path.js +3 -18
  23. package/jsutils/PromiseOrValue.js +1 -5
  24. package/jsutils/capitalize.d.ts +4 -0
  25. package/jsutils/capitalize.js +6 -0
  26. package/jsutils/devAssert.d.ts +1 -1
  27. package/jsutils/devAssert.js +2 -11
  28. package/jsutils/didYouMean.js +10 -30
  29. package/jsutils/formatList.d.ts +8 -0
  30. package/jsutils/formatList.js +25 -0
  31. package/jsutils/groupBy.js +4 -19
  32. package/jsutils/identityFunc.js +1 -8
  33. package/jsutils/inspect.js +3 -34
  34. package/jsutils/instanceOf.js +10 -26
  35. package/jsutils/invariant.d.ts +1 -1
  36. package/jsutils/invariant.js +2 -11
  37. package/jsutils/isAsyncIterable.js +2 -13
  38. package/jsutils/isIterableObject.js +2 -11
  39. package/jsutils/isObjectLike.js +1 -8
  40. package/jsutils/isPromise.js +2 -12
  41. package/jsutils/keyMap.js +1 -10
  42. package/jsutils/keyValMap.js +1 -10
  43. package/jsutils/mapValue.js +1 -10
  44. package/jsutils/memoize3.js +1 -15
  45. package/jsutils/naturalCompare.js +1 -20
  46. package/jsutils/printPathArray.js +1 -8
  47. package/jsutils/promiseForObject.js +1 -10
  48. package/jsutils/promiseReduce.js +3 -13
  49. package/jsutils/suggestionList.js +8 -39
  50. package/jsutils/toError.js +3 -12
  51. package/jsutils/toObjMap.js +1 -12
  52. package/language/ast.js +12 -97
  53. package/language/blockString.js +31 -88
  54. package/language/characterClasses.js +5 -20
  55. package/language/directiveLocation.d.ts +0 -6
  56. package/language/directiveLocation.js +4 -17
  57. package/language/index.d.ts +1 -10
  58. package/language/index.js +28 -215
  59. package/language/kinds.d.ts +0 -6
  60. package/language/kinds.js +13 -17
  61. package/language/lexer.js +158 -422
  62. package/language/location.js +4 -23
  63. package/language/parser.js +166 -451
  64. package/language/predicates.js +46 -74
  65. package/language/printLocation.js +6 -20
  66. package/language/printString.js +25 -173
  67. package/language/printer.js +34 -96
  68. package/language/source.js +10 -31
  69. package/language/tokenKind.d.ts +0 -6
  70. package/language/tokenKind.js +2 -17
  71. package/language/visitor.d.ts +0 -13
  72. package/language/visitor.js +23 -211
  73. package/package.json +16 -6
  74. package/type/assertName.js +13 -35
  75. package/type/definition.js +174 -549
  76. package/type/directives.js +49 -114
  77. package/type/index.js +119 -547
  78. package/type/introspection.js +119 -214
  79. package/type/scalars.js +65 -189
  80. package/type/schema.js +55 -146
  81. package/type/validate.js +165 -360
  82. package/utilities/TypeInfo.js +85 -200
  83. package/utilities/astFromValue.js +50 -111
  84. package/utilities/buildASTSchema.js +23 -60
  85. package/utilities/buildClientSchema.js +89 -158
  86. package/utilities/coerceInputValue.js +54 -97
  87. package/utilities/concatAST.js +3 -16
  88. package/utilities/extendSchema.js +160 -436
  89. package/utilities/findBreakingChanges.js +68 -166
  90. package/utilities/getIntrospectionQuery.js +1 -10
  91. package/utilities/getOperationAST.js +4 -22
  92. package/utilities/index.d.ts +0 -2
  93. package/utilities/index.js +51 -233
  94. package/utilities/introspectionFromSchema.js +8 -24
  95. package/utilities/lexicographicSortSchema.js +52 -75
  96. package/utilities/printSchema.js +44 -118
  97. package/utilities/separateOperations.js +18 -34
  98. package/utilities/sortValueNode.js +21 -27
  99. package/utilities/stripIgnoredCharacters.js +12 -39
  100. package/utilities/typeComparators.js +39 -58
  101. package/utilities/typeFromAST.js +8 -19
  102. package/utilities/typedQueryDocumentNode.js +1 -5
  103. package/utilities/valueFromAST.js +30 -75
  104. package/utilities/valueFromASTUntyped.js +14 -31
  105. package/validation/ValidationContext.js +11 -74
  106. package/validation/index.js +68 -317
  107. package/validation/rules/ExecutableDefinitionsRule.js +10 -24
  108. package/validation/rules/FieldsOnCorrectTypeRule.js +35 -72
  109. package/validation/rules/FragmentsOnCompositeTypesRule.js +15 -40
  110. package/validation/rules/KnownArgumentNamesRule.js +18 -57
  111. package/validation/rules/KnownDirectivesRule.js +63 -114
  112. package/validation/rules/KnownFragmentNamesRule.js +5 -17
  113. package/validation/rules/KnownTypeNamesRule.js +21 -47
  114. package/validation/rules/LoneAnonymousOperationRule.js +6 -18
  115. package/validation/rules/LoneSchemaDefinitionRule.js +11 -42
  116. package/validation/rules/NoFragmentCyclesRule.js +10 -29
  117. package/validation/rules/NoUndefinedVariablesRule.js +4 -18
  118. package/validation/rules/NoUnusedFragmentsRule.js +5 -21
  119. package/validation/rules/NoUnusedVariablesRule.js +4 -19
  120. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +102 -182
  121. package/validation/rules/PossibleFragmentSpreadsRule.js +20 -53
  122. package/validation/rules/PossibleTypeExtensionsRule.js +53 -102
  123. package/validation/rules/ProvidedRequiredArgumentsRule.js +29 -90
  124. package/validation/rules/ScalarLeafsRule.js +11 -26
  125. package/validation/rules/SingleFieldSubscriptionsRule.js +10 -30
  126. package/validation/rules/UniqueArgumentDefinitionNamesRule.js +13 -55
  127. package/validation/rules/UniqueArgumentNamesRule.js +7 -30
  128. package/validation/rules/UniqueDirectiveNamesRule.js +7 -26
  129. package/validation/rules/UniqueDirectivesPerLocationRule.js +15 -37
  130. package/validation/rules/UniqueEnumValueNamesRule.js +11 -38
  131. package/validation/rules/UniqueFieldDefinitionNamesRule.js +15 -41
  132. package/validation/rules/UniqueFragmentNamesRule.js +4 -17
  133. package/validation/rules/UniqueInputFieldNamesRule.js +6 -20
  134. package/validation/rules/UniqueOperationNamesRule.js +3 -14
  135. package/validation/rules/UniqueOperationTypesRule.js +7 -30
  136. package/validation/rules/UniqueTypeNamesRule.js +8 -25
  137. package/validation/rules/UniqueVariableNamesRule.js +7 -26
  138. package/validation/rules/ValuesOfCorrectTypeRule.js +56 -109
  139. package/validation/rules/VariablesAreInputTypesRule.js +10 -27
  140. package/validation/rules/VariablesInAllowedPositionRule.js +16 -47
  141. package/validation/rules/custom/NoDeprecatedCustomRule.js +24 -70
  142. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +8 -21
  143. package/validation/specifiedRules.js +83 -122
  144. package/validation/validate.js +32 -65
  145. package/version.js +5 -15
  146. package/error/GraphQLError.mjs +0 -253
  147. package/error/index.mjs +0 -3
  148. package/error/locatedError.mjs +0 -32
  149. package/error/syntaxError.mjs +0 -12
  150. package/execution/collectFields.mjs +0 -213
  151. package/execution/execute.mjs +0 -998
  152. package/execution/index.mjs +0 -13
  153. package/execution/mapAsyncIterator.mjs +0 -61
  154. package/execution/subscribe.mjs +0 -243
  155. package/execution/values.mjs +0 -263
  156. package/graphql.mjs +0 -122
  157. package/index.mjs +0 -255
  158. package/jsutils/Maybe.mjs +0 -1
  159. package/jsutils/ObjMap.mjs +0 -1
  160. package/jsutils/Path.mjs +0 -25
  161. package/jsutils/PromiseOrValue.mjs +0 -1
  162. package/jsutils/devAssert.mjs +0 -7
  163. package/jsutils/didYouMean.mjs +0 -32
  164. package/jsutils/groupBy.mjs +0 -19
  165. package/jsutils/identityFunc.mjs +0 -6
  166. package/jsutils/inspect.mjs +0 -115
  167. package/jsutils/instanceOf.mjs +0 -53
  168. package/jsutils/invariant.mjs +0 -9
  169. package/jsutils/isAsyncIterable.mjs +0 -11
  170. package/jsutils/isIterableObject.mjs +0 -25
  171. package/jsutils/isObjectLike.mjs +0 -7
  172. package/jsutils/isPromise.mjs +0 -10
  173. package/jsutils/keyMap.mjs +0 -36
  174. package/jsutils/keyValMap.mjs +0 -26
  175. package/jsutils/mapValue.mjs +0 -13
  176. package/jsutils/memoize3.mjs +0 -34
  177. package/jsutils/naturalCompare.mjs +0 -61
  178. package/jsutils/printPathArray.mjs +0 -10
  179. package/jsutils/promiseForObject.mjs +0 -18
  180. package/jsutils/promiseReduce.mjs +0 -20
  181. package/jsutils/suggestionList.mjs +0 -130
  182. package/jsutils/toError.mjs +0 -18
  183. package/jsutils/toObjMap.mjs +0 -17
  184. package/language/ast.mjs +0 -206
  185. package/language/blockString.mjs +0 -178
  186. package/language/characterClasses.mjs +0 -64
  187. package/language/directiveLocation.mjs +0 -31
  188. package/language/index.mjs +0 -29
  189. package/language/kinds.mjs +0 -55
  190. package/language/lexer.mjs +0 -902
  191. package/language/location.mjs +0 -30
  192. package/language/parser.mjs +0 -1524
  193. package/language/predicates.mjs +0 -81
  194. package/language/printLocation.mjs +0 -66
  195. package/language/printString.mjs +0 -176
  196. package/language/printer.mjs +0 -339
  197. package/language/source.mjs +0 -50
  198. package/language/tokenKind.mjs +0 -35
  199. package/language/visitor.mjs +0 -361
  200. package/subscription/index.d.ts +0 -19
  201. package/subscription/index.js +0 -19
  202. package/subscription/index.mjs +0 -19
  203. package/type/assertName.mjs +0 -44
  204. package/type/definition.mjs +0 -1177
  205. package/type/directives.mjs +0 -190
  206. package/type/index.mjs +0 -103
  207. package/type/introspection.mjs +0 -550
  208. package/type/scalars.mjs +0 -309
  209. package/type/schema.mjs +0 -381
  210. package/type/validate.mjs +0 -651
  211. package/utilities/TypeInfo.mjs +0 -395
  212. package/utilities/assertValidName.d.ts +0 -13
  213. package/utilities/assertValidName.js +0 -51
  214. package/utilities/assertValidName.mjs +0 -40
  215. package/utilities/astFromValue.mjs +0 -177
  216. package/utilities/buildASTSchema.mjs +0 -97
  217. package/utilities/buildClientSchema.mjs +0 -363
  218. package/utilities/coerceInputValue.mjs +0 -167
  219. package/utilities/concatAST.mjs +0 -19
  220. package/utilities/extendSchema.mjs +0 -789
  221. package/utilities/findBreakingChanges.mjs +0 -516
  222. package/utilities/getIntrospectionQuery.mjs +0 -127
  223. package/utilities/getOperationAST.mjs +0 -36
  224. package/utilities/getOperationRootType.d.ts +0 -15
  225. package/utilities/getOperationRootType.js +0 -67
  226. package/utilities/getOperationRootType.mjs +0 -54
  227. package/utilities/index.mjs +0 -55
  228. package/utilities/introspectionFromSchema.mjs +0 -30
  229. package/utilities/lexicographicSortSchema.mjs +0 -172
  230. package/utilities/printSchema.mjs +0 -309
  231. package/utilities/separateOperations.mjs +0 -80
  232. package/utilities/sortValueNode.mjs +0 -39
  233. package/utilities/stripIgnoredCharacters.mjs +0 -104
  234. package/utilities/typeComparators.mjs +0 -106
  235. package/utilities/typeFromAST.mjs +0 -18
  236. package/utilities/typedQueryDocumentNode.mjs +0 -1
  237. package/utilities/valueFromAST.mjs +0 -172
  238. package/utilities/valueFromASTUntyped.mjs +0 -53
  239. package/validation/ValidationContext.mjs +0 -212
  240. package/validation/index.mjs +0 -68
  241. package/validation/rules/ExecutableDefinitionsRule.mjs +0 -34
  242. package/validation/rules/FieldsOnCorrectTypeRule.mjs +0 -127
  243. package/validation/rules/FragmentsOnCompositeTypesRule.mjs +0 -53
  244. package/validation/rules/KnownArgumentNamesRule.mjs +0 -102
  245. package/validation/rules/KnownDirectivesRule.mjs +0 -150
  246. package/validation/rules/KnownFragmentNamesRule.mjs +0 -26
  247. package/validation/rules/KnownTypeNamesRule.mjs +0 -77
  248. package/validation/rules/LoneAnonymousOperationRule.mjs +0 -34
  249. package/validation/rules/LoneSchemaDefinitionRule.mjs +0 -57
  250. package/validation/rules/NoFragmentCyclesRule.mjs +0 -78
  251. package/validation/rules/NoUndefinedVariablesRule.mjs +0 -45
  252. package/validation/rules/NoUnusedFragmentsRule.mjs +0 -51
  253. package/validation/rules/NoUnusedVariablesRule.mjs +0 -50
  254. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +0 -790
  255. package/validation/rules/PossibleFragmentSpreadsRule.mjs +0 -73
  256. package/validation/rules/PossibleTypeExtensionsRule.mjs +0 -148
  257. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +0 -142
  258. package/validation/rules/ScalarLeafsRule.mjs +0 -46
  259. package/validation/rules/SingleFieldSubscriptionsRule.mjs +0 -77
  260. package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +0 -81
  261. package/validation/rules/UniqueArgumentNamesRule.mjs +0 -44
  262. package/validation/rules/UniqueDirectiveNamesRule.mjs +0 -47
  263. package/validation/rules/UniqueDirectivesPerLocationRule.mjs +0 -85
  264. package/validation/rules/UniqueEnumValueNamesRule.mjs +0 -64
  265. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +0 -79
  266. package/validation/rules/UniqueFragmentNamesRule.mjs +0 -34
  267. package/validation/rules/UniqueInputFieldNamesRule.mjs +0 -46
  268. package/validation/rules/UniqueOperationNamesRule.mjs +0 -39
  269. package/validation/rules/UniqueOperationTypesRule.mjs +0 -64
  270. package/validation/rules/UniqueTypeNamesRule.mjs +0 -47
  271. package/validation/rules/UniqueVariableNamesRule.mjs +0 -41
  272. package/validation/rules/ValuesOfCorrectTypeRule.mjs +0 -173
  273. package/validation/rules/VariablesAreInputTypesRule.mjs +0 -33
  274. package/validation/rules/VariablesInAllowedPositionRule.mjs +0 -97
  275. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +0 -117
  276. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +0 -32
  277. package/validation/specifiedRules.mjs +0 -123
  278. package/validation/validate.mjs +0 -133
  279. package/version.mjs +0 -17
@@ -1 +1 @@
1
- "Package 'graphql' support only TS versions that are >=4.1.0".
1
+ "Package 'graphql' support only TS versions that are >=4.4.0".
package/README.md CHANGED
@@ -4,7 +4,6 @@ The JavaScript reference implementation for GraphQL, a query language for APIs c
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/graphql.svg)](https://badge.fury.io/js/graphql)
6
6
  [![Build Status](https://github.com/graphql/graphql-js/workflows/CI/badge.svg?branch=main)](https://github.com/graphql/graphql-js/actions?query=branch%3Amain)
7
- [![Coverage Status](https://codecov.io/gh/graphql/graphql-js/branch/main/graph/badge.svg)](https://codecov.io/gh/graphql/graphql-js)
8
7
 
9
8
  See more complete documentation at https://graphql.org/ and
10
9
  https://graphql.org/graphql-js/.
@@ -76,22 +76,6 @@ export declare class GraphQLError extends Error {
76
76
  */
77
77
  readonly extensions: GraphQLErrorExtensions;
78
78
  constructor(message: string, options?: GraphQLErrorOptions);
79
- /**
80
- * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
81
- */
82
- constructor(
83
- message: string,
84
- nodes?: ReadonlyArray<ASTNode> | ASTNode | null,
85
- source?: Maybe<Source>,
86
- positions?: Maybe<ReadonlyArray<number>>,
87
- path?: Maybe<ReadonlyArray<string | number>>,
88
- originalError?: Maybe<
89
- Error & {
90
- readonly extensions?: unknown;
91
- }
92
- >,
93
- extensions?: Maybe<GraphQLErrorExtensions>,
94
- );
95
79
  get [Symbol.toStringTag](): string;
96
80
  toString(): string;
97
81
  toJSON(): GraphQLFormattedError;
@@ -126,17 +110,3 @@ export interface GraphQLFormattedError {
126
110
  [key: string]: unknown;
127
111
  };
128
112
  }
129
- /**
130
- * Prints a GraphQLError to a string, representing useful location information
131
- * about the error's position in the source.
132
- *
133
- * @deprecated Please use `error.toString` instead. Will be removed in v17
134
- */
135
- export declare function printError(error: GraphQLError): string;
136
- /**
137
- * Given a GraphQLError, format it according to the rules described by the
138
- * Response Format, Errors section of the GraphQL Specification.
139
- *
140
- * @deprecated Please use `error.toJSON` instead. Will be removed in v17
141
- */
142
- export declare function formatError(error: GraphQLError): GraphQLFormattedError;
@@ -1,180 +1,58 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- });
6
- exports.GraphQLError = void 0;
7
- exports.formatError = formatError;
8
- exports.printError = printError;
9
-
10
- var _isObjectLike = require('../jsutils/isObjectLike.js');
11
-
12
- var _location = require('../language/location.js');
13
-
14
- var _printLocation = require('../language/printLocation.js');
15
-
16
- function toNormalizedOptions(args) {
17
- const firstArg = args[0];
18
-
19
- if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
20
- return {
21
- nodes: firstArg,
22
- source: args[1],
23
- positions: args[2],
24
- path: args[3],
25
- originalError: args[4],
26
- extensions: args[5],
27
- };
28
- }
29
-
30
- return firstArg;
31
- }
1
+ import { isObjectLike } from '../jsutils/isObjectLike.js';
2
+ import { getLocation } from '../language/location.js';
3
+ import {
4
+ printLocation,
5
+ printSourceLocation,
6
+ } from '../language/printLocation.js';
32
7
  /**
33
8
  * A GraphQLError describes an Error found during the parse, validate, or
34
9
  * execute phases of performing a GraphQL operation. In addition to a message
35
10
  * and stack trace, it also includes information about the locations in a
36
11
  * GraphQL document and/or execution result that correspond to the Error.
37
12
  */
38
-
39
- class GraphQLError extends Error {
40
- /**
41
- * An array of `{ line, column }` locations within the source GraphQL document
42
- * which correspond to this error.
43
- *
44
- * Errors during validation often contain multiple locations, for example to
45
- * point out two things with the same name. Errors during execution include a
46
- * single location, the field which produced the error.
47
- *
48
- * Enumerable, and appears in the result of JSON.stringify().
49
- */
50
-
51
- /**
52
- * An array describing the JSON-path into the execution response which
53
- * corresponds to this error. Only included for errors during execution.
54
- *
55
- * Enumerable, and appears in the result of JSON.stringify().
56
- */
57
-
58
- /**
59
- * An array of GraphQL AST Nodes corresponding to this error.
60
- */
61
-
62
- /**
63
- * The source GraphQL document for the first location of this error.
64
- *
65
- * Note that if this Error represents more than one node, the source may not
66
- * represent nodes after the first node.
67
- */
68
-
69
- /**
70
- * An array of character offsets within the source GraphQL document
71
- * which correspond to this error.
72
- */
73
-
74
- /**
75
- * The original error thrown from a field resolver during execution.
76
- */
77
-
78
- /**
79
- * Extension fields to add to the formatted error.
80
- */
81
-
82
- /**
83
- * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
84
- */
85
- constructor(message, ...rawArgs) {
86
- var _this$nodes, _nodeLocations$, _ref;
87
-
13
+ export class GraphQLError extends Error {
14
+ constructor(message, options = {}) {
88
15
  const { nodes, source, positions, path, originalError, extensions } =
89
- toNormalizedOptions(rawArgs);
16
+ options;
90
17
  super(message);
91
18
  this.name = 'GraphQLError';
92
- this.path = path !== null && path !== void 0 ? path : undefined;
93
- this.originalError =
94
- originalError !== null && originalError !== void 0
95
- ? originalError
96
- : undefined; // Compute list of blame nodes.
97
-
19
+ this.path = path ?? undefined;
20
+ this.originalError = originalError ?? undefined;
21
+ // Compute list of blame nodes.
98
22
  this.nodes = undefinedIfEmpty(
99
23
  Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,
100
24
  );
101
25
  const nodeLocations = undefinedIfEmpty(
102
- (_this$nodes = this.nodes) === null || _this$nodes === void 0
103
- ? void 0
104
- : _this$nodes.map((node) => node.loc).filter((loc) => loc != null),
105
- ); // Compute locations in the source for the given nodes/positions.
106
-
107
- this.source =
108
- source !== null && source !== void 0
109
- ? source
110
- : nodeLocations === null || nodeLocations === void 0
111
- ? void 0
112
- : (_nodeLocations$ = nodeLocations[0]) === null ||
113
- _nodeLocations$ === void 0
114
- ? void 0
115
- : _nodeLocations$.source;
116
- this.positions =
117
- positions !== null && positions !== void 0
118
- ? positions
119
- : nodeLocations === null || nodeLocations === void 0
120
- ? void 0
121
- : nodeLocations.map((loc) => loc.start);
26
+ this.nodes?.map((node) => node.loc).filter((loc) => loc != null),
27
+ );
28
+ // Compute locations in the source for the given nodes/positions.
29
+ this.source = source ?? nodeLocations?.[0]?.source;
30
+ this.positions = positions ?? nodeLocations?.map((loc) => loc.start);
122
31
  this.locations =
123
32
  positions && source
124
- ? positions.map((pos) => (0, _location.getLocation)(source, pos))
125
- : nodeLocations === null || nodeLocations === void 0
126
- ? void 0
127
- : nodeLocations.map((loc) =>
128
- (0, _location.getLocation)(loc.source, loc.start),
129
- );
130
- const originalExtensions = (0, _isObjectLike.isObjectLike)(
131
- originalError === null || originalError === void 0
132
- ? void 0
133
- : originalError.extensions,
134
- )
135
- ? originalError === null || originalError === void 0
136
- ? void 0
137
- : originalError.extensions
33
+ ? positions.map((pos) => getLocation(source, pos))
34
+ : nodeLocations?.map((loc) => getLocation(loc.source, loc.start));
35
+ const originalExtensions = isObjectLike(originalError?.extensions)
36
+ ? originalError?.extensions
138
37
  : undefined;
139
- this.extensions =
140
- (_ref =
141
- extensions !== null && extensions !== void 0
142
- ? extensions
143
- : originalExtensions) !== null && _ref !== void 0
144
- ? _ref
145
- : Object.create(null); // Only properties prescribed by the spec should be enumerable.
38
+ this.extensions = extensions ?? originalExtensions ?? Object.create(null);
39
+ // Only properties prescribed by the spec should be enumerable.
146
40
  // Keep the rest as non-enumerable.
147
-
148
41
  Object.defineProperties(this, {
149
42
  message: {
150
43
  writable: true,
151
44
  enumerable: true,
152
45
  },
153
- name: {
154
- enumerable: false,
155
- },
156
- nodes: {
157
- enumerable: false,
158
- },
159
- source: {
160
- enumerable: false,
161
- },
162
- positions: {
163
- enumerable: false,
164
- },
165
- originalError: {
166
- enumerable: false,
167
- },
168
- }); // Include (non-enumerable) stack trace.
169
-
46
+ name: { enumerable: false },
47
+ nodes: { enumerable: false },
48
+ source: { enumerable: false },
49
+ positions: { enumerable: false },
50
+ originalError: { enumerable: false },
51
+ });
52
+ // Include (non-enumerable) stack trace.
170
53
  /* c8 ignore start */
171
54
  // FIXME: https://github.com/graphql/graphql-js/issues/2317
172
-
173
- if (
174
- originalError !== null &&
175
- originalError !== void 0 &&
176
- originalError.stack
177
- ) {
55
+ if (originalError?.stack) {
178
56
  Object.defineProperty(this, 'stack', {
179
57
  value: originalError.stack,
180
58
  writable: true,
@@ -191,77 +69,40 @@ class GraphQLError extends Error {
191
69
  }
192
70
  /* c8 ignore stop */
193
71
  }
194
-
195
72
  get [Symbol.toStringTag]() {
196
73
  return 'GraphQLError';
197
74
  }
198
-
199
75
  toString() {
200
76
  let output = this.message;
201
-
202
77
  if (this.nodes) {
203
78
  for (const node of this.nodes) {
204
79
  if (node.loc) {
205
- output += '\n\n' + (0, _printLocation.printLocation)(node.loc);
80
+ output += '\n\n' + printLocation(node.loc);
206
81
  }
207
82
  }
208
83
  } else if (this.source && this.locations) {
209
84
  for (const location of this.locations) {
210
- output +=
211
- '\n\n' +
212
- (0, _printLocation.printSourceLocation)(this.source, location);
85
+ output += '\n\n' + printSourceLocation(this.source, location);
213
86
  }
214
87
  }
215
-
216
88
  return output;
217
89
  }
218
-
219
90
  toJSON() {
220
91
  const formattedError = {
221
92
  message: this.message,
222
93
  };
223
-
224
94
  if (this.locations != null) {
225
95
  formattedError.locations = this.locations;
226
96
  }
227
-
228
97
  if (this.path != null) {
229
98
  formattedError.path = this.path;
230
99
  }
231
-
232
100
  if (this.extensions != null && Object.keys(this.extensions).length > 0) {
233
101
  formattedError.extensions = this.extensions;
234
102
  }
235
-
236
103
  return formattedError;
237
104
  }
238
105
  }
239
-
240
- exports.GraphQLError = GraphQLError;
241
-
242
106
  function undefinedIfEmpty(array) {
243
107
  return array === undefined || array.length === 0 ? undefined : array;
244
108
  }
245
- /**
246
- * See: https://spec.graphql.org/draft/#sec-Errors
247
- */
248
-
249
- /**
250
- * Prints a GraphQLError to a string, representing useful location information
251
- * about the error's position in the source.
252
- *
253
- * @deprecated Please use `error.toString` instead. Will be removed in v17
254
- */
255
- function printError(error) {
256
- return error.toString();
257
- }
258
- /**
259
- * Given a GraphQLError, format it according to the rules described by the
260
- * Response Format, Errors section of the GraphQL Specification.
261
- *
262
- * @deprecated Please use `error.toJSON` instead. Will be removed in v17
263
- */
264
-
265
- function formatError(error) {
266
- return error.toJSON();
267
- }
package/error/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { GraphQLError, printError, formatError } from './GraphQLError';
1
+ export { GraphQLError } from './GraphQLError';
2
2
  export type {
3
3
  GraphQLErrorOptions,
4
4
  GraphQLFormattedError,
package/error/index.js CHANGED
@@ -1,41 +1,3 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- });
6
- Object.defineProperty(exports, 'GraphQLError', {
7
- enumerable: true,
8
- get: function () {
9
- return _GraphQLError.GraphQLError;
10
- },
11
- });
12
- Object.defineProperty(exports, 'formatError', {
13
- enumerable: true,
14
- get: function () {
15
- return _GraphQLError.formatError;
16
- },
17
- });
18
- Object.defineProperty(exports, 'locatedError', {
19
- enumerable: true,
20
- get: function () {
21
- return _locatedError.locatedError;
22
- },
23
- });
24
- Object.defineProperty(exports, 'printError', {
25
- enumerable: true,
26
- get: function () {
27
- return _GraphQLError.printError;
28
- },
29
- });
30
- Object.defineProperty(exports, 'syntaxError', {
31
- enumerable: true,
32
- get: function () {
33
- return _syntaxError.syntaxError;
34
- },
35
- });
36
-
37
- var _GraphQLError = require('./GraphQLError.js');
38
-
39
- var _syntaxError = require('./syntaxError.js');
40
-
41
- var _locatedError = require('./locatedError.js');
1
+ export { GraphQLError } from './GraphQLError.js';
2
+ export { syntaxError } from './syntaxError.js';
3
+ export { locatedError } from './locatedError.js';
@@ -1,40 +1,24 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- });
6
- exports.locatedError = locatedError;
7
-
8
- var _toError = require('../jsutils/toError.js');
9
-
10
- var _GraphQLError = require('./GraphQLError.js');
11
-
1
+ import { toError } from '../jsutils/toError.js';
2
+ import { GraphQLError } from './GraphQLError.js';
12
3
  /**
13
4
  * Given an arbitrary value, presumably thrown while attempting to execute a
14
5
  * GraphQL operation, produce a new GraphQLError aware of the location in the
15
6
  * document responsible for the original Error.
16
7
  */
17
- function locatedError(rawOriginalError, nodes, path) {
18
- var _nodes;
19
-
20
- const originalError = (0, _toError.toError)(rawOriginalError); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
21
-
8
+ export function locatedError(rawOriginalError, nodes, path) {
9
+ const originalError = toError(rawOriginalError);
10
+ // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
22
11
  if (isLocatedGraphQLError(originalError)) {
23
12
  return originalError;
24
13
  }
25
-
26
- return new _GraphQLError.GraphQLError(originalError.message, {
27
- nodes:
28
- (_nodes = originalError.nodes) !== null && _nodes !== void 0
29
- ? _nodes
30
- : nodes,
14
+ return new GraphQLError(originalError.message, {
15
+ nodes: originalError.nodes ?? nodes,
31
16
  source: originalError.source,
32
17
  positions: originalError.positions,
33
18
  path,
34
19
  originalError,
35
20
  });
36
21
  }
37
-
38
22
  function isLocatedGraphQLError(error) {
39
23
  return Array.isArray(error.path);
40
24
  }
@@ -1,18 +1,10 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- });
6
- exports.syntaxError = syntaxError;
7
-
8
- var _GraphQLError = require('./GraphQLError.js');
9
-
1
+ import { GraphQLError } from './GraphQLError.js';
10
2
  /**
11
3
  * Produces a GraphQLError representing a syntax error, containing useful
12
4
  * descriptive information about the syntax error's position in the source.
13
5
  */
14
- function syntaxError(source, position, description) {
15
- return new _GraphQLError.GraphQLError(`Syntax Error: ${description}`, {
6
+ export function syntaxError(source, position, description) {
7
+ return new GraphQLError(`Syntax Error: ${description}`, {
16
8
  source,
17
9
  positions: [position],
18
10
  });
@@ -1,21 +1,12 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- });
6
- exports.collectFields = collectFields;
7
- exports.collectSubfields = collectSubfields;
8
-
9
- var _kinds = require('../language/kinds.js');
10
-
11
- var _definition = require('../type/definition.js');
12
-
13
- var _directives = require('../type/directives.js');
14
-
15
- var _typeFromAST = require('../utilities/typeFromAST.js');
16
-
17
- var _values = require('./values.js');
18
-
1
+ import { AccumulatorMap } from '../jsutils/AccumulatorMap.js';
2
+ import { Kind } from '../language/kinds.js';
3
+ import { isAbstractType } from '../type/definition.js';
4
+ import {
5
+ GraphQLIncludeDirective,
6
+ GraphQLSkipDirective,
7
+ } from '../type/directives.js';
8
+ import { typeFromAST } from '../utilities/typeFromAST.js';
9
+ import { getDirectiveValues } from './values.js';
19
10
  /**
20
11
  * Given a selectionSet, collects all of the fields and returns them.
21
12
  *
@@ -25,14 +16,14 @@ var _values = require('./values.js');
25
16
  *
26
17
  * @internal
27
18
  */
28
- function collectFields(
19
+ export function collectFields(
29
20
  schema,
30
21
  fragments,
31
22
  variableValues,
32
23
  runtimeType,
33
24
  selectionSet,
34
25
  ) {
35
- const fields = new Map();
26
+ const fields = new AccumulatorMap();
36
27
  collectFieldsImpl(
37
28
  schema,
38
29
  fragments,
@@ -54,17 +45,15 @@ function collectFields(
54
45
  *
55
46
  * @internal
56
47
  */
57
-
58
- function collectSubfields(
48
+ export function collectSubfields(
59
49
  schema,
60
50
  fragments,
61
51
  variableValues,
62
52
  returnType,
63
53
  fieldNodes,
64
54
  ) {
65
- const subFieldNodes = new Map();
55
+ const subFieldNodes = new AccumulatorMap();
66
56
  const visitedFragmentNames = new Set();
67
-
68
57
  for (const node of fieldNodes) {
69
58
  if (node.selectionSet) {
70
59
  collectFieldsImpl(
@@ -78,10 +67,8 @@ function collectSubfields(
78
67
  );
79
68
  }
80
69
  }
81
-
82
70
  return subFieldNodes;
83
71
  }
84
-
85
72
  function collectFieldsImpl(
86
73
  schema,
87
74
  fragments,
@@ -93,31 +80,20 @@ function collectFieldsImpl(
93
80
  ) {
94
81
  for (const selection of selectionSet.selections) {
95
82
  switch (selection.kind) {
96
- case _kinds.Kind.FIELD: {
83
+ case Kind.FIELD: {
97
84
  if (!shouldIncludeNode(variableValues, selection)) {
98
85
  continue;
99
86
  }
100
-
101
- const name = getFieldEntryKey(selection);
102
- const fieldList = fields.get(name);
103
-
104
- if (fieldList !== undefined) {
105
- fieldList.push(selection);
106
- } else {
107
- fields.set(name, [selection]);
108
- }
109
-
87
+ fields.add(getFieldEntryKey(selection), selection);
110
88
  break;
111
89
  }
112
-
113
- case _kinds.Kind.INLINE_FRAGMENT: {
90
+ case Kind.INLINE_FRAGMENT: {
114
91
  if (
115
92
  !shouldIncludeNode(variableValues, selection) ||
116
93
  !doesFragmentConditionMatch(schema, selection, runtimeType)
117
94
  ) {
118
95
  continue;
119
96
  }
120
-
121
97
  collectFieldsImpl(
122
98
  schema,
123
99
  fragments,
@@ -129,27 +105,22 @@ function collectFieldsImpl(
129
105
  );
130
106
  break;
131
107
  }
132
-
133
- case _kinds.Kind.FRAGMENT_SPREAD: {
108
+ case Kind.FRAGMENT_SPREAD: {
134
109
  const fragName = selection.name.value;
135
-
136
110
  if (
137
111
  visitedFragmentNames.has(fragName) ||
138
112
  !shouldIncludeNode(variableValues, selection)
139
113
  ) {
140
114
  continue;
141
115
  }
142
-
143
116
  visitedFragmentNames.add(fragName);
144
117
  const fragment = fragments[fragName];
145
-
146
118
  if (
147
119
  !fragment ||
148
120
  !doesFragmentConditionMatch(schema, fragment, runtimeType)
149
121
  ) {
150
122
  continue;
151
123
  }
152
-
153
124
  collectFieldsImpl(
154
125
  schema,
155
126
  fragments,
@@ -168,62 +139,41 @@ function collectFieldsImpl(
168
139
  * Determines if a field should be included based on the `@include` and `@skip`
169
140
  * directives, where `@skip` has higher precedence than `@include`.
170
141
  */
171
-
172
142
  function shouldIncludeNode(variableValues, node) {
173
- const skip = (0, _values.getDirectiveValues)(
174
- _directives.GraphQLSkipDirective,
175
- node,
176
- variableValues,
177
- );
178
-
179
- if ((skip === null || skip === void 0 ? void 0 : skip.if) === true) {
143
+ const skip = getDirectiveValues(GraphQLSkipDirective, node, variableValues);
144
+ if (skip?.if === true) {
180
145
  return false;
181
146
  }
182
-
183
- const include = (0, _values.getDirectiveValues)(
184
- _directives.GraphQLIncludeDirective,
147
+ const include = getDirectiveValues(
148
+ GraphQLIncludeDirective,
185
149
  node,
186
150
  variableValues,
187
151
  );
188
-
189
- if (
190
- (include === null || include === void 0 ? void 0 : include.if) === false
191
- ) {
152
+ if (include?.if === false) {
192
153
  return false;
193
154
  }
194
-
195
155
  return true;
196
156
  }
197
157
  /**
198
158
  * Determines if a fragment is applicable to the given type.
199
159
  */
200
-
201
160
  function doesFragmentConditionMatch(schema, fragment, type) {
202
161
  const typeConditionNode = fragment.typeCondition;
203
-
204
162
  if (!typeConditionNode) {
205
163
  return true;
206
164
  }
207
-
208
- const conditionalType = (0, _typeFromAST.typeFromAST)(
209
- schema,
210
- typeConditionNode,
211
- );
212
-
165
+ const conditionalType = typeFromAST(schema, typeConditionNode);
213
166
  if (conditionalType === type) {
214
167
  return true;
215
168
  }
216
-
217
- if ((0, _definition.isAbstractType)(conditionalType)) {
169
+ if (isAbstractType(conditionalType)) {
218
170
  return schema.isSubType(conditionalType, type);
219
171
  }
220
-
221
172
  return false;
222
173
  }
223
174
  /**
224
175
  * Implements the logic to compute the key of a given field's entry
225
176
  */
226
-
227
177
  function getFieldEntryKey(node) {
228
178
  return node.alias ? node.alias.value : node.name.value;
229
179
  }