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.
- package/README.md +3 -5
- package/diagnostics.d.mts +67 -38
- package/diagnostics.d.ts +67 -38
- package/diagnostics.js +2 -1
- package/diagnostics.js.map +1 -1
- package/diagnostics.mjs +2 -1
- package/diagnostics.mjs.map +1 -1
- package/error/locatedError.d.mts +1 -3
- package/error/locatedError.d.ts +1 -3
- package/error/locatedError.js.map +1 -1
- package/error/locatedError.mjs.map +1 -1
- package/execution/Executor.d.mts +2 -2
- package/execution/Executor.d.ts +2 -2
- package/execution/Executor.js.map +1 -1
- package/execution/Executor.mjs.map +1 -1
- package/execution/execute.d.mts +65 -44
- package/execution/execute.d.ts +65 -44
- package/execution/execute.js +11 -2
- package/execution/execute.js.map +1 -1
- package/execution/execute.mjs +11 -2
- package/execution/execute.mjs.map +1 -1
- package/execution/values.d.mts +17 -17
- package/execution/values.d.ts +17 -17
- package/execution/values.js.map +1 -1
- package/execution/values.mjs.map +1 -1
- package/language/parser.d.mts +20 -30
- package/language/parser.d.ts +20 -30
- package/language/parser.js +3 -9
- package/language/parser.js.map +1 -1
- package/language/parser.mjs +3 -9
- package/language/parser.mjs.map +1 -1
- package/language/predicates.d.mts +5 -1
- package/language/predicates.d.ts +5 -1
- package/language/predicates.js.map +1 -1
- package/language/predicates.mjs.map +1 -1
- package/language/source.d.mts +4 -5
- package/language/source.d.ts +4 -5
- package/language/source.js.map +1 -1
- package/language/source.mjs.map +1 -1
- package/language/visitor.d.mts +10 -2
- package/language/visitor.d.ts +10 -2
- package/language/visitor.js.map +1 -1
- package/language/visitor.mjs.map +1 -1
- package/package.json +1 -4
- package/type/definition.d.mts +96 -64
- package/type/definition.d.ts +96 -64
- package/type/definition.js.map +1 -1
- package/type/definition.mjs.map +1 -1
- package/type/directives.d.mts +3 -3
- package/type/directives.d.ts +3 -3
- package/type/directives.js.map +1 -1
- package/type/directives.mjs.map +1 -1
- package/type/schema.d.mts +4 -8
- package/type/schema.d.ts +4 -8
- package/type/schema.js.map +1 -1
- package/type/schema.mjs.map +1 -1
- package/type/validate.js +101 -30
- package/type/validate.js.map +1 -1
- package/type/validate.mjs +101 -30
- package/type/validate.mjs.map +1 -1
- package/utilities/TypeInfo.d.mts +1 -1
- package/utilities/TypeInfo.d.ts +1 -1
- package/utilities/TypeInfo.js.map +1 -1
- package/utilities/TypeInfo.mjs.map +1 -1
- package/utilities/buildASTSchema.d.mts +0 -1
- package/utilities/buildASTSchema.d.ts +0 -1
- package/utilities/buildASTSchema.js +0 -1
- package/utilities/buildASTSchema.js.map +1 -1
- package/utilities/buildASTSchema.mjs +0 -1
- package/utilities/buildASTSchema.mjs.map +1 -1
- package/utilities/buildClientSchema.d.mts +5 -1
- package/utilities/buildClientSchema.d.ts +5 -1
- package/utilities/buildClientSchema.js.map +1 -1
- package/utilities/buildClientSchema.mjs.map +1 -1
- package/utilities/coerceInputValue.d.mts +7 -6
- package/utilities/coerceInputValue.d.ts +7 -6
- package/utilities/coerceInputValue.js.map +1 -1
- package/utilities/coerceInputValue.mjs.map +1 -1
- package/utilities/concatAST.d.mts +4 -1
- package/utilities/concatAST.d.ts +4 -1
- package/utilities/concatAST.js.map +1 -1
- package/utilities/concatAST.mjs.map +1 -1
- package/utilities/extendSchema.d.mts +3 -3
- package/utilities/extendSchema.d.ts +3 -3
- package/utilities/extendSchema.js +5 -1
- package/utilities/extendSchema.js.map +1 -1
- package/utilities/extendSchema.mjs +5 -1
- package/utilities/extendSchema.mjs.map +1 -1
- package/utilities/introspectionFromSchema.d.mts +6 -2
- package/utilities/introspectionFromSchema.d.ts +6 -2
- package/utilities/introspectionFromSchema.js.map +1 -1
- package/utilities/introspectionFromSchema.mjs.map +1 -1
- package/utilities/lexicographicSortSchema.d.mts +5 -1
- package/utilities/lexicographicSortSchema.d.ts +5 -1
- package/utilities/lexicographicSortSchema.js.map +1 -1
- package/utilities/lexicographicSortSchema.mjs.map +1 -1
- package/utilities/printSchema.d.mts +5 -1
- package/utilities/printSchema.d.ts +5 -1
- package/utilities/printSchema.js.map +1 -1
- package/utilities/printSchema.mjs.map +1 -1
- package/utilities/replaceVariables.d.mts +4 -8
- package/utilities/replaceVariables.d.ts +4 -8
- package/utilities/replaceVariables.js.map +1 -1
- package/utilities/replaceVariables.mjs.map +1 -1
- package/utilities/stripIgnoredCharacters.d.mts +2 -2
- package/utilities/stripIgnoredCharacters.d.ts +2 -2
- package/utilities/stripIgnoredCharacters.js.map +1 -1
- package/utilities/stripIgnoredCharacters.mjs.map +1 -1
- package/utilities/typeComparators.d.mts +1 -5
- package/utilities/typeComparators.d.ts +1 -5
- package/utilities/typeComparators.js.map +1 -1
- package/utilities/typeComparators.mjs.map +1 -1
- package/utilities/validateInputValue.d.mts +10 -8
- package/utilities/validateInputValue.d.ts +10 -8
- package/utilities/validateInputValue.js.map +1 -1
- package/utilities/validateInputValue.mjs.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.mts +4 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.ts +4 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs.map +1 -1
- package/validation/rules/ExecutableDefinitionsRule.d.mts +6 -2
- package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -2
- package/validation/rules/ExecutableDefinitionsRule.js.map +1 -1
- package/validation/rules/ExecutableDefinitionsRule.mjs.map +1 -1
- package/validation/rules/FieldsOnCorrectTypeRule.d.mts +3 -1
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +3 -1
- package/validation/rules/FieldsOnCorrectTypeRule.js.map +1 -1
- package/validation/rules/FieldsOnCorrectTypeRule.mjs.map +1 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.d.mts +6 -2
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -2
- package/validation/rules/FragmentsOnCompositeTypesRule.js.map +1 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs.map +1 -1
- package/validation/rules/KnownArgumentNamesRule.d.mts +3 -1
- package/validation/rules/KnownArgumentNamesRule.d.ts +3 -1
- package/validation/rules/KnownArgumentNamesRule.js.map +1 -1
- package/validation/rules/KnownArgumentNamesRule.mjs.map +1 -1
- package/validation/rules/KnownDirectivesRule.js +2 -1
- package/validation/rules/KnownDirectivesRule.js.map +1 -1
- package/validation/rules/KnownDirectivesRule.mjs +2 -1
- package/validation/rules/KnownDirectivesRule.mjs.map +1 -1
- package/validation/rules/KnownFragmentNamesRule.d.mts +3 -1
- package/validation/rules/KnownFragmentNamesRule.d.ts +3 -1
- package/validation/rules/KnownFragmentNamesRule.js.map +1 -1
- package/validation/rules/KnownFragmentNamesRule.mjs.map +1 -1
- package/validation/rules/LoneAnonymousOperationRule.d.mts +6 -2
- package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -2
- package/validation/rules/LoneAnonymousOperationRule.js.map +1 -1
- package/validation/rules/LoneAnonymousOperationRule.mjs.map +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.d.mts +6 -2
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -2
- package/validation/rules/MaxIntrospectionDepthRule.js.map +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.mjs.map +1 -1
- package/validation/rules/NoUndefinedVariablesRule.d.mts +3 -1
- package/validation/rules/NoUndefinedVariablesRule.d.ts +3 -1
- package/validation/rules/NoUndefinedVariablesRule.js.map +1 -1
- package/validation/rules/NoUndefinedVariablesRule.mjs.map +1 -1
- package/validation/rules/NoUnusedFragmentsRule.d.mts +3 -1
- package/validation/rules/NoUnusedFragmentsRule.d.ts +3 -1
- package/validation/rules/NoUnusedFragmentsRule.js.map +1 -1
- package/validation/rules/NoUnusedFragmentsRule.mjs.map +1 -1
- package/validation/rules/NoUnusedVariablesRule.d.mts +3 -1
- package/validation/rules/NoUnusedVariablesRule.d.ts +3 -1
- package/validation/rules/NoUnusedVariablesRule.js.map +1 -1
- package/validation/rules/NoUnusedVariablesRule.mjs.map +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.mts +6 -2
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +6 -2
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.map +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs.map +1 -1
- package/validation/rules/PossibleFragmentSpreadsRule.d.mts +6 -2
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -2
- package/validation/rules/PossibleFragmentSpreadsRule.js.map +1 -1
- package/validation/rules/PossibleFragmentSpreadsRule.mjs.map +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.d.mts +6 -2
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -2
- package/validation/rules/ProvidedRequiredArgumentsRule.js.map +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs.map +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.d.mts +6 -2
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -2
- package/validation/rules/SingleFieldSubscriptionsRule.js.map +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.mjs.map +1 -1
- package/validation/rules/UniqueArgumentNamesRule.d.mts +3 -1
- package/validation/rules/UniqueArgumentNamesRule.d.ts +3 -1
- package/validation/rules/UniqueArgumentNamesRule.js.map +1 -1
- package/validation/rules/UniqueArgumentNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.d.mts +6 -2
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -2
- package/validation/rules/UniqueDirectivesPerLocationRule.js.map +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs.map +1 -1
- package/validation/rules/UniqueFragmentNamesRule.d.mts +3 -1
- package/validation/rules/UniqueFragmentNamesRule.d.ts +3 -1
- package/validation/rules/UniqueFragmentNamesRule.js.map +1 -1
- package/validation/rules/UniqueFragmentNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.d.mts +6 -2
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -2
- package/validation/rules/UniqueInputFieldNamesRule.js.map +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueOperationNamesRule.d.mts +3 -1
- package/validation/rules/UniqueOperationNamesRule.d.ts +3 -1
- package/validation/rules/UniqueOperationNamesRule.js.map +1 -1
- package/validation/rules/UniqueOperationNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueVariableNamesRule.d.mts +3 -1
- package/validation/rules/UniqueVariableNamesRule.d.ts +3 -1
- package/validation/rules/UniqueVariableNamesRule.js.map +1 -1
- package/validation/rules/UniqueVariableNamesRule.mjs.map +1 -1
- package/validation/rules/ValuesOfCorrectTypeRule.d.mts +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js.map +1 -1
- package/validation/rules/ValuesOfCorrectTypeRule.mjs.map +1 -1
- package/validation/rules/VariablesAreInputTypesRule.d.mts +6 -2
- package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -2
- package/validation/rules/VariablesAreInputTypesRule.js.map +1 -1
- package/validation/rules/VariablesAreInputTypesRule.mjs.map +1 -1
- package/validation/rules/VariablesInAllowedPositionRule.d.mts +6 -2
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -2
- package/validation/rules/VariablesInAllowedPositionRule.js.map +1 -1
- package/validation/rules/VariablesInAllowedPositionRule.mjs.map +1 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.mts +3 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +3 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.js.map +1 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs.map +1 -1
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.mts +6 -2
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +6 -2
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.map +1 -1
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs.map +1 -1
- package/validation/validate.d.mts +3 -6
- package/validation/validate.d.ts +3 -6
- package/validation/validate.js.map +1 -1
- package/validation/validate.mjs.map +1 -1
- package/version.js +3 -3
- package/version.js.map +1 -1
- package/version.mjs +3 -3
- package/version.mjs.map +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
[](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
|
[](https://badge.fury.io/js/graphql)
|
|
8
|
-
[](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 `
|
|
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
|
|
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
|
-
*
|
|
5
|
-
* that APM tools can subscribe to in
|
|
6
|
-
* execute, subscribe, and resolver behavior,
|
|
7
|
-
* At module load time
|
|
8
|
-
* APMs do not need to interact with the
|
|
9
|
-
* runtimes that do not expose
|
|
10
|
-
* load silently no-ops and
|
|
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`
|
|
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
|
|
35
|
-
* `TracingChannel` satisfies this by duck typing,
|
|
36
|
-
* a dependency on `@types/node` or on the runtime
|
|
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
|
-
/**
|
|
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
|
|
121
|
-
* `start`/`end` (and, on
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
|
185
|
+
/** Error thrown or rejected while subscribing, when setup fails abruptly. */
|
|
166
186
|
error?: unknown;
|
|
167
|
-
/**
|
|
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
|
|
214
|
-
* these by name on their own
|
|
215
|
-
* land on the same channel
|
|
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
|
|
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
|
-
*
|
|
5
|
-
* that APM tools can subscribe to in
|
|
6
|
-
* execute, subscribe, and resolver behavior,
|
|
7
|
-
* At module load time
|
|
8
|
-
* APMs do not need to interact with the
|
|
9
|
-
* runtimes that do not expose
|
|
10
|
-
* load silently no-ops and
|
|
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`
|
|
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
|
|
35
|
-
* `TracingChannel` satisfies this by duck typing,
|
|
36
|
-
* a dependency on `@types/node` or on the runtime
|
|
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
|
-
/**
|
|
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
|
|
121
|
-
* `start`/`end` (and, on
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
|
185
|
+
/** Error thrown or rejected while subscribing, when setup fails abruptly. */
|
|
166
186
|
error?: unknown;
|
|
167
|
-
/**
|
|
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
|
|
214
|
-
* these by name on their own
|
|
215
|
-
* land on the same channel
|
|
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
|
|
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
|
});
|
package/diagnostics.js.map
CHANGED
|
@@ -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
|
});
|