graphql 16.14.2 → 16.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/error/GraphQLError.d.ts +5 -1
  2. package/error/GraphQLError.js +12 -7
  3. package/error/GraphQLError.mjs +13 -6
  4. package/error/locatedError.d.ts +6 -4
  5. package/error/locatedError.js +6 -4
  6. package/error/locatedError.mjs +6 -4
  7. package/execution/collectFields.d.ts +1 -0
  8. package/execution/collectFields.js +9 -0
  9. package/execution/collectFields.mjs +9 -0
  10. package/execution/execute.d.ts +9 -10
  11. package/execution/execute.js +44 -29
  12. package/execution/execute.mjs +44 -29
  13. package/execution/mapAsyncIterator.js +12 -11
  14. package/execution/mapAsyncIterator.mjs +12 -11
  15. package/execution/subscribe.d.ts +5 -2
  16. package/execution/subscribe.js +5 -2
  17. package/execution/subscribe.mjs +5 -2
  18. package/execution/values.d.ts +43 -21
  19. package/execution/values.js +52 -24
  20. package/execution/values.mjs +51 -23
  21. package/graphql.d.ts +8 -14
  22. package/graphql.js +16 -15
  23. package/graphql.mjs +11 -15
  24. package/jsutils/SetMap.d.ts +14 -0
  25. package/jsutils/SetMap.js +48 -0
  26. package/jsutils/SetMap.mjs +39 -0
  27. package/jsutils/isIterableObject.d.ts +2 -0
  28. package/jsutils/isIterableObject.js +2 -0
  29. package/jsutils/isIterableObject.mjs +2 -0
  30. package/jsutils/keyMap.d.ts +2 -0
  31. package/jsutils/keyMap.js +2 -0
  32. package/jsutils/keyMap.mjs +2 -0
  33. package/jsutils/keyValMap.d.ts +3 -3
  34. package/jsutils/keyValMap.js +3 -3
  35. package/jsutils/keyValMap.mjs +3 -3
  36. package/language/ast.d.ts +2 -6
  37. package/language/ast.js +2 -6
  38. package/language/ast.mjs +2 -6
  39. package/language/lexer.d.ts +6 -0
  40. package/language/lexer.js +22 -0
  41. package/language/lexer.mjs +22 -0
  42. package/language/location.d.ts +8 -3
  43. package/language/location.js +57 -17
  44. package/language/location.mjs +56 -16
  45. package/language/parser.d.ts +27 -13
  46. package/language/parser.js +31 -9
  47. package/language/parser.mjs +31 -9
  48. package/language/predicates.d.ts +10 -3
  49. package/language/predicates.js +10 -3
  50. package/language/predicates.mjs +10 -3
  51. package/language/printLocation.d.ts +2 -6
  52. package/language/printLocation.js +2 -6
  53. package/language/printLocation.mjs +2 -6
  54. package/language/printer.d.ts +22 -3
  55. package/language/printer.js +394 -308
  56. package/language/printer.mjs +394 -308
  57. package/language/reducer.d.ts +32 -0
  58. package/language/reducer.js +95 -0
  59. package/language/reducer.mjs +86 -0
  60. package/language/source.d.ts +4 -5
  61. package/language/source.js +4 -5
  62. package/language/source.mjs +4 -5
  63. package/language/visitor.d.ts +16 -10
  64. package/language/visitor.js +15 -7
  65. package/language/visitor.mjs +15 -7
  66. package/package.json +1 -4
  67. package/type/definition.d.ts +170 -102
  68. package/type/definition.js +169 -96
  69. package/type/definition.mjs +168 -95
  70. package/type/directives.d.ts +12 -6
  71. package/type/directives.js +12 -6
  72. package/type/directives.mjs +12 -6
  73. package/type/scalars.js +8 -11
  74. package/type/scalars.mjs +1 -1
  75. package/type/schema.d.ts +36 -11
  76. package/type/schema.js +35 -10
  77. package/type/schema.mjs +35 -10
  78. package/type/validate.d.ts +1 -3
  79. package/type/validate.js +1 -3
  80. package/type/validate.mjs +1 -3
  81. package/utilities/TypeInfo.d.ts +15 -11
  82. package/utilities/TypeInfo.js +15 -11
  83. package/utilities/TypeInfo.mjs +15 -11
  84. package/utilities/assertValidName.d.ts +1 -1
  85. package/utilities/assertValidName.js +1 -1
  86. package/utilities/assertValidName.mjs +1 -1
  87. package/utilities/astFromValue.d.ts +3 -1
  88. package/utilities/astFromValue.js +3 -1
  89. package/utilities/astFromValue.mjs +3 -1
  90. package/utilities/buildASTSchema.d.ts +8 -8
  91. package/utilities/buildASTSchema.js +9 -20
  92. package/utilities/buildASTSchema.mjs +9 -20
  93. package/utilities/buildClientSchema.d.ts +6 -2
  94. package/utilities/buildClientSchema.js +6 -2
  95. package/utilities/buildClientSchema.mjs +6 -2
  96. package/utilities/coerceInputValue.d.ts +9 -3
  97. package/utilities/coerceInputValue.js +60 -13
  98. package/utilities/coerceInputValue.mjs +58 -13
  99. package/utilities/concatAST.d.ts +4 -1
  100. package/utilities/concatAST.js +4 -1
  101. package/utilities/concatAST.mjs +4 -1
  102. package/utilities/extendSchema.d.ts +7 -4
  103. package/utilities/extendSchema.js +7 -4
  104. package/utilities/extendSchema.mjs +7 -4
  105. package/utilities/findBreakingChanges.d.ts +2 -2
  106. package/utilities/findBreakingChanges.js +2 -2
  107. package/utilities/findBreakingChanges.mjs +2 -2
  108. package/utilities/getIntrospectionQuery.d.ts +9 -9
  109. package/utilities/getIntrospectionQuery.js +8 -8
  110. package/utilities/getIntrospectionQuery.mjs +8 -8
  111. package/utilities/getOperationAST.d.ts +2 -2
  112. package/utilities/getOperationAST.js +2 -2
  113. package/utilities/getOperationAST.mjs +2 -2
  114. package/utilities/getOperationRootType.d.ts +3 -1
  115. package/utilities/getOperationRootType.js +3 -1
  116. package/utilities/getOperationRootType.mjs +3 -1
  117. package/utilities/introspectionFromSchema.d.ts +12 -4
  118. package/utilities/introspectionFromSchema.js +12 -4
  119. package/utilities/introspectionFromSchema.mjs +12 -4
  120. package/utilities/lexicographicSortSchema.d.ts +17 -13
  121. package/utilities/lexicographicSortSchema.js +17 -13
  122. package/utilities/lexicographicSortSchema.mjs +17 -13
  123. package/utilities/printSchema.d.ts +7 -4
  124. package/utilities/printSchema.js +7 -4
  125. package/utilities/printSchema.mjs +7 -4
  126. package/utilities/resolveSchemaCoordinate.d.ts +9 -8
  127. package/utilities/resolveSchemaCoordinate.js +9 -8
  128. package/utilities/resolveSchemaCoordinate.mjs +9 -8
  129. package/utilities/separateOperations.d.ts +2 -2
  130. package/utilities/separateOperations.js +2 -2
  131. package/utilities/separateOperations.mjs +2 -2
  132. package/utilities/stripIgnoredCharacters.d.ts +19 -5
  133. package/utilities/stripIgnoredCharacters.js +19 -5
  134. package/utilities/stripIgnoredCharacters.mjs +19 -5
  135. package/utilities/typeComparators.d.ts +1 -5
  136. package/utilities/typeComparators.js +1 -5
  137. package/utilities/typeComparators.mjs +1 -5
  138. package/utilities/valueFromAST.js +4 -4
  139. package/utilities/valueFromAST.mjs +4 -4
  140. package/utilities/valueFromASTUntyped.d.ts +1 -3
  141. package/utilities/valueFromASTUntyped.js +1 -3
  142. package/utilities/valueFromASTUntyped.mjs +1 -3
  143. package/validation/ValidationContext.d.ts +22 -3
  144. package/validation/ValidationContext.js +84 -27
  145. package/validation/ValidationContext.mjs +82 -27
  146. package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -4
  147. package/validation/rules/ExecutableDefinitionsRule.js +6 -4
  148. package/validation/rules/ExecutableDefinitionsRule.mjs +6 -4
  149. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +4 -4
  150. package/validation/rules/FieldsOnCorrectTypeRule.js +10 -6
  151. package/validation/rules/FieldsOnCorrectTypeRule.mjs +12 -6
  152. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -4
  153. package/validation/rules/FragmentsOnCompositeTypesRule.js +6 -4
  154. package/validation/rules/FragmentsOnCompositeTypesRule.mjs +6 -4
  155. package/validation/rules/KnownArgumentNamesRule.d.ts +4 -4
  156. package/validation/rules/KnownArgumentNamesRule.js +26 -17
  157. package/validation/rules/KnownArgumentNamesRule.mjs +21 -11
  158. package/validation/rules/KnownDirectivesRule.d.ts +1 -3
  159. package/validation/rules/KnownDirectivesRule.js +1 -3
  160. package/validation/rules/KnownDirectivesRule.mjs +1 -3
  161. package/validation/rules/KnownFragmentNamesRule.d.ts +4 -4
  162. package/validation/rules/KnownFragmentNamesRule.js +4 -4
  163. package/validation/rules/KnownFragmentNamesRule.mjs +4 -4
  164. package/validation/rules/KnownTypeNamesRule.d.ts +1 -3
  165. package/validation/rules/KnownTypeNamesRule.js +7 -7
  166. package/validation/rules/KnownTypeNamesRule.mjs +7 -7
  167. package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -4
  168. package/validation/rules/LoneAnonymousOperationRule.js +6 -4
  169. package/validation/rules/LoneAnonymousOperationRule.mjs +6 -4
  170. package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -4
  171. package/validation/rules/MaxIntrospectionDepthRule.js +44 -19
  172. package/validation/rules/MaxIntrospectionDepthRule.mjs +44 -19
  173. package/validation/rules/NoFragmentCyclesRule.d.ts +1 -3
  174. package/validation/rules/NoFragmentCyclesRule.js +1 -3
  175. package/validation/rules/NoFragmentCyclesRule.mjs +1 -3
  176. package/validation/rules/NoUndefinedVariablesRule.d.ts +4 -4
  177. package/validation/rules/NoUndefinedVariablesRule.js +4 -4
  178. package/validation/rules/NoUndefinedVariablesRule.mjs +4 -4
  179. package/validation/rules/NoUnusedFragmentsRule.d.ts +4 -4
  180. package/validation/rules/NoUnusedFragmentsRule.js +10 -14
  181. package/validation/rules/NoUnusedFragmentsRule.mjs +10 -14
  182. package/validation/rules/NoUnusedVariablesRule.d.ts +4 -4
  183. package/validation/rules/NoUnusedVariablesRule.js +4 -4
  184. package/validation/rules/NoUnusedVariablesRule.mjs +4 -4
  185. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +8 -6
  186. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +552 -354
  187. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +545 -352
  188. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -4
  189. package/validation/rules/PossibleFragmentSpreadsRule.js +6 -4
  190. package/validation/rules/PossibleFragmentSpreadsRule.mjs +6 -4
  191. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -4
  192. package/validation/rules/ProvidedRequiredArgumentsRule.js +6 -4
  193. package/validation/rules/ProvidedRequiredArgumentsRule.mjs +6 -4
  194. package/validation/rules/ScalarLeafsRule.d.ts +1 -3
  195. package/validation/rules/ScalarLeafsRule.js +1 -3
  196. package/validation/rules/ScalarLeafsRule.mjs +1 -3
  197. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -4
  198. package/validation/rules/SingleFieldSubscriptionsRule.js +50 -9
  199. package/validation/rules/SingleFieldSubscriptionsRule.mjs +50 -9
  200. package/validation/rules/UniqueArgumentNamesRule.d.ts +4 -4
  201. package/validation/rules/UniqueArgumentNamesRule.js +4 -4
  202. package/validation/rules/UniqueArgumentNamesRule.mjs +4 -4
  203. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -4
  204. package/validation/rules/UniqueDirectivesPerLocationRule.js +6 -4
  205. package/validation/rules/UniqueDirectivesPerLocationRule.mjs +6 -4
  206. package/validation/rules/UniqueFragmentNamesRule.d.ts +4 -4
  207. package/validation/rules/UniqueFragmentNamesRule.js +4 -4
  208. package/validation/rules/UniqueFragmentNamesRule.mjs +4 -4
  209. package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -4
  210. package/validation/rules/UniqueInputFieldNamesRule.js +6 -4
  211. package/validation/rules/UniqueInputFieldNamesRule.mjs +6 -4
  212. package/validation/rules/UniqueOperationNamesRule.d.ts +4 -4
  213. package/validation/rules/UniqueOperationNamesRule.js +4 -4
  214. package/validation/rules/UniqueOperationNamesRule.mjs +4 -4
  215. package/validation/rules/UniqueVariableNamesRule.d.ts +4 -4
  216. package/validation/rules/UniqueVariableNamesRule.js +4 -4
  217. package/validation/rules/UniqueVariableNamesRule.mjs +4 -4
  218. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +4 -4
  219. package/validation/rules/ValuesOfCorrectTypeRule.js +29 -23
  220. package/validation/rules/ValuesOfCorrectTypeRule.mjs +24 -14
  221. package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -4
  222. package/validation/rules/VariablesAreInputTypesRule.js +6 -4
  223. package/validation/rules/VariablesAreInputTypesRule.mjs +6 -4
  224. package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -4
  225. package/validation/rules/VariablesInAllowedPositionRule.js +6 -4
  226. package/validation/rules/VariablesInAllowedPositionRule.mjs +6 -4
  227. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +4 -4
  228. package/validation/rules/custom/NoDeprecatedCustomRule.js +4 -4
  229. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +4 -4
  230. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +7 -5
  231. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +7 -5
  232. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +7 -5
  233. package/validation/validate.d.ts +2 -0
  234. package/validation/validate.js +14 -2
  235. package/validation/validate.mjs +13 -2
  236. package/validation/validationAbortedError.d.ts +3 -0
  237. package/validation/validationAbortedError.js +14 -0
  238. package/validation/validationAbortedError.mjs +4 -0
  239. package/version.js +3 -3
  240. package/version.mjs +3 -3
@@ -96,12 +96,16 @@ export declare class GraphQLError extends Error {
96
96
  * `GraphQLError(message, options)` overload instead.
97
97
  * @example
98
98
  * ```ts
99
+ * import { Kind } from 'graphql/language';
100
+ * import assert from 'node:assert/strict';
99
101
  * // Create an error from AST nodes and response metadata.
100
102
  * import { parse } from 'graphql/language';
101
103
  * import { GraphQLError } from 'graphql/error';
102
104
  *
103
105
  * const document = parse('{ greeting }');
104
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
106
+ * const operation = document.definitions[0];
107
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
108
+ * const fieldNode = operation.selectionSet.selections[0];
105
109
  * const error = new GraphQLError('Cannot query this field.', {
106
110
  * nodes: fieldNode,
107
111
  * path: ['greeting'],
@@ -82,12 +82,16 @@ class GraphQLError extends Error {
82
82
  * `GraphQLError(message, options)` overload instead.
83
83
  * @example
84
84
  * ```ts
85
+ * import { Kind } from 'graphql/language';
86
+ * import assert from 'node:assert/strict';
85
87
  * // Create an error from AST nodes and response metadata.
86
88
  * import { parse } from 'graphql/language';
87
89
  * import { GraphQLError } from 'graphql/error';
88
90
  *
89
91
  * const document = parse('{ greeting }');
90
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
92
+ * const operation = document.definitions[0];
93
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
94
+ * const fieldNode = operation.selectionSet.selections[0];
91
95
  * const error = new GraphQLError('Cannot query this field.', {
92
96
  * nodes: fieldNode,
93
97
  * path: ['greeting'],
@@ -197,12 +201,13 @@ class GraphQLError extends Error {
197
201
  : nodeLocations.map((loc) => loc.start);
198
202
  this.locations =
199
203
  positions && source
200
- ? positions.map((pos) => (0, _location.getLocation)(source, pos))
201
- : nodeLocations === null || nodeLocations === void 0
202
- ? void 0
203
- : nodeLocations.map((loc) =>
204
- (0, _location.getLocation)(loc.source, loc.start),
205
- );
204
+ ? (0, _location.getLocations)(
205
+ positions.map((start) => ({
206
+ source,
207
+ start,
208
+ })),
209
+ )
210
+ : nodeLocations && (0, _location.getLocations)(nodeLocations);
206
211
  const originalExtensions = (0, _isObjectLike.isObjectLike)(
207
212
  originalError === null || originalError === void 0
208
213
  ? void 0
@@ -1,6 +1,6 @@
1
1
  /** @category Errors */
2
2
  import { isObjectLike } from '../jsutils/isObjectLike.mjs';
3
- import { getLocation } from '../language/location.mjs';
3
+ import { getLocations } from '../language/location.mjs';
4
4
  import {
5
5
  printLocation,
6
6
  printSourceLocation,
@@ -74,12 +74,16 @@ export class GraphQLError extends Error {
74
74
  * `GraphQLError(message, options)` overload instead.
75
75
  * @example
76
76
  * ```ts
77
+ * import { Kind } from 'graphql/language';
78
+ * import assert from 'node:assert/strict';
77
79
  * // Create an error from AST nodes and response metadata.
78
80
  * import { parse } from 'graphql/language';
79
81
  * import { GraphQLError } from 'graphql/error';
80
82
  *
81
83
  * const document = parse('{ greeting }');
82
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
84
+ * const operation = document.definitions[0];
85
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
86
+ * const fieldNode = operation.selectionSet.selections[0];
83
87
  * const error = new GraphQLError('Cannot query this field.', {
84
88
  * nodes: fieldNode,
85
89
  * path: ['greeting'],
@@ -189,10 +193,13 @@ export class GraphQLError extends Error {
189
193
  : nodeLocations.map((loc) => loc.start);
190
194
  this.locations =
191
195
  positions && source
192
- ? positions.map((pos) => getLocation(source, pos))
193
- : nodeLocations === null || nodeLocations === void 0
194
- ? void 0
195
- : nodeLocations.map((loc) => getLocation(loc.source, loc.start));
196
+ ? getLocations(
197
+ positions.map((start) => ({
198
+ source,
199
+ start,
200
+ })),
201
+ )
202
+ : nodeLocations && getLocations(nodeLocations);
196
203
  const originalExtensions = isObjectLike(
197
204
  originalError === null || originalError === void 0
198
205
  ? void 0
@@ -12,14 +12,16 @@ import { GraphQLError } from './GraphQLError';
12
12
  * @returns The GraphQL error.
13
13
  * @example
14
14
  * ```ts
15
+ * import { Kind } from 'graphql/language';
16
+ * import assert from 'node:assert/strict';
15
17
  * import { parse } from 'graphql/language';
16
18
  * import { locatedError } from 'graphql/error';
17
19
  *
18
20
  * const document = parse('{ viewer { name } }');
19
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
20
- * const error = locatedError(new Error('Resolver failed'), fieldNode, [
21
- * 'viewer',
22
- * ]);
21
+ * const operation = document.definitions[0];
22
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
23
+ * const fieldNode = operation.selectionSet.selections[0];
24
+ * const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);
23
25
  *
24
26
  * error.message; // => 'Resolver failed'
25
27
  * error.locations; // => [{ line: 1, column: 3 }]
@@ -21,14 +21,16 @@ var _GraphQLError = require('./GraphQLError.js');
21
21
  * @returns The GraphQL error.
22
22
  * @example
23
23
  * ```ts
24
+ * import { Kind } from 'graphql/language';
25
+ * import assert from 'node:assert/strict';
24
26
  * import { parse } from 'graphql/language';
25
27
  * import { locatedError } from 'graphql/error';
26
28
  *
27
29
  * const document = parse('{ viewer { name } }');
28
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
29
- * const error = locatedError(new Error('Resolver failed'), fieldNode, [
30
- * 'viewer',
31
- * ]);
30
+ * const operation = document.definitions[0];
31
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
32
+ * const fieldNode = operation.selectionSet.selections[0];
33
+ * const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);
32
34
  *
33
35
  * error.message; // => 'Resolver failed'
34
36
  * error.locations; // => [{ line: 1, column: 3 }]
@@ -11,14 +11,16 @@ import { GraphQLError } from './GraphQLError.mjs';
11
11
  * @returns The GraphQL error.
12
12
  * @example
13
13
  * ```ts
14
+ * import { Kind } from 'graphql/language';
15
+ * import assert from 'node:assert/strict';
14
16
  * import { parse } from 'graphql/language';
15
17
  * import { locatedError } from 'graphql/error';
16
18
  *
17
19
  * const document = parse('{ viewer { name } }');
18
- * const fieldNode = document.definitions[0].selectionSet.selections[0];
19
- * const error = locatedError(new Error('Resolver failed'), fieldNode, [
20
- * 'viewer',
21
- * ]);
20
+ * const operation = document.definitions[0];
21
+ * assert(operation.kind === Kind.OPERATION_DEFINITION);
22
+ * const fieldNode = operation.selectionSet.selections[0];
23
+ * const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);
22
24
  *
23
25
  * error.message; // => 'Resolver failed'
24
26
  * error.locations; // => [{ line: 1, column: 3 }]
@@ -23,6 +23,7 @@ export declare function collectFields(
23
23
  },
24
24
  runtimeType: GraphQLObjectType,
25
25
  selectionSet: SelectionSetNode,
26
+ onSelectionSet?: (selectionSet: SelectionSetNode) => void,
26
27
  ): Map<string, ReadonlyArray<FieldNode>>;
27
28
  /**
28
29
  * Given an array of field nodes, collects all of the subfields of the passed
@@ -31,6 +31,7 @@ function collectFields(
31
31
  variableValues,
32
32
  runtimeType,
33
33
  selectionSet,
34
+ onSelectionSet,
34
35
  ) {
35
36
  const fields = new Map();
36
37
  collectFieldsImpl(
@@ -41,6 +42,7 @@ function collectFields(
41
42
  selectionSet,
42
43
  fields,
43
44
  new Set(),
45
+ onSelectionSet,
44
46
  );
45
47
  return fields;
46
48
  }
@@ -90,7 +92,12 @@ function collectFieldsImpl(
90
92
  selectionSet,
91
93
  fields,
92
94
  visitedFragmentNames,
95
+ onSelectionSet,
93
96
  ) {
97
+ onSelectionSet === null || onSelectionSet === void 0
98
+ ? void 0
99
+ : onSelectionSet(selectionSet);
100
+
94
101
  for (const selection of selectionSet.selections) {
95
102
  switch (selection.kind) {
96
103
  case _kinds.Kind.FIELD: {
@@ -126,6 +133,7 @@ function collectFieldsImpl(
126
133
  selection.selectionSet,
127
134
  fields,
128
135
  visitedFragmentNames,
136
+ onSelectionSet,
129
137
  );
130
138
  break;
131
139
  }
@@ -158,6 +166,7 @@ function collectFieldsImpl(
158
166
  fragment.selectionSet,
159
167
  fields,
160
168
  visitedFragmentNames,
169
+ onSelectionSet,
161
170
  );
162
171
  break;
163
172
  }
@@ -22,6 +22,7 @@ export function collectFields(
22
22
  variableValues,
23
23
  runtimeType,
24
24
  selectionSet,
25
+ onSelectionSet,
25
26
  ) {
26
27
  const fields = new Map();
27
28
  collectFieldsImpl(
@@ -32,6 +33,7 @@ export function collectFields(
32
33
  selectionSet,
33
34
  fields,
34
35
  new Set(),
36
+ onSelectionSet,
35
37
  );
36
38
  return fields;
37
39
  }
@@ -81,7 +83,12 @@ function collectFieldsImpl(
81
83
  selectionSet,
82
84
  fields,
83
85
  visitedFragmentNames,
86
+ onSelectionSet,
84
87
  ) {
88
+ onSelectionSet === null || onSelectionSet === void 0
89
+ ? void 0
90
+ : onSelectionSet(selectionSet);
91
+
85
92
  for (const selection of selectionSet.selections) {
86
93
  switch (selection.kind) {
87
94
  case Kind.FIELD: {
@@ -117,6 +124,7 @@ function collectFieldsImpl(
117
124
  selection.selectionSet,
118
125
  fields,
119
126
  visitedFragmentNames,
127
+ onSelectionSet,
120
128
  );
121
129
  break;
122
130
  }
@@ -149,6 +157,7 @@ function collectFieldsImpl(
149
157
  fragment.selectionSet,
150
158
  fields,
151
159
  visitedFragmentNames,
160
+ onSelectionSet,
152
161
  );
153
162
  break;
154
163
  }
@@ -102,6 +102,8 @@ export interface FormattedExecutionResult<
102
102
  }
103
103
  /** Arguments accepted by execute and executeSync. */
104
104
  export interface ExecutionArgs {
105
+ /** Omit suggestions from input coercion errors. */
106
+ hideSuggestions?: Maybe<boolean>;
105
107
  /** The schema used for validation or execution. */
106
108
  schema: GraphQLSchema;
107
109
  /** The parsed GraphQL document to execute. */
@@ -162,12 +164,10 @@ export interface ExecutionArgs {
162
164
  * schema,
163
165
  * document: parse('query ($name: String!) { greeting(name: $name) }'),
164
166
  * rootValue: {
165
- * greeting: ({ name }) => `Hello, ${name}!`,
167
+ * greeting: ({ name }: { name: string }) => `Hello, ${name}!`,
166
168
  * },
167
169
  * variableValues: { name: 'Ada' },
168
- * });
169
- *
170
- * result; // => { data: { greeting: 'Hello, Ada!' } }
170
+ * }); // => { data: { greeting: 'Hello, Ada!' } }
171
171
  * ```
172
172
  * @example
173
173
  * ```ts
@@ -196,8 +196,7 @@ export interface ExecutionArgs {
196
196
  * rootValue: { viewer: { kind: 'user', name: 'Ada' } },
197
197
  * contextValue: { locale: 'en' },
198
198
  * operationName: 'Viewer',
199
- * fieldResolver: (source, _args, contextValue, info) => {
200
- * contextValue.locale; // => 'en'
199
+ * fieldResolver: (source, _args, _contextValue, info) => {
201
200
  * return source[info.fieldName];
202
201
  * },
203
202
  * typeResolver: (value) => {
@@ -231,8 +230,8 @@ export interface ExecutionArgs {
231
230
  * },
232
231
  * });
233
232
  *
234
- * result.data.broken; // => null
235
- * result.errors[0].message; // => 'Resolver failed.'
233
+ * result.data?.broken; // => null
234
+ * result.errors?.[0].message; // => 'Resolver failed.'
236
235
  * ```
237
236
  * @example
238
237
  * ```ts
@@ -267,8 +266,8 @@ export interface ExecutionArgs {
267
266
  * options: { maxCoercionErrors: 1 },
268
267
  * });
269
268
  *
270
- * result.errors.length; // => 2
271
- * result.errors[1].message; // matches /error limit reached/
269
+ * result.errors?.length; // => 2
270
+ * result.errors?.[1].message.includes('error limit reached'); // => true
272
271
  * ```
273
272
  */
274
273
  export declare function execute(
@@ -175,12 +175,10 @@ class CollectedErrors {
175
175
  * schema,
176
176
  * document: parse('query ($name: String!) { greeting(name: $name) }'),
177
177
  * rootValue: {
178
- * greeting: ({ name }) => `Hello, ${name}!`,
178
+ * greeting: ({ name }: { name: string }) => `Hello, ${name}!`,
179
179
  * },
180
180
  * variableValues: { name: 'Ada' },
181
- * });
182
- *
183
- * result; // => { data: { greeting: 'Hello, Ada!' } }
181
+ * }); // => { data: { greeting: 'Hello, Ada!' } }
184
182
  * ```
185
183
  * @example
186
184
  * ```ts
@@ -209,8 +207,7 @@ class CollectedErrors {
209
207
  * rootValue: { viewer: { kind: 'user', name: 'Ada' } },
210
208
  * contextValue: { locale: 'en' },
211
209
  * operationName: 'Viewer',
212
- * fieldResolver: (source, _args, contextValue, info) => {
213
- * contextValue.locale; // => 'en'
210
+ * fieldResolver: (source, _args, _contextValue, info) => {
214
211
  * return source[info.fieldName];
215
212
  * },
216
213
  * typeResolver: (value) => {
@@ -244,8 +241,8 @@ class CollectedErrors {
244
241
  * },
245
242
  * });
246
243
  *
247
- * result.data.broken; // => null
248
- * result.errors[0].message; // => 'Resolver failed.'
244
+ * result.data?.broken; // => null
245
+ * result.errors?.[0].message; // => 'Resolver failed.'
249
246
  * ```
250
247
  * @example
251
248
  * ```ts
@@ -280,8 +277,8 @@ class CollectedErrors {
280
277
  * options: { maxCoercionErrors: 1 },
281
278
  * });
282
279
  *
283
- * result.errors.length; // => 2
284
- * result.errors[1].message; // matches /error limit reached/
280
+ * result.errors?.length; // => 2
281
+ * result.errors?.[1].message.includes('error limit reached'); // => true
285
282
  * ```
286
283
  */
287
284
  function execute(args) {
@@ -435,7 +432,10 @@ function assertValidExecutionArguments(schema, document, rawVariableValues) {
435
432
  */
436
433
 
437
434
  function buildExecutionContext(args) {
438
- var _definition$name, _operation$variableDe, _options$maxCoercionE;
435
+ var _definition$name,
436
+ _operation$variableDe,
437
+ _options$maxCoercionE,
438
+ _args$hideSuggestions;
439
439
 
440
440
  const {
441
441
  schema,
@@ -518,6 +518,11 @@ function buildExecutionContext(args) {
518
518
  _options$maxCoercionE !== void 0
519
519
  ? _options$maxCoercionE
520
520
  : 50,
521
+ hideSuggestions:
522
+ (_args$hideSuggestions = args.hideSuggestions) !== null &&
523
+ _args$hideSuggestions !== void 0
524
+ ? _args$hideSuggestions
525
+ : false,
521
526
  },
522
527
  );
523
528
 
@@ -1206,27 +1211,37 @@ const defaultTypeResolver = function (value, contextValue, info, abstractType) {
1206
1211
  const possibleTypes = info.schema.getPossibleTypes(abstractType);
1207
1212
  const promisedIsTypeOfResults = [];
1208
1213
 
1209
- for (let i = 0; i < possibleTypes.length; i++) {
1210
- const type = possibleTypes[i];
1211
-
1212
- if (type.isTypeOf) {
1213
- const isTypeOfResult = type.isTypeOf(value, contextValue, info);
1214
-
1215
- if ((0, _isPromise.isPromise)(isTypeOfResult)) {
1216
- promisedIsTypeOfResults[i] = isTypeOfResult;
1217
- } else if (isTypeOfResult) {
1218
- if (promisedIsTypeOfResults.length) {
1219
- // Explicitly ignore any promise rejections
1220
- Promise.allSettled(promisedIsTypeOfResults)
1221
- /* c8 ignore next 3 */
1222
- .catch(() => {
1223
- // Do nothing
1224
- });
1225
- }
1214
+ try {
1215
+ for (let i = 0; i < possibleTypes.length; i++) {
1216
+ const type = possibleTypes[i];
1217
+
1218
+ if (type.isTypeOf) {
1219
+ const isTypeOfResult = type.isTypeOf(value, contextValue, info);
1220
+
1221
+ if ((0, _isPromise.isPromise)(isTypeOfResult)) {
1222
+ promisedIsTypeOfResults[i] = isTypeOfResult;
1223
+ } else if (isTypeOfResult) {
1224
+ if (promisedIsTypeOfResults.length) {
1225
+ // Explicitly ignore any promise rejections
1226
+ Promise.allSettled(promisedIsTypeOfResults)
1227
+ /* c8 ignore next 3 */
1228
+ .catch(() => {
1229
+ // Do nothing
1230
+ });
1231
+ }
1226
1232
 
1227
- return type.name;
1233
+ return type.name;
1234
+ }
1228
1235
  }
1229
1236
  }
1237
+ } catch (error) {
1238
+ if (promisedIsTypeOfResults.length) {
1239
+ return Promise.allSettled(promisedIsTypeOfResults).then(() => {
1240
+ throw error;
1241
+ });
1242
+ }
1243
+
1244
+ throw error;
1230
1245
  }
1231
1246
 
1232
1247
  if (promisedIsTypeOfResults.length) {
@@ -155,12 +155,10 @@ class CollectedErrors {
155
155
  * schema,
156
156
  * document: parse('query ($name: String!) { greeting(name: $name) }'),
157
157
  * rootValue: {
158
- * greeting: ({ name }) => `Hello, ${name}!`,
158
+ * greeting: ({ name }: { name: string }) => `Hello, ${name}!`,
159
159
  * },
160
160
  * variableValues: { name: 'Ada' },
161
- * });
162
- *
163
- * result; // => { data: { greeting: 'Hello, Ada!' } }
161
+ * }); // => { data: { greeting: 'Hello, Ada!' } }
164
162
  * ```
165
163
  * @example
166
164
  * ```ts
@@ -189,8 +187,7 @@ class CollectedErrors {
189
187
  * rootValue: { viewer: { kind: 'user', name: 'Ada' } },
190
188
  * contextValue: { locale: 'en' },
191
189
  * operationName: 'Viewer',
192
- * fieldResolver: (source, _args, contextValue, info) => {
193
- * contextValue.locale; // => 'en'
190
+ * fieldResolver: (source, _args, _contextValue, info) => {
194
191
  * return source[info.fieldName];
195
192
  * },
196
193
  * typeResolver: (value) => {
@@ -224,8 +221,8 @@ class CollectedErrors {
224
221
  * },
225
222
  * });
226
223
  *
227
- * result.data.broken; // => null
228
- * result.errors[0].message; // => 'Resolver failed.'
224
+ * result.data?.broken; // => null
225
+ * result.errors?.[0].message; // => 'Resolver failed.'
229
226
  * ```
230
227
  * @example
231
228
  * ```ts
@@ -260,8 +257,8 @@ class CollectedErrors {
260
257
  * options: { maxCoercionErrors: 1 },
261
258
  * });
262
259
  *
263
- * result.errors.length; // => 2
264
- * result.errors[1].message; // matches /error limit reached/
260
+ * result.errors?.length; // => 2
261
+ * result.errors?.[1].message.includes('error limit reached'); // => true
265
262
  * ```
266
263
  */
267
264
  export function execute(args) {
@@ -419,7 +416,10 @@ export function assertValidExecutionArguments(
419
416
  */
420
417
 
421
418
  export function buildExecutionContext(args) {
422
- var _definition$name, _operation$variableDe, _options$maxCoercionE;
419
+ var _definition$name,
420
+ _operation$variableDe,
421
+ _options$maxCoercionE,
422
+ _args$hideSuggestions;
423
423
 
424
424
  const {
425
425
  schema,
@@ -498,6 +498,11 @@ export function buildExecutionContext(args) {
498
498
  _options$maxCoercionE !== void 0
499
499
  ? _options$maxCoercionE
500
500
  : 50,
501
+ hideSuggestions:
502
+ (_args$hideSuggestions = args.hideSuggestions) !== null &&
503
+ _args$hideSuggestions !== void 0
504
+ ? _args$hideSuggestions
505
+ : false,
501
506
  },
502
507
  );
503
508
 
@@ -1176,27 +1181,37 @@ export const defaultTypeResolver = function (
1176
1181
  const possibleTypes = info.schema.getPossibleTypes(abstractType);
1177
1182
  const promisedIsTypeOfResults = [];
1178
1183
 
1179
- for (let i = 0; i < possibleTypes.length; i++) {
1180
- const type = possibleTypes[i];
1181
-
1182
- if (type.isTypeOf) {
1183
- const isTypeOfResult = type.isTypeOf(value, contextValue, info);
1184
-
1185
- if (isPromise(isTypeOfResult)) {
1186
- promisedIsTypeOfResults[i] = isTypeOfResult;
1187
- } else if (isTypeOfResult) {
1188
- if (promisedIsTypeOfResults.length) {
1189
- // Explicitly ignore any promise rejections
1190
- Promise.allSettled(promisedIsTypeOfResults)
1191
- /* c8 ignore next 3 */
1192
- .catch(() => {
1193
- // Do nothing
1194
- });
1195
- }
1184
+ try {
1185
+ for (let i = 0; i < possibleTypes.length; i++) {
1186
+ const type = possibleTypes[i];
1187
+
1188
+ if (type.isTypeOf) {
1189
+ const isTypeOfResult = type.isTypeOf(value, contextValue, info);
1190
+
1191
+ if (isPromise(isTypeOfResult)) {
1192
+ promisedIsTypeOfResults[i] = isTypeOfResult;
1193
+ } else if (isTypeOfResult) {
1194
+ if (promisedIsTypeOfResults.length) {
1195
+ // Explicitly ignore any promise rejections
1196
+ Promise.allSettled(promisedIsTypeOfResults)
1197
+ /* c8 ignore next 3 */
1198
+ .catch(() => {
1199
+ // Do nothing
1200
+ });
1201
+ }
1196
1202
 
1197
- return type.name;
1203
+ return type.name;
1204
+ }
1198
1205
  }
1199
1206
  }
1207
+ } catch (error) {
1208
+ if (promisedIsTypeOfResults.length) {
1209
+ return Promise.allSettled(promisedIsTypeOfResults).then(() => {
1210
+ throw error;
1211
+ });
1212
+ }
1213
+
1214
+ throw error;
1200
1215
  }
1201
1216
 
1202
1217
  if (promisedIsTypeOfResults.length) {
@@ -25,18 +25,18 @@ function mapAsyncIterator(iterable, callback) {
25
25
  done: false,
26
26
  };
27
27
  } catch (error) {
28
- /* c8 ignore start */
29
- // FIXME: add test case
30
- if (typeof iterator.return === 'function') {
31
- try {
32
- await iterator.return();
33
- } catch (_e) {
34
- /* ignore error */
35
- }
36
- }
37
-
28
+ await returnIgnoringErrors();
38
29
  throw error;
39
- /* c8 ignore stop */
30
+ }
31
+ }
32
+
33
+ async function returnIgnoringErrors() {
34
+ if (typeof iterator.return === 'function') {
35
+ try {
36
+ await iterator.return();
37
+ } catch (_error) {
38
+ // Keep the original error when closing the source also fails.
39
+ }
40
40
  }
41
41
  }
42
42
 
@@ -60,6 +60,7 @@ function mapAsyncIterator(iterable, callback) {
60
60
  return mapResult(await iterator.throw(error));
61
61
  }
62
62
 
63
+ await returnIgnoringErrors();
63
64
  throw error;
64
65
  },
65
66
 
@@ -18,18 +18,18 @@ export function mapAsyncIterator(iterable, callback) {
18
18
  done: false,
19
19
  };
20
20
  } catch (error) {
21
- /* c8 ignore start */
22
- // FIXME: add test case
23
- if (typeof iterator.return === 'function') {
24
- try {
25
- await iterator.return();
26
- } catch (_e) {
27
- /* ignore error */
28
- }
29
- }
30
-
21
+ await returnIgnoringErrors();
31
22
  throw error;
32
- /* c8 ignore stop */
23
+ }
24
+ }
25
+
26
+ async function returnIgnoringErrors() {
27
+ if (typeof iterator.return === 'function') {
28
+ try {
29
+ await iterator.return();
30
+ } catch (_error) {
31
+ // Keep the original error when closing the source also fails.
32
+ }
33
33
  }
34
34
  }
35
35
 
@@ -53,6 +53,7 @@ export function mapAsyncIterator(iterable, callback) {
53
53
  return mapResult(await iterator.throw(error));
54
54
  }
55
55
 
56
+ await returnIgnoringErrors();
56
57
  throw error;
57
58
  },
58
59
 
@@ -97,7 +97,10 @@ import type { ExecutionArgs, ExecutionResult } from './execute';
97
97
  * 'subscription Greeting($locale: String) { greeting(locale: $locale) }',
98
98
  * ),
99
99
  * rootValue: {
100
- * greeting: (args, contextValue) => {
100
+ * greeting: (
101
+ * args: { locale?: string },
102
+ * contextValue: { defaultLocale: string },
103
+ * ) => {
101
104
  * const locale = args.locale ?? contextValue.defaultLocale;
102
105
  * return locale === 'fr' ? frenchGreetings() : defaultGreetings();
103
106
  * },
@@ -137,7 +140,7 @@ import type { ExecutionArgs, ExecutionResult } from './execute';
137
140
  *
138
141
  * assert('errors' in result);
139
142
  *
140
- * result.errors[0].message; // => 'Schema is not configured to execute subscription operation.'
143
+ * result.errors?.[0].message; // => 'Schema is not configured to execute subscription operation.'
141
144
  * ```
142
145
  */
143
146
  export declare function subscribe(