graphql 17.0.0-rc.0 → 17.0.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 (232) hide show
  1. package/README.md +3 -5
  2. package/diagnostics.d.mts +67 -38
  3. package/diagnostics.d.ts +67 -38
  4. package/diagnostics.js +2 -1
  5. package/diagnostics.js.map +1 -1
  6. package/diagnostics.mjs +2 -1
  7. package/diagnostics.mjs.map +1 -1
  8. package/error/locatedError.d.mts +1 -3
  9. package/error/locatedError.d.ts +1 -3
  10. package/error/locatedError.js.map +1 -1
  11. package/error/locatedError.mjs.map +1 -1
  12. package/execution/Executor.d.mts +2 -2
  13. package/execution/Executor.d.ts +2 -2
  14. package/execution/Executor.js.map +1 -1
  15. package/execution/Executor.mjs.map +1 -1
  16. package/execution/execute.d.mts +65 -44
  17. package/execution/execute.d.ts +65 -44
  18. package/execution/execute.js +11 -2
  19. package/execution/execute.js.map +1 -1
  20. package/execution/execute.mjs +11 -2
  21. package/execution/execute.mjs.map +1 -1
  22. package/execution/values.d.mts +17 -17
  23. package/execution/values.d.ts +17 -17
  24. package/execution/values.js.map +1 -1
  25. package/execution/values.mjs.map +1 -1
  26. package/language/parser.d.mts +20 -30
  27. package/language/parser.d.ts +20 -30
  28. package/language/parser.js +3 -9
  29. package/language/parser.js.map +1 -1
  30. package/language/parser.mjs +3 -9
  31. package/language/parser.mjs.map +1 -1
  32. package/language/predicates.d.mts +5 -1
  33. package/language/predicates.d.ts +5 -1
  34. package/language/predicates.js.map +1 -1
  35. package/language/predicates.mjs.map +1 -1
  36. package/language/source.d.mts +4 -5
  37. package/language/source.d.ts +4 -5
  38. package/language/source.js.map +1 -1
  39. package/language/source.mjs.map +1 -1
  40. package/language/visitor.d.mts +10 -2
  41. package/language/visitor.d.ts +10 -2
  42. package/language/visitor.js.map +1 -1
  43. package/language/visitor.mjs.map +1 -1
  44. package/package.json +1 -4
  45. package/type/definition.d.mts +96 -64
  46. package/type/definition.d.ts +96 -64
  47. package/type/definition.js.map +1 -1
  48. package/type/definition.mjs.map +1 -1
  49. package/type/directives.d.mts +3 -3
  50. package/type/directives.d.ts +3 -3
  51. package/type/directives.js.map +1 -1
  52. package/type/directives.mjs.map +1 -1
  53. package/type/schema.d.mts +4 -8
  54. package/type/schema.d.ts +4 -8
  55. package/type/schema.js.map +1 -1
  56. package/type/schema.mjs.map +1 -1
  57. package/type/validate.js +101 -30
  58. package/type/validate.js.map +1 -1
  59. package/type/validate.mjs +101 -30
  60. package/type/validate.mjs.map +1 -1
  61. package/utilities/TypeInfo.d.mts +1 -1
  62. package/utilities/TypeInfo.d.ts +1 -1
  63. package/utilities/TypeInfo.js.map +1 -1
  64. package/utilities/TypeInfo.mjs.map +1 -1
  65. package/utilities/buildASTSchema.d.mts +0 -1
  66. package/utilities/buildASTSchema.d.ts +0 -1
  67. package/utilities/buildASTSchema.js +0 -1
  68. package/utilities/buildASTSchema.js.map +1 -1
  69. package/utilities/buildASTSchema.mjs +0 -1
  70. package/utilities/buildASTSchema.mjs.map +1 -1
  71. package/utilities/buildClientSchema.d.mts +5 -1
  72. package/utilities/buildClientSchema.d.ts +5 -1
  73. package/utilities/buildClientSchema.js.map +1 -1
  74. package/utilities/buildClientSchema.mjs.map +1 -1
  75. package/utilities/coerceInputValue.d.mts +7 -6
  76. package/utilities/coerceInputValue.d.ts +7 -6
  77. package/utilities/coerceInputValue.js.map +1 -1
  78. package/utilities/coerceInputValue.mjs.map +1 -1
  79. package/utilities/concatAST.d.mts +4 -1
  80. package/utilities/concatAST.d.ts +4 -1
  81. package/utilities/concatAST.js.map +1 -1
  82. package/utilities/concatAST.mjs.map +1 -1
  83. package/utilities/extendSchema.d.mts +3 -3
  84. package/utilities/extendSchema.d.ts +3 -3
  85. package/utilities/extendSchema.js +5 -1
  86. package/utilities/extendSchema.js.map +1 -1
  87. package/utilities/extendSchema.mjs +5 -1
  88. package/utilities/extendSchema.mjs.map +1 -1
  89. package/utilities/introspectionFromSchema.d.mts +6 -2
  90. package/utilities/introspectionFromSchema.d.ts +6 -2
  91. package/utilities/introspectionFromSchema.js.map +1 -1
  92. package/utilities/introspectionFromSchema.mjs.map +1 -1
  93. package/utilities/lexicographicSortSchema.d.mts +5 -1
  94. package/utilities/lexicographicSortSchema.d.ts +5 -1
  95. package/utilities/lexicographicSortSchema.js.map +1 -1
  96. package/utilities/lexicographicSortSchema.mjs.map +1 -1
  97. package/utilities/printSchema.d.mts +5 -1
  98. package/utilities/printSchema.d.ts +5 -1
  99. package/utilities/printSchema.js.map +1 -1
  100. package/utilities/printSchema.mjs.map +1 -1
  101. package/utilities/replaceVariables.d.mts +4 -8
  102. package/utilities/replaceVariables.d.ts +4 -8
  103. package/utilities/replaceVariables.js.map +1 -1
  104. package/utilities/replaceVariables.mjs.map +1 -1
  105. package/utilities/stripIgnoredCharacters.d.mts +2 -2
  106. package/utilities/stripIgnoredCharacters.d.ts +2 -2
  107. package/utilities/stripIgnoredCharacters.js.map +1 -1
  108. package/utilities/stripIgnoredCharacters.mjs.map +1 -1
  109. package/utilities/typeComparators.d.mts +1 -5
  110. package/utilities/typeComparators.d.ts +1 -5
  111. package/utilities/typeComparators.js.map +1 -1
  112. package/utilities/typeComparators.mjs.map +1 -1
  113. package/utilities/validateInputValue.d.mts +10 -8
  114. package/utilities/validateInputValue.d.ts +10 -8
  115. package/utilities/validateInputValue.js.map +1 -1
  116. package/utilities/validateInputValue.mjs.map +1 -1
  117. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.mts +4 -1
  118. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.ts +4 -1
  119. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js.map +1 -1
  120. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs.map +1 -1
  121. package/validation/rules/ExecutableDefinitionsRule.d.mts +6 -2
  122. package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -2
  123. package/validation/rules/ExecutableDefinitionsRule.js.map +1 -1
  124. package/validation/rules/ExecutableDefinitionsRule.mjs.map +1 -1
  125. package/validation/rules/FieldsOnCorrectTypeRule.d.mts +3 -1
  126. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +3 -1
  127. package/validation/rules/FieldsOnCorrectTypeRule.js.map +1 -1
  128. package/validation/rules/FieldsOnCorrectTypeRule.mjs.map +1 -1
  129. package/validation/rules/FragmentsOnCompositeTypesRule.d.mts +6 -2
  130. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -2
  131. package/validation/rules/FragmentsOnCompositeTypesRule.js.map +1 -1
  132. package/validation/rules/FragmentsOnCompositeTypesRule.mjs.map +1 -1
  133. package/validation/rules/KnownArgumentNamesRule.d.mts +3 -1
  134. package/validation/rules/KnownArgumentNamesRule.d.ts +3 -1
  135. package/validation/rules/KnownArgumentNamesRule.js.map +1 -1
  136. package/validation/rules/KnownArgumentNamesRule.mjs.map +1 -1
  137. package/validation/rules/KnownDirectivesRule.js +2 -1
  138. package/validation/rules/KnownDirectivesRule.js.map +1 -1
  139. package/validation/rules/KnownDirectivesRule.mjs +2 -1
  140. package/validation/rules/KnownDirectivesRule.mjs.map +1 -1
  141. package/validation/rules/KnownFragmentNamesRule.d.mts +3 -1
  142. package/validation/rules/KnownFragmentNamesRule.d.ts +3 -1
  143. package/validation/rules/KnownFragmentNamesRule.js.map +1 -1
  144. package/validation/rules/KnownFragmentNamesRule.mjs.map +1 -1
  145. package/validation/rules/LoneAnonymousOperationRule.d.mts +6 -2
  146. package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -2
  147. package/validation/rules/LoneAnonymousOperationRule.js.map +1 -1
  148. package/validation/rules/LoneAnonymousOperationRule.mjs.map +1 -1
  149. package/validation/rules/MaxIntrospectionDepthRule.d.mts +6 -2
  150. package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -2
  151. package/validation/rules/MaxIntrospectionDepthRule.js.map +1 -1
  152. package/validation/rules/MaxIntrospectionDepthRule.mjs.map +1 -1
  153. package/validation/rules/NoUndefinedVariablesRule.d.mts +3 -1
  154. package/validation/rules/NoUndefinedVariablesRule.d.ts +3 -1
  155. package/validation/rules/NoUndefinedVariablesRule.js.map +1 -1
  156. package/validation/rules/NoUndefinedVariablesRule.mjs.map +1 -1
  157. package/validation/rules/NoUnusedFragmentsRule.d.mts +3 -1
  158. package/validation/rules/NoUnusedFragmentsRule.d.ts +3 -1
  159. package/validation/rules/NoUnusedFragmentsRule.js.map +1 -1
  160. package/validation/rules/NoUnusedFragmentsRule.mjs.map +1 -1
  161. package/validation/rules/NoUnusedVariablesRule.d.mts +3 -1
  162. package/validation/rules/NoUnusedVariablesRule.d.ts +3 -1
  163. package/validation/rules/NoUnusedVariablesRule.js.map +1 -1
  164. package/validation/rules/NoUnusedVariablesRule.mjs.map +1 -1
  165. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.mts +6 -2
  166. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +6 -2
  167. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.map +1 -1
  168. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs.map +1 -1
  169. package/validation/rules/PossibleFragmentSpreadsRule.d.mts +6 -2
  170. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -2
  171. package/validation/rules/PossibleFragmentSpreadsRule.js.map +1 -1
  172. package/validation/rules/PossibleFragmentSpreadsRule.mjs.map +1 -1
  173. package/validation/rules/ProvidedRequiredArgumentsRule.d.mts +6 -2
  174. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -2
  175. package/validation/rules/ProvidedRequiredArgumentsRule.js.map +1 -1
  176. package/validation/rules/ProvidedRequiredArgumentsRule.mjs.map +1 -1
  177. package/validation/rules/SingleFieldSubscriptionsRule.d.mts +6 -2
  178. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -2
  179. package/validation/rules/SingleFieldSubscriptionsRule.js.map +1 -1
  180. package/validation/rules/SingleFieldSubscriptionsRule.mjs.map +1 -1
  181. package/validation/rules/UniqueArgumentNamesRule.d.mts +3 -1
  182. package/validation/rules/UniqueArgumentNamesRule.d.ts +3 -1
  183. package/validation/rules/UniqueArgumentNamesRule.js.map +1 -1
  184. package/validation/rules/UniqueArgumentNamesRule.mjs.map +1 -1
  185. package/validation/rules/UniqueDirectivesPerLocationRule.d.mts +6 -2
  186. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -2
  187. package/validation/rules/UniqueDirectivesPerLocationRule.js.map +1 -1
  188. package/validation/rules/UniqueDirectivesPerLocationRule.mjs.map +1 -1
  189. package/validation/rules/UniqueFragmentNamesRule.d.mts +3 -1
  190. package/validation/rules/UniqueFragmentNamesRule.d.ts +3 -1
  191. package/validation/rules/UniqueFragmentNamesRule.js.map +1 -1
  192. package/validation/rules/UniqueFragmentNamesRule.mjs.map +1 -1
  193. package/validation/rules/UniqueInputFieldNamesRule.d.mts +6 -2
  194. package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -2
  195. package/validation/rules/UniqueInputFieldNamesRule.js.map +1 -1
  196. package/validation/rules/UniqueInputFieldNamesRule.mjs.map +1 -1
  197. package/validation/rules/UniqueOperationNamesRule.d.mts +3 -1
  198. package/validation/rules/UniqueOperationNamesRule.d.ts +3 -1
  199. package/validation/rules/UniqueOperationNamesRule.js.map +1 -1
  200. package/validation/rules/UniqueOperationNamesRule.mjs.map +1 -1
  201. package/validation/rules/UniqueVariableNamesRule.d.mts +3 -1
  202. package/validation/rules/UniqueVariableNamesRule.d.ts +3 -1
  203. package/validation/rules/UniqueVariableNamesRule.js.map +1 -1
  204. package/validation/rules/UniqueVariableNamesRule.mjs.map +1 -1
  205. package/validation/rules/ValuesOfCorrectTypeRule.d.mts +3 -1
  206. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +3 -1
  207. package/validation/rules/ValuesOfCorrectTypeRule.js.map +1 -1
  208. package/validation/rules/ValuesOfCorrectTypeRule.mjs.map +1 -1
  209. package/validation/rules/VariablesAreInputTypesRule.d.mts +6 -2
  210. package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -2
  211. package/validation/rules/VariablesAreInputTypesRule.js.map +1 -1
  212. package/validation/rules/VariablesAreInputTypesRule.mjs.map +1 -1
  213. package/validation/rules/VariablesInAllowedPositionRule.d.mts +6 -2
  214. package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -2
  215. package/validation/rules/VariablesInAllowedPositionRule.js.map +1 -1
  216. package/validation/rules/VariablesInAllowedPositionRule.mjs.map +1 -1
  217. package/validation/rules/custom/NoDeprecatedCustomRule.d.mts +3 -1
  218. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +3 -1
  219. package/validation/rules/custom/NoDeprecatedCustomRule.js.map +1 -1
  220. package/validation/rules/custom/NoDeprecatedCustomRule.mjs.map +1 -1
  221. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.mts +6 -2
  222. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +6 -2
  223. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.map +1 -1
  224. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs.map +1 -1
  225. package/validation/validate.d.mts +3 -6
  226. package/validation/validate.d.ts +3 -6
  227. package/validation/validate.js.map +1 -1
  228. package/validation/validate.mjs.map +1 -1
  229. package/version.js +3 -3
  230. package/version.js.map +1 -1
  231. package/version.mjs +3 -3
  232. package/version.mjs.map +1 -1
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
- [![GraphQLConf 2025 Banner: September 08-10, Amsterdam. Hosted by the GraphQL Foundation](./assets/graphql-conf-2025.png)](https://graphql.org/conf/2025/?utm_source=github&utm_medium=graphql_js&utm_campaign=readme)
2
-
3
1
  # GraphQL.js
4
2
 
5
3
  The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.
6
4
 
7
5
  [![npm version](https://badge.fury.io/js/graphql.svg)](https://badge.fury.io/js/graphql)
8
- [![Build Status](https://github.com/graphql/graphql-js/workflows/CI/badge.svg?branch=main)](https://github.com/graphql/graphql-js/actions?query=branch%3Amain)
6
+ [![Build Status](https://github.com/graphql/graphql-js/actions/workflows/push.yml/badge.svg?branch=17.x.x)](https://github.com/graphql/graphql-js/actions/workflows/push.yml?query=branch%3A17.x.x)
9
7
 
10
8
  See more complete documentation at https://graphql.org/ and
11
9
  https://graphql.org/graphql-js/.
@@ -111,7 +109,7 @@ graphql({ schema, source }).then((result) => {
111
109
  ## Want to ride the bleeding edge?
112
110
 
113
111
  The `npm` branch in this repository is automatically maintained to be the last
114
- commit to `main` to pass all tests, in the same form found on npm. It is
112
+ commit to `17.x.x` to pass all tests, in the same form found on npm. It is
115
113
  recommended to use builds deployed to npm for many reasons, but if you want to use
116
114
  the latest not-yet-released version of graphql-js, you can do so by depending
117
115
  directly on this branch:
@@ -139,7 +137,7 @@ in files with the `.js` extension and the ESModule build within `.mjs` files.
139
137
 
140
138
  We actively welcome pull requests. Learn how to [contribute](./.github/CONTRIBUTING.md).
141
139
 
142
- This repository is managed by EasyCLA. Project participants must sign the free ([GraphQL Specification Membership agreement](https://preview-spec-membership.graphql.org) before making a contribution. You only need to do this one time, and it can be signed by [individual contributors](http://individual-spec-membership.graphql.org/) or their [employers](http://corporate-spec-membership.graphql.org/).
140
+ This repository is managed by EasyCLA. Project participants must sign the free [GraphQL Specification Membership agreement](https://preview-spec-membership.graphql.org) before making a contribution. You only need to do this one time, and it can be signed by [individual contributors](http://individual-spec-membership.graphql.org/) or their [employers](http://corporate-spec-membership.graphql.org/).
143
141
 
144
142
  To initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.
145
143
 
package/diagnostics.d.mts CHANGED
@@ -1,13 +1,22 @@
1
1
  /**
2
2
  * TracingChannel integration.
3
3
  *
4
- * graphql-js publishes lifecycle events on a set of named tracing channels
5
- * that APM tools can subscribe to in order to observe parse, validate,
6
- * execute, subscribe, and resolver behavior, plus selected executor internals.
7
- * At module load time graphql-js resolves `node:diagnostics_channel` itself so
8
- * APMs do not need to interact with the graphql API to enable tracing. On
9
- * runtimes that do not expose `node:diagnostics_channel` (e.g., browsers) the
10
- * load silently no-ops and emission sites short-circuit.
4
+ * GraphQL.js publishes lifecycle events on a set of named tracing channels
5
+ * that application performance monitoring (APM) tools can subscribe to in
6
+ * order to observe parse, validate, execute, subscribe, and resolver behavior,
7
+ * plus selected executor internals. At module load time GraphQL.js resolves
8
+ * `node:diagnostics_channel` itself so APMs do not need to interact with the
9
+ * GraphQL API to enable tracing. On runtimes that do not expose
10
+ * `node:diagnostics_channel` (e.g., browsers) the load silently no-ops and
11
+ * emission sites short-circuit.
12
+ *
13
+ * Within the tracing context types, `error` means the traced JavaScript call
14
+ * threw or rejected; it does not mean every `GraphQLError` returned by
15
+ * GraphQL.js. Some channels complete normally and publish GraphQL errors on
16
+ * `result`. Resolver errors can appear both as `message.error` on
17
+ * `graphql:resolve` and as formatted errors in an enclosing execution or
18
+ * subscription result. `graphql:parse`, `graphql:validate`, and
19
+ * `graphql:execute:variableCoercion` are sync-only channels.
11
20
  * @category Diagnostics
12
21
  */
13
22
  import type { Maybe } from "./jsutils/Maybe.mjs";
@@ -21,7 +30,7 @@ import type { ExperimentalIncrementalExecutionResults } from "./execution/increm
21
30
  import type { VariableValues } from "./execution/values.mjs";
22
31
  /**
23
32
  * Structural subset of `DiagnosticsChannel` sufficient for publishing and
24
- * subscriber gating. `node:diagnostics_channel`'s `Channel` satisfies this.
33
+ * subscriber gating. The `node:diagnostics_channel` `Channel` satisfies this.
25
34
  *
26
35
  * @internal
27
36
  */
@@ -31,9 +40,10 @@ export interface MinimalChannel<TMessage = unknown> {
31
40
  runStores: <T, ContextType extends object>(context: ContextType, fn: (this: ContextType, ...args: Array<unknown>) => T, thisArg?: unknown, ...args: Array<unknown>) => T;
32
41
  }
33
42
  /**
34
- * Structural subset of Node's `TracingChannel`. The `node:diagnostics_channel`
35
- * `TracingChannel` satisfies this by duck typing, so graphql-js does not need
36
- * a dependency on `@types/node` or on the runtime itself.
43
+ * Structural subset of the Node.js `TracingChannel` API. The
44
+ * `node:diagnostics_channel` `TracingChannel` satisfies this by duck typing,
45
+ * so GraphQL.js does not need a dependency on `@types/node` or on the runtime
46
+ * itself.
37
47
  *
38
48
  * @internal
39
49
  */
@@ -46,9 +56,7 @@ export interface MinimalTracingChannel<TContext = unknown> {
46
56
  readonly error: MinimalChannel<TContext>;
47
57
  traceSync: <T>(fn: (...args: Array<unknown>) => T, context: TContext extends object ? TContext : object, thisArg?: unknown, ...args: Array<unknown>) => T;
48
58
  }
49
- /**
50
- * Context published on `graphql:parse`.
51
- */
59
+ /** Context published on the sync-only `graphql:parse` channel. */
52
60
  export interface GraphQLParseContext {
53
61
  /** Source text or source object passed to the parser. */
54
62
  source: string | Source;
@@ -57,9 +65,7 @@ export interface GraphQLParseContext {
57
65
  /** Parsed document, when parsing succeeds. */
58
66
  result?: DocumentNode;
59
67
  }
60
- /**
61
- * Context published on `graphql:validate`.
62
- */
68
+ /** Context published on the sync-only `graphql:validate` channel. */
63
69
  export interface GraphQLValidateContext {
64
70
  /** Schema used for validation. */
65
71
  schema: GraphQLSchema;
@@ -72,6 +78,8 @@ export interface GraphQLValidateContext {
72
78
  }
73
79
  /**
74
80
  * Context published on `graphql:execute`.
81
+ *
82
+ * Returned results may contain GraphQL errors collected during execution.
75
83
  */
76
84
  export interface GraphQLExecuteContext {
77
85
  /** Schema used for execution. */
@@ -86,13 +94,15 @@ export interface GraphQLExecuteContext {
86
94
  operationName: string | undefined;
87
95
  /** Selected operation type, if one is available. */
88
96
  operationType: OperationTypeNode | undefined;
89
- /** Error thrown while executing, when execution fails abruptly. */
97
+ /** Error thrown or rejected while executing, when execution fails abruptly. */
90
98
  error?: unknown;
91
- /** Execution result returned by execution. */
99
+ /** Execution result returned by execution, including GraphQL errors. */
92
100
  result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
93
101
  }
94
102
  /**
95
103
  * Context published on `graphql:execute:rootSelectionSet`.
104
+ *
105
+ * Returned results may contain GraphQL errors collected during execution.
96
106
  */
97
107
  export interface GraphQLExecuteRootSelectionSetContext {
98
108
  /** Schema used for execution. */
@@ -109,18 +119,23 @@ export interface GraphQLExecuteRootSelectionSetContext {
109
119
  operationName: string | undefined;
110
120
  /** Selected operation type. */
111
121
  operationType: OperationTypeNode;
112
- /** Error thrown while executing the root selection set. */
122
+ /** Error thrown or rejected while executing the root selection set. */
113
123
  error?: unknown;
114
- /** Execution result returned from the root selection set. */
124
+ /**
125
+ * Execution result returned from the root selection set, including GraphQL
126
+ * errors.
127
+ */
115
128
  result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
116
129
  }
117
130
  /**
118
131
  * Context published on `graphql:execute:variableCoercion`.
119
132
  *
120
- * Coercion runs synchronously inside argument validation, so only the
121
- * `start`/`end` (and, on a thrown error, `error`) lifecycle fires. When
122
- * coercion produces variable errors it does not throw; instead `result`
123
- * carries the `errors` array, mirroring `graphql:validate`.
133
+ * Coercion runs synchronously while execution arguments are validated, so only
134
+ * the `start`/`end` (and, on an abrupt throw, `error`) lifecycle fires.
135
+ * Ordinary variable coercion failures are returned on `result.errors`; when
136
+ * execution is invoked through APIs such as `execute()` or `subscribe()`, they
137
+ * surface as GraphQL result errors rather than as the tracing `error`
138
+ * lifecycle event.
124
139
  */
125
140
  export interface GraphQLExecuteVariableCoercionContext {
126
141
  /** Schema used for variable coercion. */
@@ -148,6 +163,11 @@ export interface GraphQLExecuteVariableCoercionContext {
148
163
  }
149
164
  /**
150
165
  * Context published on `graphql:subscribe`.
166
+ *
167
+ * Subscription source resolver errors and invalid source stream results are
168
+ * returned on `result` as ExecutionResult errors; they do not publish the
169
+ * `error` lifecycle event unless subscription setup fails abruptly before
170
+ * GraphQL can form a result.
151
171
  */
152
172
  export interface GraphQLSubscribeContext {
153
173
  /** Schema used for subscription execution. */
@@ -162,13 +182,20 @@ export interface GraphQLSubscribeContext {
162
182
  operationName: string | undefined;
163
183
  /** Selected operation type, if one is available. */
164
184
  operationType: OperationTypeNode | undefined;
165
- /** Error thrown while subscribing, when subscription setup fails abruptly. */
185
+ /** Error thrown or rejected while subscribing, when setup fails abruptly. */
166
186
  error?: unknown;
167
- /** Subscription response stream or execution result returned by subscribe. */
187
+ /**
188
+ * Subscription response stream, or an ExecutionResult containing GraphQL
189
+ * errors.
190
+ */
168
191
  result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;
169
192
  }
170
193
  /**
171
194
  * Context published on `graphql:resolve`.
195
+ *
196
+ * Resolver throws and rejections publish the `error` lifecycle event here.
197
+ * The same failure may also be formatted into the enclosing execution or
198
+ * subscription result.
172
199
  */
173
200
  export interface GraphQLResolveContext {
174
201
  /** Field name being resolved. */
@@ -185,14 +212,12 @@ export interface GraphQLResolveContext {
185
212
  isDefaultResolver: boolean;
186
213
  /** Response path for the field being resolved. */
187
214
  fieldPath: string;
188
- /** Error thrown by the resolver, when resolution fails. */
215
+ /** Error thrown or rejected by the resolver, when resolution fails. */
189
216
  error?: unknown;
190
- /** Value returned by the resolver. */
217
+ /** Value returned by the resolver, when resolution succeeds. */
191
218
  result?: unknown;
192
219
  }
193
- /**
194
- * Mapping from tracing channel name to the context type published on it.
195
- */
220
+ /** Mapping from tracing channel name to the context type published on it. */
196
221
  export interface GraphQLChannelContextByName {
197
222
  /** Context published on `graphql:parse`. */
198
223
  'graphql:parse': GraphQLParseContext;
@@ -210,10 +235,10 @@ export interface GraphQLChannelContextByName {
210
235
  'graphql:resolve': GraphQLResolveContext;
211
236
  }
212
237
  /**
213
- * The collection of tracing channels graphql-js emits on. APMs subscribe to
214
- * these by name on their own `node:diagnostics_channel` import; both paths
215
- * land on the same channel instance because `tracingChannel(name)` is cached
216
- * by name.
238
+ * The collection of tracing channels GraphQL.js emits on. Application
239
+ * performance monitoring (APM) tools subscribe to these by name on their own
240
+ * `node:diagnostics_channel` import; both paths land on the same channel
241
+ * instance because `tracingChannel(name)` is cached by name.
217
242
  */
218
243
  export interface GraphQLChannels {
219
244
  /** Tracing channel for `graphql:execute`. */
@@ -269,8 +294,12 @@ interface TraceLifecycleContext {
269
294
  }
270
295
  type TraceStartContext<TContext extends TraceLifecycleContext> = Omit<TContext, 'error' | 'result'>;
271
296
  /**
272
- * Publish a mixed sync-or-promise operation through `channel`. Caller has
273
- * already verified that a subscriber is attached.
297
+ * Publish a traced call that may complete synchronously or with a promise.
298
+ * Caller has already verified that a subscriber is attached. On normal
299
+ * completion, `result` is attached before the terminal `end` or `asyncEnd`
300
+ * event. When the traced call throws or rejects, `error` is attached, the
301
+ * `error` sub-channel fires, and the terminal `end` or `asyncEnd` event is
302
+ * published before the original failure is propagated.
274
303
  *
275
304
  * @internal
276
305
  */
package/diagnostics.d.ts CHANGED
@@ -1,13 +1,22 @@
1
1
  /**
2
2
  * TracingChannel integration.
3
3
  *
4
- * graphql-js publishes lifecycle events on a set of named tracing channels
5
- * that APM tools can subscribe to in order to observe parse, validate,
6
- * execute, subscribe, and resolver behavior, plus selected executor internals.
7
- * At module load time graphql-js resolves `node:diagnostics_channel` itself so
8
- * APMs do not need to interact with the graphql API to enable tracing. On
9
- * runtimes that do not expose `node:diagnostics_channel` (e.g., browsers) the
10
- * load silently no-ops and emission sites short-circuit.
4
+ * GraphQL.js publishes lifecycle events on a set of named tracing channels
5
+ * that application performance monitoring (APM) tools can subscribe to in
6
+ * order to observe parse, validate, execute, subscribe, and resolver behavior,
7
+ * plus selected executor internals. At module load time GraphQL.js resolves
8
+ * `node:diagnostics_channel` itself so APMs do not need to interact with the
9
+ * GraphQL API to enable tracing. On runtimes that do not expose
10
+ * `node:diagnostics_channel` (e.g., browsers) the load silently no-ops and
11
+ * emission sites short-circuit.
12
+ *
13
+ * Within the tracing context types, `error` means the traced JavaScript call
14
+ * threw or rejected; it does not mean every `GraphQLError` returned by
15
+ * GraphQL.js. Some channels complete normally and publish GraphQL errors on
16
+ * `result`. Resolver errors can appear both as `message.error` on
17
+ * `graphql:resolve` and as formatted errors in an enclosing execution or
18
+ * subscription result. `graphql:parse`, `graphql:validate`, and
19
+ * `graphql:execute:variableCoercion` are sync-only channels.
11
20
  * @category Diagnostics
12
21
  */
13
22
  import type { Maybe } from "./jsutils/Maybe.js";
@@ -21,7 +30,7 @@ import type { ExperimentalIncrementalExecutionResults } from "./execution/increm
21
30
  import type { VariableValues } from "./execution/values.js";
22
31
  /**
23
32
  * Structural subset of `DiagnosticsChannel` sufficient for publishing and
24
- * subscriber gating. `node:diagnostics_channel`'s `Channel` satisfies this.
33
+ * subscriber gating. The `node:diagnostics_channel` `Channel` satisfies this.
25
34
  *
26
35
  * @internal
27
36
  */
@@ -31,9 +40,10 @@ export interface MinimalChannel<TMessage = unknown> {
31
40
  runStores: <T, ContextType extends object>(context: ContextType, fn: (this: ContextType, ...args: Array<unknown>) => T, thisArg?: unknown, ...args: Array<unknown>) => T;
32
41
  }
33
42
  /**
34
- * Structural subset of Node's `TracingChannel`. The `node:diagnostics_channel`
35
- * `TracingChannel` satisfies this by duck typing, so graphql-js does not need
36
- * a dependency on `@types/node` or on the runtime itself.
43
+ * Structural subset of the Node.js `TracingChannel` API. The
44
+ * `node:diagnostics_channel` `TracingChannel` satisfies this by duck typing,
45
+ * so GraphQL.js does not need a dependency on `@types/node` or on the runtime
46
+ * itself.
37
47
  *
38
48
  * @internal
39
49
  */
@@ -46,9 +56,7 @@ export interface MinimalTracingChannel<TContext = unknown> {
46
56
  readonly error: MinimalChannel<TContext>;
47
57
  traceSync: <T>(fn: (...args: Array<unknown>) => T, context: TContext extends object ? TContext : object, thisArg?: unknown, ...args: Array<unknown>) => T;
48
58
  }
49
- /**
50
- * Context published on `graphql:parse`.
51
- */
59
+ /** Context published on the sync-only `graphql:parse` channel. */
52
60
  export interface GraphQLParseContext {
53
61
  /** Source text or source object passed to the parser. */
54
62
  source: string | Source;
@@ -57,9 +65,7 @@ export interface GraphQLParseContext {
57
65
  /** Parsed document, when parsing succeeds. */
58
66
  result?: DocumentNode;
59
67
  }
60
- /**
61
- * Context published on `graphql:validate`.
62
- */
68
+ /** Context published on the sync-only `graphql:validate` channel. */
63
69
  export interface GraphQLValidateContext {
64
70
  /** Schema used for validation. */
65
71
  schema: GraphQLSchema;
@@ -72,6 +78,8 @@ export interface GraphQLValidateContext {
72
78
  }
73
79
  /**
74
80
  * Context published on `graphql:execute`.
81
+ *
82
+ * Returned results may contain GraphQL errors collected during execution.
75
83
  */
76
84
  export interface GraphQLExecuteContext {
77
85
  /** Schema used for execution. */
@@ -86,13 +94,15 @@ export interface GraphQLExecuteContext {
86
94
  operationName: string | undefined;
87
95
  /** Selected operation type, if one is available. */
88
96
  operationType: OperationTypeNode | undefined;
89
- /** Error thrown while executing, when execution fails abruptly. */
97
+ /** Error thrown or rejected while executing, when execution fails abruptly. */
90
98
  error?: unknown;
91
- /** Execution result returned by execution. */
99
+ /** Execution result returned by execution, including GraphQL errors. */
92
100
  result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
93
101
  }
94
102
  /**
95
103
  * Context published on `graphql:execute:rootSelectionSet`.
104
+ *
105
+ * Returned results may contain GraphQL errors collected during execution.
96
106
  */
97
107
  export interface GraphQLExecuteRootSelectionSetContext {
98
108
  /** Schema used for execution. */
@@ -109,18 +119,23 @@ export interface GraphQLExecuteRootSelectionSetContext {
109
119
  operationName: string | undefined;
110
120
  /** Selected operation type. */
111
121
  operationType: OperationTypeNode;
112
- /** Error thrown while executing the root selection set. */
122
+ /** Error thrown or rejected while executing the root selection set. */
113
123
  error?: unknown;
114
- /** Execution result returned from the root selection set. */
124
+ /**
125
+ * Execution result returned from the root selection set, including GraphQL
126
+ * errors.
127
+ */
115
128
  result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
116
129
  }
117
130
  /**
118
131
  * Context published on `graphql:execute:variableCoercion`.
119
132
  *
120
- * Coercion runs synchronously inside argument validation, so only the
121
- * `start`/`end` (and, on a thrown error, `error`) lifecycle fires. When
122
- * coercion produces variable errors it does not throw; instead `result`
123
- * carries the `errors` array, mirroring `graphql:validate`.
133
+ * Coercion runs synchronously while execution arguments are validated, so only
134
+ * the `start`/`end` (and, on an abrupt throw, `error`) lifecycle fires.
135
+ * Ordinary variable coercion failures are returned on `result.errors`; when
136
+ * execution is invoked through APIs such as `execute()` or `subscribe()`, they
137
+ * surface as GraphQL result errors rather than as the tracing `error`
138
+ * lifecycle event.
124
139
  */
125
140
  export interface GraphQLExecuteVariableCoercionContext {
126
141
  /** Schema used for variable coercion. */
@@ -148,6 +163,11 @@ export interface GraphQLExecuteVariableCoercionContext {
148
163
  }
149
164
  /**
150
165
  * Context published on `graphql:subscribe`.
166
+ *
167
+ * Subscription source resolver errors and invalid source stream results are
168
+ * returned on `result` as ExecutionResult errors; they do not publish the
169
+ * `error` lifecycle event unless subscription setup fails abruptly before
170
+ * GraphQL can form a result.
151
171
  */
152
172
  export interface GraphQLSubscribeContext {
153
173
  /** Schema used for subscription execution. */
@@ -162,13 +182,20 @@ export interface GraphQLSubscribeContext {
162
182
  operationName: string | undefined;
163
183
  /** Selected operation type, if one is available. */
164
184
  operationType: OperationTypeNode | undefined;
165
- /** Error thrown while subscribing, when subscription setup fails abruptly. */
185
+ /** Error thrown or rejected while subscribing, when setup fails abruptly. */
166
186
  error?: unknown;
167
- /** Subscription response stream or execution result returned by subscribe. */
187
+ /**
188
+ * Subscription response stream, or an ExecutionResult containing GraphQL
189
+ * errors.
190
+ */
168
191
  result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;
169
192
  }
170
193
  /**
171
194
  * Context published on `graphql:resolve`.
195
+ *
196
+ * Resolver throws and rejections publish the `error` lifecycle event here.
197
+ * The same failure may also be formatted into the enclosing execution or
198
+ * subscription result.
172
199
  */
173
200
  export interface GraphQLResolveContext {
174
201
  /** Field name being resolved. */
@@ -185,14 +212,12 @@ export interface GraphQLResolveContext {
185
212
  isDefaultResolver: boolean;
186
213
  /** Response path for the field being resolved. */
187
214
  fieldPath: string;
188
- /** Error thrown by the resolver, when resolution fails. */
215
+ /** Error thrown or rejected by the resolver, when resolution fails. */
189
216
  error?: unknown;
190
- /** Value returned by the resolver. */
217
+ /** Value returned by the resolver, when resolution succeeds. */
191
218
  result?: unknown;
192
219
  }
193
- /**
194
- * Mapping from tracing channel name to the context type published on it.
195
- */
220
+ /** Mapping from tracing channel name to the context type published on it. */
196
221
  export interface GraphQLChannelContextByName {
197
222
  /** Context published on `graphql:parse`. */
198
223
  'graphql:parse': GraphQLParseContext;
@@ -210,10 +235,10 @@ export interface GraphQLChannelContextByName {
210
235
  'graphql:resolve': GraphQLResolveContext;
211
236
  }
212
237
  /**
213
- * The collection of tracing channels graphql-js emits on. APMs subscribe to
214
- * these by name on their own `node:diagnostics_channel` import; both paths
215
- * land on the same channel instance because `tracingChannel(name)` is cached
216
- * by name.
238
+ * The collection of tracing channels GraphQL.js emits on. Application
239
+ * performance monitoring (APM) tools subscribe to these by name on their own
240
+ * `node:diagnostics_channel` import; both paths land on the same channel
241
+ * instance because `tracingChannel(name)` is cached by name.
217
242
  */
218
243
  export interface GraphQLChannels {
219
244
  /** Tracing channel for `graphql:execute`. */
@@ -269,8 +294,12 @@ interface TraceLifecycleContext {
269
294
  }
270
295
  type TraceStartContext<TContext extends TraceLifecycleContext> = Omit<TContext, 'error' | 'result'>;
271
296
  /**
272
- * Publish a mixed sync-or-promise operation through `channel`. Caller has
273
- * already verified that a subscriber is attached.
297
+ * Publish a traced call that may complete synchronously or with a promise.
298
+ * Caller has already verified that a subscriber is attached. On normal
299
+ * completion, `result` is attached before the terminal `end` or `asyncEnd`
300
+ * event. When the traced call throws or rejects, `error` is attached, the
301
+ * `error` sub-channel fires, and the terminal `end` or `asyncEnd` event is
302
+ * published before the original failure is propagated.
274
303
  *
275
304
  * @internal
276
305
  */
package/diagnostics.js CHANGED
@@ -59,14 +59,15 @@ function traceMixed(channel, contextInput, fn) {
59
59
  return result;
60
60
  }
61
61
  channel.end.publish(context);
62
- channel.asyncStart.publish(context);
63
62
  return result.then((value) => {
64
63
  context.result = value;
64
+ channel.asyncStart.publish(context);
65
65
  channel.asyncEnd.publish(context);
66
66
  return value;
67
67
  }, (err) => {
68
68
  context.error = err;
69
69
  channel.error.publish(context);
70
+ channel.asyncStart.publish(context);
70
71
  channel.asyncEnd.publish(context);
71
72
  throw err;
72
73
  });
@@ -1 +1 @@
1
- {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * TracingChannel integration.\n *\n * graphql-js publishes lifecycle events on a set of named tracing channels\n * that APM tools can subscribe to in order to observe parse, validate,\n * execute, subscribe, and resolver behavior, plus selected executor internals.\n * At module load time graphql-js resolves `node:diagnostics_channel` itself so\n * APMs do not need to interact with the graphql API to enable tracing. On\n * runtimes that do not expose `node:diagnostics_channel` (e.g., browsers) the\n * load silently no-ops and emission sites short-circuit.\n * @category Diagnostics\n */\n\nimport { isPromiseLike } from './jsutils/isPromise.ts';\nimport type { Maybe } from './jsutils/Maybe.ts';\nimport type { ObjMap } from './jsutils/ObjMap.ts';\n\nimport type { GraphQLError } from './error/GraphQLError.ts';\n\nimport type {\n DocumentNode,\n OperationDefinitionNode,\n OperationTypeNode,\n} from './language/ast.ts';\nimport type { Source } from './language/source.ts';\n\nimport type { GraphQLSchema } from './type/schema.ts';\n\nimport type { ExecutionResult } from './execution/Executor.ts';\nimport type { ExperimentalIncrementalExecutionResults } from './execution/incremental/IncrementalExecutor.ts';\nimport type { VariableValues } from './execution/values.ts';\n\n/**\n * Structural subset of `DiagnosticsChannel` sufficient for publishing and\n * subscriber gating. `node:diagnostics_channel`'s `Channel` satisfies this.\n *\n * @internal\n */\nexport interface MinimalChannel<TMessage = unknown> {\n readonly hasSubscribers?: boolean;\n publish: (message: TMessage) => void;\n runStores: <T, ContextType extends object>(\n context: ContextType,\n fn: (this: ContextType, ...args: Array<unknown>) => T,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\n/**\n * Structural subset of Node's `TracingChannel`. The `node:diagnostics_channel`\n * `TracingChannel` satisfies this by duck typing, so graphql-js does not need\n * a dependency on `@types/node` or on the runtime itself.\n *\n * @internal\n */\nexport interface MinimalTracingChannel<TContext = unknown> {\n // `undefined` accommodates runtimes (e.g. Bun) that ship `tracingChannel`\n // without exposing the aggregate `hasSubscribers` getter.\n readonly hasSubscribers: boolean | undefined;\n readonly start: MinimalChannel<TContext>;\n readonly end: MinimalChannel<TContext>;\n readonly asyncStart: MinimalChannel<TContext>;\n readonly asyncEnd: MinimalChannel<TContext>;\n readonly error: MinimalChannel<TContext>;\n\n traceSync: <T>(\n fn: (...args: Array<unknown>) => T,\n context: TContext extends object ? TContext : object,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\ninterface DiagnosticsChannelModule {\n tracingChannel: <TContext = unknown>(\n name: string,\n ) => MinimalTracingChannel<TContext>;\n}\n\n/**\n * Context published on `graphql:parse`.\n */\nexport interface GraphQLParseContext {\n /** Source text or source object passed to the parser. */\n source: string | Source;\n /** Error thrown while parsing, when parsing fails. */\n error?: unknown;\n /** Parsed document, when parsing succeeds. */\n result?: DocumentNode;\n}\n\n/**\n * Context published on `graphql:validate`.\n */\nexport interface GraphQLValidateContext {\n /** Schema used for validation. */\n schema: GraphQLSchema;\n /** Parsed document being validated. */\n document: DocumentNode;\n /** Error thrown while validating, when validation fails abruptly. */\n error?: unknown;\n /** Validation errors returned by validation. */\n result?: ReadonlyArray<GraphQLError>;\n}\n\n/**\n * Context published on `graphql:execute`.\n */\nexport interface GraphQLExecuteContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown while executing, when execution fails abruptly. */\n error?: unknown;\n /** Execution result returned by execution. */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:rootSelectionSet`.\n */\nexport interface GraphQLExecuteRootSelectionSetContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown while executing the root selection set. */\n error?: unknown;\n /** Execution result returned from the root selection set. */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:variableCoercion`.\n *\n * Coercion runs synchronously inside argument validation, so only the\n * `start`/`end` (and, on a thrown error, `error`) lifecycle fires. When\n * coercion produces variable errors it does not throw; instead `result`\n * carries the `errors` array, mirroring `graphql:validate`.\n */\nexport interface GraphQLExecuteVariableCoercionContext {\n /** Schema used for variable coercion. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition whose variables are being coerced. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown while coercing variables, when coercion fails abruptly. */\n error?: unknown;\n /** Coerced variable values or coercion errors returned by coercion. */\n result?:\n | { variableValues: VariableValues }\n | { errors: ReadonlyArray<GraphQLError> };\n}\n\n/**\n * Context published on `graphql:subscribe`.\n */\nexport interface GraphQLSubscribeContext {\n /** Schema used for subscription execution. */\n schema: GraphQLSchema;\n /** Parsed subscription document. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown while subscribing, when subscription setup fails abruptly. */\n error?: unknown;\n /** Subscription response stream or execution result returned by subscribe. */\n result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;\n}\n\n/**\n * Context published on `graphql:resolve`.\n */\nexport interface GraphQLResolveContext {\n /** Field name being resolved. */\n fieldName: string;\n /** Response alias for the field being resolved. */\n alias: string;\n /** Parent type name for the field being resolved. */\n parentType: string;\n /** Return type string for the field being resolved. */\n fieldType: string;\n /** Argument values passed to the resolver. */\n args: ObjMap<unknown>;\n /** Whether the field is using the default resolver. */\n isDefaultResolver: boolean;\n /** Response path for the field being resolved. */\n fieldPath: string;\n /** Error thrown by the resolver, when resolution fails. */\n error?: unknown;\n /** Value returned by the resolver. */\n result?: unknown;\n}\n\n/**\n * Mapping from tracing channel name to the context type published on it.\n */\nexport interface GraphQLChannelContextByName {\n /** Context published on `graphql:parse`. */\n 'graphql:parse': GraphQLParseContext;\n /** Context published on `graphql:validate`. */\n 'graphql:validate': GraphQLValidateContext;\n /** Context published on `graphql:execute`. */\n 'graphql:execute': GraphQLExecuteContext;\n /** Context published on `graphql:execute:variableCoercion`. */\n 'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;\n /** Context published on `graphql:execute:rootSelectionSet`. */\n 'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;\n /** Context published on `graphql:subscribe`. */\n 'graphql:subscribe': GraphQLSubscribeContext;\n /** Context published on `graphql:resolve`. */\n 'graphql:resolve': GraphQLResolveContext;\n}\n\n/**\n * The collection of tracing channels graphql-js emits on. APMs subscribe to\n * these by name on their own `node:diagnostics_channel` import; both paths\n * land on the same channel instance because `tracingChannel(name)` is cached\n * by name.\n */\nexport interface GraphQLChannels {\n /** Tracing channel for `graphql:execute`. */\n execute: MinimalTracingChannel<GraphQLExecuteContext>;\n /** Tracing channel for `graphql:execute:variableCoercion`. */\n executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;\n /** Tracing channel for `graphql:execute:rootSelectionSet`. */\n executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;\n /** Tracing channel for `graphql:parse`. */\n parse: MinimalTracingChannel<GraphQLParseContext>;\n /** Tracing channel for `graphql:validate`. */\n validate: MinimalTracingChannel<GraphQLValidateContext>;\n /** Tracing channel for `graphql:resolve`. */\n resolve: MinimalTracingChannel<GraphQLResolveContext>;\n /** Tracing channel for `graphql:subscribe`. */\n subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;\n}\n\nfunction resolveDiagnosticsChannel(): DiagnosticsChannelModule | undefined {\n let dc: DiagnosticsChannelModule | undefined;\n try {\n const processRef = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown };\n }\n ).process;\n if (\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n typeof processRef?.getBuiltinModule === 'function'\n ) {\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n dc = processRef.getBuiltinModule(\n 'node:diagnostics_channel',\n ) as DiagnosticsChannelModule;\n }\n /* node:coverage ignore next 3 */\n } catch {\n // diagnostics_channel not available on this runtime; tracing is a no-op.\n }\n return dc;\n}\n\nconst dc = resolveDiagnosticsChannel();\n\n/**\n * Per-channel handles, resolved once at module load. `undefined` when\n * `node:diagnostics_channel` isn't available. Emission sites read these\n * directly to keep the no-subscriber fast path to a single property access\n * plus a `hasSubscribers` check (no function calls, no closures).\n *\n * @internal\n */\nexport const parseChannel:\n | MinimalTracingChannel<GraphQLParseContext>\n | undefined = dc?.tracingChannel('graphql:parse');\n/** @internal */\nexport const validateChannel:\n | MinimalTracingChannel<GraphQLValidateContext>\n | undefined = dc?.tracingChannel('graphql:validate');\n/** @internal */\nexport const executeChannel:\n | MinimalTracingChannel<GraphQLExecuteContext>\n | undefined = dc?.tracingChannel('graphql:execute');\n/** @internal */\nexport const executeVariableCoercionChannel:\n | MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>\n | undefined = dc?.tracingChannel('graphql:execute:variableCoercion');\n/** @internal */\nexport const executeRootSelectionSetChannel:\n | MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>\n | undefined = dc?.tracingChannel('graphql:execute:rootSelectionSet');\n/** @internal */\nexport const subscribeChannel:\n | MinimalTracingChannel<GraphQLSubscribeContext>\n | undefined = dc?.tracingChannel('graphql:subscribe');\n/** @internal */\nexport const resolveChannel:\n | MinimalTracingChannel<GraphQLResolveContext>\n | undefined = dc?.tracingChannel('graphql:resolve');\n\nconst SUB_CHANNEL_KEYS: ReadonlyArray<\n 'start' | 'end' | 'asyncStart' | 'asyncEnd' | 'error'\n> = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];\n\n/**\n * Whether emission sites should publish to `channel`. Trusts the\n * `TracingChannel.hasSubscribers` aggregate when the runtime exposes it; if\n * the getter is missing (e.g. Bun's `node:diagnostics_channel`, where\n * `tracingChannel.hasSubscribers` is `undefined`), falls back to checking\n * each of the five underlying lifecycle channels so a subscriber attached\n * via `tracingChannel.subscribe(handlers)` is still observed.\n *\n * @internal\n */\nexport function shouldTrace<TContext = unknown>(\n channel: MinimalTracingChannel<TContext> | undefined,\n): channel is MinimalTracingChannel<TContext> {\n if (channel == null) {\n return false;\n }\n const aggregate = channel.hasSubscribers;\n if (aggregate !== undefined) {\n return aggregate;\n }\n // Bun-only fallback, exercised by integrationTests/diagnostics-bun.\n for (const key of SUB_CHANNEL_KEYS) {\n if (channel[key].hasSubscribers) {\n return true;\n }\n }\n return false;\n}\n\ninterface TraceLifecycleContext {\n error?: unknown;\n result?: unknown;\n}\n\ntype TraceStartContext<TContext extends TraceLifecycleContext> = Omit<\n TContext,\n 'error' | 'result'\n>;\n\n/**\n * Publish a mixed sync-or-promise operation through `channel`. Caller has\n * already verified that a subscriber is attached.\n *\n * @internal\n */\nexport function traceMixed<TResult, TContext extends TraceLifecycleContext>(\n channel: MinimalTracingChannel<TContext>,\n contextInput: TraceStartContext<TContext>,\n fn: () => TResult,\n): TResult {\n const context = contextInput as TContext;\n\n return channel.start.runStores(context, () => {\n let result: TResult;\n try {\n result = fn();\n } catch (err) {\n context.error = err;\n channel.error.publish(context);\n channel.end.publish(context);\n throw err;\n }\n\n if (!isPromiseLike(result)) {\n context.result = result;\n channel.end.publish(context);\n return result;\n }\n\n channel.end.publish(context);\n channel.asyncStart.publish(context);\n\n return result.then(\n (value) => {\n context.result = value;\n channel.asyncEnd.publish(context);\n return value;\n },\n (err: unknown) => {\n context.error = err;\n channel.error.publish(context);\n channel.asyncEnd.publish(context);\n throw err;\n },\n ) as TResult;\n });\n}\n"]}
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * TracingChannel integration.\n *\n * GraphQL.js publishes lifecycle events on a set of named tracing channels\n * that application performance monitoring (APM) tools can subscribe to in\n * order to observe parse, validate, execute, subscribe, and resolver behavior,\n * plus selected executor internals. At module load time GraphQL.js resolves\n * `node:diagnostics_channel` itself so APMs do not need to interact with the\n * GraphQL API to enable tracing. On runtimes that do not expose\n * `node:diagnostics_channel` (e.g., browsers) the load silently no-ops and\n * emission sites short-circuit.\n *\n * Within the tracing context types, `error` means the traced JavaScript call\n * threw or rejected; it does not mean every `GraphQLError` returned by\n * GraphQL.js. Some channels complete normally and publish GraphQL errors on\n * `result`. Resolver errors can appear both as `message.error` on\n * `graphql:resolve` and as formatted errors in an enclosing execution or\n * subscription result. `graphql:parse`, `graphql:validate`, and\n * `graphql:execute:variableCoercion` are sync-only channels.\n * @category Diagnostics\n */\n\nimport { isPromiseLike } from './jsutils/isPromise.ts';\nimport type { Maybe } from './jsutils/Maybe.ts';\nimport type { ObjMap } from './jsutils/ObjMap.ts';\n\nimport type { GraphQLError } from './error/GraphQLError.ts';\n\nimport type {\n DocumentNode,\n OperationDefinitionNode,\n OperationTypeNode,\n} from './language/ast.ts';\nimport type { Source } from './language/source.ts';\n\nimport type { GraphQLSchema } from './type/schema.ts';\n\nimport type { ExecutionResult } from './execution/Executor.ts';\nimport type { ExperimentalIncrementalExecutionResults } from './execution/incremental/IncrementalExecutor.ts';\nimport type { VariableValues } from './execution/values.ts';\n\n/**\n * Structural subset of `DiagnosticsChannel` sufficient for publishing and\n * subscriber gating. The `node:diagnostics_channel` `Channel` satisfies this.\n *\n * @internal\n */\nexport interface MinimalChannel<TMessage = unknown> {\n readonly hasSubscribers?: boolean;\n publish: (message: TMessage) => void;\n runStores: <T, ContextType extends object>(\n context: ContextType,\n fn: (this: ContextType, ...args: Array<unknown>) => T,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\n/**\n * Structural subset of the Node.js `TracingChannel` API. The\n * `node:diagnostics_channel` `TracingChannel` satisfies this by duck typing,\n * so GraphQL.js does not need a dependency on `@types/node` or on the runtime\n * itself.\n *\n * @internal\n */\nexport interface MinimalTracingChannel<TContext = unknown> {\n // `undefined` accommodates runtimes (e.g. Bun) that ship `tracingChannel`\n // without exposing the aggregate `hasSubscribers` getter.\n readonly hasSubscribers: boolean | undefined;\n readonly start: MinimalChannel<TContext>;\n readonly end: MinimalChannel<TContext>;\n readonly asyncStart: MinimalChannel<TContext>;\n readonly asyncEnd: MinimalChannel<TContext>;\n readonly error: MinimalChannel<TContext>;\n\n traceSync: <T>(\n fn: (...args: Array<unknown>) => T,\n context: TContext extends object ? TContext : object,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\ninterface DiagnosticsChannelModule {\n tracingChannel: <TContext = unknown>(\n name: string,\n ) => MinimalTracingChannel<TContext>;\n}\n\n/** Context published on the sync-only `graphql:parse` channel. */\nexport interface GraphQLParseContext {\n /** Source text or source object passed to the parser. */\n source: string | Source;\n /** Error thrown while parsing, when parsing fails. */\n error?: unknown;\n /** Parsed document, when parsing succeeds. */\n result?: DocumentNode;\n}\n\n/** Context published on the sync-only `graphql:validate` channel. */\nexport interface GraphQLValidateContext {\n /** Schema used for validation. */\n schema: GraphQLSchema;\n /** Parsed document being validated. */\n document: DocumentNode;\n /** Error thrown while validating, when validation fails abruptly. */\n error?: unknown;\n /** Validation errors returned by validation. */\n result?: ReadonlyArray<GraphQLError>;\n}\n\n/**\n * Context published on `graphql:execute`.\n *\n * Returned results may contain GraphQL errors collected during execution.\n */\nexport interface GraphQLExecuteContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown or rejected while executing, when execution fails abruptly. */\n error?: unknown;\n /** Execution result returned by execution, including GraphQL errors. */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:rootSelectionSet`.\n *\n * Returned results may contain GraphQL errors collected during execution.\n */\nexport interface GraphQLExecuteRootSelectionSetContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown or rejected while executing the root selection set. */\n error?: unknown;\n /**\n * Execution result returned from the root selection set, including GraphQL\n * errors.\n */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:variableCoercion`.\n *\n * Coercion runs synchronously while execution arguments are validated, so only\n * the `start`/`end` (and, on an abrupt throw, `error`) lifecycle fires.\n * Ordinary variable coercion failures are returned on `result.errors`; when\n * execution is invoked through APIs such as `execute()` or `subscribe()`, they\n * surface as GraphQL result errors rather than as the tracing `error`\n * lifecycle event.\n */\nexport interface GraphQLExecuteVariableCoercionContext {\n /** Schema used for variable coercion. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition whose variables are being coerced. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown while coercing variables, when coercion fails abruptly. */\n error?: unknown;\n /** Coerced variable values or coercion errors returned by coercion. */\n result?:\n | { variableValues: VariableValues }\n | { errors: ReadonlyArray<GraphQLError> };\n}\n\n/**\n * Context published on `graphql:subscribe`.\n *\n * Subscription source resolver errors and invalid source stream results are\n * returned on `result` as ExecutionResult errors; they do not publish the\n * `error` lifecycle event unless subscription setup fails abruptly before\n * GraphQL can form a result.\n */\nexport interface GraphQLSubscribeContext {\n /** Schema used for subscription execution. */\n schema: GraphQLSchema;\n /** Parsed subscription document. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown or rejected while subscribing, when setup fails abruptly. */\n error?: unknown;\n /**\n * Subscription response stream, or an ExecutionResult containing GraphQL\n * errors.\n */\n result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;\n}\n\n/**\n * Context published on `graphql:resolve`.\n *\n * Resolver throws and rejections publish the `error` lifecycle event here.\n * The same failure may also be formatted into the enclosing execution or\n * subscription result.\n */\nexport interface GraphQLResolveContext {\n /** Field name being resolved. */\n fieldName: string;\n /** Response alias for the field being resolved. */\n alias: string;\n /** Parent type name for the field being resolved. */\n parentType: string;\n /** Return type string for the field being resolved. */\n fieldType: string;\n /** Argument values passed to the resolver. */\n args: ObjMap<unknown>;\n /** Whether the field is using the default resolver. */\n isDefaultResolver: boolean;\n /** Response path for the field being resolved. */\n fieldPath: string;\n /** Error thrown or rejected by the resolver, when resolution fails. */\n error?: unknown;\n /** Value returned by the resolver, when resolution succeeds. */\n result?: unknown;\n}\n\n/** Mapping from tracing channel name to the context type published on it. */\nexport interface GraphQLChannelContextByName {\n /** Context published on `graphql:parse`. */\n 'graphql:parse': GraphQLParseContext;\n /** Context published on `graphql:validate`. */\n 'graphql:validate': GraphQLValidateContext;\n /** Context published on `graphql:execute`. */\n 'graphql:execute': GraphQLExecuteContext;\n /** Context published on `graphql:execute:variableCoercion`. */\n 'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;\n /** Context published on `graphql:execute:rootSelectionSet`. */\n 'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;\n /** Context published on `graphql:subscribe`. */\n 'graphql:subscribe': GraphQLSubscribeContext;\n /** Context published on `graphql:resolve`. */\n 'graphql:resolve': GraphQLResolveContext;\n}\n\n/**\n * The collection of tracing channels GraphQL.js emits on. Application\n * performance monitoring (APM) tools subscribe to these by name on their own\n * `node:diagnostics_channel` import; both paths land on the same channel\n * instance because `tracingChannel(name)` is cached by name.\n */\nexport interface GraphQLChannels {\n /** Tracing channel for `graphql:execute`. */\n execute: MinimalTracingChannel<GraphQLExecuteContext>;\n /** Tracing channel for `graphql:execute:variableCoercion`. */\n executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;\n /** Tracing channel for `graphql:execute:rootSelectionSet`. */\n executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;\n /** Tracing channel for `graphql:parse`. */\n parse: MinimalTracingChannel<GraphQLParseContext>;\n /** Tracing channel for `graphql:validate`. */\n validate: MinimalTracingChannel<GraphQLValidateContext>;\n /** Tracing channel for `graphql:resolve`. */\n resolve: MinimalTracingChannel<GraphQLResolveContext>;\n /** Tracing channel for `graphql:subscribe`. */\n subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;\n}\n\nfunction resolveDiagnosticsChannel(): DiagnosticsChannelModule | undefined {\n let dc: DiagnosticsChannelModule | undefined;\n try {\n const processRef = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown };\n }\n ).process;\n if (\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n typeof processRef?.getBuiltinModule === 'function'\n ) {\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n dc = processRef.getBuiltinModule(\n 'node:diagnostics_channel',\n ) as DiagnosticsChannelModule;\n }\n /* node:coverage ignore next 3 */\n } catch {\n // diagnostics_channel not available on this runtime; tracing is a no-op.\n }\n return dc;\n}\n\nconst dc = resolveDiagnosticsChannel();\n\n/**\n * Per-channel handles, resolved once at module load. `undefined` when\n * `node:diagnostics_channel` isn't available. Emission sites read these\n * directly to keep the no-subscriber fast path to a single property access\n * plus a `hasSubscribers` check (no function calls, no closures).\n *\n * @internal\n */\nexport const parseChannel:\n | MinimalTracingChannel<GraphQLParseContext>\n | undefined = dc?.tracingChannel('graphql:parse');\n/** @internal */\nexport const validateChannel:\n | MinimalTracingChannel<GraphQLValidateContext>\n | undefined = dc?.tracingChannel('graphql:validate');\n/** @internal */\nexport const executeChannel:\n | MinimalTracingChannel<GraphQLExecuteContext>\n | undefined = dc?.tracingChannel('graphql:execute');\n/** @internal */\nexport const executeVariableCoercionChannel:\n | MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>\n | undefined = dc?.tracingChannel('graphql:execute:variableCoercion');\n/** @internal */\nexport const executeRootSelectionSetChannel:\n | MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>\n | undefined = dc?.tracingChannel('graphql:execute:rootSelectionSet');\n/** @internal */\nexport const subscribeChannel:\n | MinimalTracingChannel<GraphQLSubscribeContext>\n | undefined = dc?.tracingChannel('graphql:subscribe');\n/** @internal */\nexport const resolveChannel:\n | MinimalTracingChannel<GraphQLResolveContext>\n | undefined = dc?.tracingChannel('graphql:resolve');\n\nconst SUB_CHANNEL_KEYS: ReadonlyArray<\n 'start' | 'end' | 'asyncStart' | 'asyncEnd' | 'error'\n> = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];\n\n/**\n * Whether emission sites should publish to `channel`. Trusts the\n * `TracingChannel.hasSubscribers` aggregate when the runtime exposes it; if\n * the getter is missing (e.g. Bun's `node:diagnostics_channel`, where\n * `tracingChannel.hasSubscribers` is `undefined`), falls back to checking\n * each of the five underlying lifecycle channels so a subscriber attached\n * via `tracingChannel.subscribe(handlers)` is still observed.\n *\n * @internal\n */\nexport function shouldTrace<TContext = unknown>(\n channel: MinimalTracingChannel<TContext> | undefined,\n): channel is MinimalTracingChannel<TContext> {\n if (channel == null) {\n return false;\n }\n const aggregate = channel.hasSubscribers;\n if (aggregate !== undefined) {\n return aggregate;\n }\n // Bun-only fallback, exercised by integrationTests/diagnostics-bun.\n for (const key of SUB_CHANNEL_KEYS) {\n if (channel[key].hasSubscribers) {\n return true;\n }\n }\n return false;\n}\n\ninterface TraceLifecycleContext {\n error?: unknown;\n result?: unknown;\n}\n\ntype TraceStartContext<TContext extends TraceLifecycleContext> = Omit<\n TContext,\n 'error' | 'result'\n>;\n\n/**\n * Publish a traced call that may complete synchronously or with a promise.\n * Caller has already verified that a subscriber is attached. On normal\n * completion, `result` is attached before the terminal `end` or `asyncEnd`\n * event. When the traced call throws or rejects, `error` is attached, the\n * `error` sub-channel fires, and the terminal `end` or `asyncEnd` event is\n * published before the original failure is propagated.\n *\n * @internal\n */\nexport function traceMixed<TResult, TContext extends TraceLifecycleContext>(\n channel: MinimalTracingChannel<TContext>,\n contextInput: TraceStartContext<TContext>,\n fn: () => TResult,\n): TResult {\n const context = contextInput as TContext;\n\n return channel.start.runStores(context, () => {\n let result: TResult;\n try {\n result = fn();\n } catch (err) {\n context.error = err;\n channel.error.publish(context);\n channel.end.publish(context);\n throw err;\n }\n\n if (!isPromiseLike(result)) {\n context.result = result;\n channel.end.publish(context);\n return result;\n }\n\n channel.end.publish(context);\n\n return result.then(\n (value) => {\n context.result = value;\n channel.asyncStart.publish(context);\n channel.asyncEnd.publish(context);\n return value;\n },\n (err: unknown) => {\n context.error = err;\n channel.error.publish(context);\n channel.asyncStart.publish(context);\n channel.asyncEnd.publish(context);\n throw err;\n },\n ) as TResult;\n });\n}\n"]}
package/diagnostics.mjs CHANGED
@@ -54,14 +54,15 @@ export function traceMixed(channel, contextInput, fn) {
54
54
  return result;
55
55
  }
56
56
  channel.end.publish(context);
57
- channel.asyncStart.publish(context);
58
57
  return result.then((value) => {
59
58
  context.result = value;
59
+ channel.asyncStart.publish(context);
60
60
  channel.asyncEnd.publish(context);
61
61
  return value;
62
62
  }, (err) => {
63
63
  context.error = err;
64
64
  channel.error.publish(context);
65
+ channel.asyncStart.publish(context);
65
66
  channel.asyncEnd.publish(context);
66
67
  throw err;
67
68
  });