graphql 17.0.0-beta.2 → 17.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/__dev__/diagnostics.d.mts +1 -0
  2. package/__dev__/diagnostics.d.ts +1 -0
  3. package/__dev__/diagnostics.js +3 -0
  4. package/__dev__/diagnostics.mjs +3 -0
  5. package/diagnostics.d.mts +278 -0
  6. package/diagnostics.d.ts +278 -0
  7. package/diagnostics.js +75 -0
  8. package/diagnostics.js.map +1 -0
  9. package/diagnostics.mjs +70 -0
  10. package/diagnostics.mjs.map +1 -0
  11. package/error/GraphQLError.d.mts +3 -1
  12. package/error/GraphQLError.d.ts +3 -1
  13. package/error/GraphQLError.js +3 -3
  14. package/error/GraphQLError.js.map +1 -1
  15. package/error/GraphQLError.mjs +3 -3
  16. package/error/GraphQLError.mjs.map +1 -1
  17. package/execution/ExecutionArgs.d.mts +6 -0
  18. package/execution/ExecutionArgs.d.ts +6 -0
  19. package/execution/ExecutionArgs.js.map +1 -1
  20. package/execution/ExecutionArgs.mjs.map +1 -1
  21. package/execution/Executor.d.mts +19 -1
  22. package/execution/Executor.d.ts +19 -1
  23. package/execution/Executor.js +49 -4
  24. package/execution/Executor.js.map +1 -1
  25. package/execution/Executor.mjs +49 -4
  26. package/execution/Executor.mjs.map +1 -1
  27. package/execution/execute.js +62 -2
  28. package/execution/execute.js.map +1 -1
  29. package/execution/execute.mjs +62 -2
  30. package/execution/execute.mjs.map +1 -1
  31. package/index.d.mts +1 -0
  32. package/index.d.ts +1 -0
  33. package/index.js.map +1 -1
  34. package/index.mjs.map +1 -1
  35. package/language/parser.js +6 -0
  36. package/language/parser.js.map +1 -1
  37. package/language/parser.mjs +6 -0
  38. package/language/parser.mjs.map +1 -1
  39. package/package.json +2 -2
  40. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js +70 -17
  41. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js.map +1 -1
  42. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs +70 -17
  43. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs.map +1 -1
  44. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.mts +1 -1
  45. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.ts +1 -1
  46. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js +90 -21
  47. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js.map +1 -1
  48. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs +91 -22
  49. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs.map +1 -1
  50. package/validation/validate.js +6 -0
  51. package/validation/validate.js.map +1 -1
  52. package/validation/validate.mjs +6 -0
  53. package/validation/validate.mjs.map +1 -1
  54. package/version.js +2 -2
  55. package/version.js.map +1 -1
  56. package/version.mjs +2 -2
  57. package/version.mjs.map +1 -1
@@ -0,0 +1 @@
1
+ export * from '../diagnostics.mjs';
@@ -0,0 +1 @@
1
+ export * from '../diagnostics.js';
@@ -0,0 +1,3 @@
1
+ const { enableDevMode } = require('../devMode.js');
2
+ enableDevMode();
3
+ module.exports = require('../diagnostics.js');
@@ -0,0 +1,3 @@
1
+ import { enableDevMode } from '../devMode.mjs';
2
+ enableDevMode();
3
+ export * from '../diagnostics.mjs';
@@ -0,0 +1,278 @@
1
+ /**
2
+ * TracingChannel integration.
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.
11
+ * @category Diagnostics
12
+ */
13
+ import type { Maybe } from "./jsutils/Maybe.mjs";
14
+ import type { ObjMap } from "./jsutils/ObjMap.mjs";
15
+ import type { GraphQLError } from "./error/GraphQLError.mjs";
16
+ import type { DocumentNode, OperationDefinitionNode, OperationTypeNode } from "./language/ast.mjs";
17
+ import type { Source } from "./language/source.mjs";
18
+ import type { GraphQLSchema } from "./type/schema.mjs";
19
+ import type { ExecutionResult } from "./execution/Executor.mjs";
20
+ import type { ExperimentalIncrementalExecutionResults } from "./execution/incremental/IncrementalExecutor.mjs";
21
+ import type { VariableValues } from "./execution/values.mjs";
22
+ /**
23
+ * Structural subset of `DiagnosticsChannel` sufficient for publishing and
24
+ * subscriber gating. `node:diagnostics_channel`'s `Channel` satisfies this.
25
+ *
26
+ * @internal
27
+ */
28
+ export interface MinimalChannel<TMessage = unknown> {
29
+ readonly hasSubscribers?: boolean;
30
+ publish: (message: TMessage) => void;
31
+ runStores: <T, ContextType extends object>(context: ContextType, fn: (this: ContextType, ...args: Array<unknown>) => T, thisArg?: unknown, ...args: Array<unknown>) => T;
32
+ }
33
+ /**
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.
37
+ *
38
+ * @internal
39
+ */
40
+ export interface MinimalTracingChannel<TContext = unknown> {
41
+ readonly hasSubscribers: boolean | undefined;
42
+ readonly start: MinimalChannel<TContext>;
43
+ readonly end: MinimalChannel<TContext>;
44
+ readonly asyncStart: MinimalChannel<TContext>;
45
+ readonly asyncEnd: MinimalChannel<TContext>;
46
+ readonly error: MinimalChannel<TContext>;
47
+ traceSync: <T>(fn: (...args: Array<unknown>) => T, context: TContext extends object ? TContext : object, thisArg?: unknown, ...args: Array<unknown>) => T;
48
+ }
49
+ /**
50
+ * Context published on `graphql:parse`.
51
+ */
52
+ export interface GraphQLParseContext {
53
+ /** Source text or source object passed to the parser. */
54
+ source: string | Source;
55
+ /** Error thrown while parsing, when parsing fails. */
56
+ error?: unknown;
57
+ /** Parsed document, when parsing succeeds. */
58
+ result?: DocumentNode;
59
+ }
60
+ /**
61
+ * Context published on `graphql:validate`.
62
+ */
63
+ export interface GraphQLValidateContext {
64
+ /** Schema used for validation. */
65
+ schema: GraphQLSchema;
66
+ /** Parsed document being validated. */
67
+ document: DocumentNode;
68
+ /** Error thrown while validating, when validation fails abruptly. */
69
+ error?: unknown;
70
+ /** Validation errors returned by validation. */
71
+ result?: ReadonlyArray<GraphQLError>;
72
+ }
73
+ /**
74
+ * Context published on `graphql:execute`.
75
+ */
76
+ export interface GraphQLExecuteContext {
77
+ /** Schema used for execution. */
78
+ schema: GraphQLSchema;
79
+ /** Parsed document being executed. */
80
+ document: DocumentNode;
81
+ /** Raw variable values provided by the caller before coercion. */
82
+ rawVariableValues: Maybe<{
83
+ readonly [variable: string]: unknown;
84
+ }>;
85
+ /** Selected operation name, if one is available. */
86
+ operationName: string | undefined;
87
+ /** Selected operation type, if one is available. */
88
+ operationType: OperationTypeNode | undefined;
89
+ /** Error thrown while executing, when execution fails abruptly. */
90
+ error?: unknown;
91
+ /** Execution result returned by execution. */
92
+ result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
93
+ }
94
+ /**
95
+ * Context published on `graphql:execute:rootSelectionSet`.
96
+ */
97
+ export interface GraphQLExecuteRootSelectionSetContext {
98
+ /** Schema used for execution. */
99
+ schema: GraphQLSchema;
100
+ /** Parsed document being executed. */
101
+ document: DocumentNode;
102
+ /** Operation definition selected for execution. */
103
+ operation: OperationDefinitionNode;
104
+ /** Raw variable values provided by the caller before coercion. */
105
+ rawVariableValues: Maybe<{
106
+ readonly [variable: string]: unknown;
107
+ }>;
108
+ /** Selected operation name, if one is available. */
109
+ operationName: string | undefined;
110
+ /** Selected operation type. */
111
+ operationType: OperationTypeNode;
112
+ /** Error thrown while executing the root selection set. */
113
+ error?: unknown;
114
+ /** Execution result returned from the root selection set. */
115
+ result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
116
+ }
117
+ /**
118
+ * Context published on `graphql:execute:variableCoercion`.
119
+ *
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`.
124
+ */
125
+ export interface GraphQLExecuteVariableCoercionContext {
126
+ /** Schema used for variable coercion. */
127
+ schema: GraphQLSchema;
128
+ /** Parsed document being executed. */
129
+ document: DocumentNode;
130
+ /** Operation definition whose variables are being coerced. */
131
+ operation: OperationDefinitionNode;
132
+ /** Raw variable values provided by the caller before coercion. */
133
+ rawVariableValues: Maybe<{
134
+ readonly [variable: string]: unknown;
135
+ }>;
136
+ /** Selected operation name, if one is available. */
137
+ operationName: string | undefined;
138
+ /** Selected operation type. */
139
+ operationType: OperationTypeNode;
140
+ /** Error thrown while coercing variables, when coercion fails abruptly. */
141
+ error?: unknown;
142
+ /** Coerced variable values or coercion errors returned by coercion. */
143
+ result?: {
144
+ variableValues: VariableValues;
145
+ } | {
146
+ errors: ReadonlyArray<GraphQLError>;
147
+ };
148
+ }
149
+ /**
150
+ * Context published on `graphql:subscribe`.
151
+ */
152
+ export interface GraphQLSubscribeContext {
153
+ /** Schema used for subscription execution. */
154
+ schema: GraphQLSchema;
155
+ /** Parsed subscription document. */
156
+ document: DocumentNode;
157
+ /** Raw variable values provided by the caller before coercion. */
158
+ rawVariableValues: Maybe<{
159
+ readonly [variable: string]: unknown;
160
+ }>;
161
+ /** Selected operation name, if one is available. */
162
+ operationName: string | undefined;
163
+ /** Selected operation type, if one is available. */
164
+ operationType: OperationTypeNode | undefined;
165
+ /** Error thrown while subscribing, when subscription setup fails abruptly. */
166
+ error?: unknown;
167
+ /** Subscription response stream or execution result returned by subscribe. */
168
+ result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;
169
+ }
170
+ /**
171
+ * Context published on `graphql:resolve`.
172
+ */
173
+ export interface GraphQLResolveContext {
174
+ /** Field name being resolved. */
175
+ fieldName: string;
176
+ /** Response alias for the field being resolved. */
177
+ alias: string;
178
+ /** Parent type name for the field being resolved. */
179
+ parentType: string;
180
+ /** Return type string for the field being resolved. */
181
+ fieldType: string;
182
+ /** Argument values passed to the resolver. */
183
+ args: ObjMap<unknown>;
184
+ /** Whether the field is using the default resolver. */
185
+ isDefaultResolver: boolean;
186
+ /** Response path for the field being resolved. */
187
+ fieldPath: string;
188
+ /** Error thrown by the resolver, when resolution fails. */
189
+ error?: unknown;
190
+ /** Value returned by the resolver. */
191
+ result?: unknown;
192
+ }
193
+ /**
194
+ * Mapping from tracing channel name to the context type published on it.
195
+ */
196
+ export interface GraphQLChannelContextByName {
197
+ /** Context published on `graphql:parse`. */
198
+ 'graphql:parse': GraphQLParseContext;
199
+ /** Context published on `graphql:validate`. */
200
+ 'graphql:validate': GraphQLValidateContext;
201
+ /** Context published on `graphql:execute`. */
202
+ 'graphql:execute': GraphQLExecuteContext;
203
+ /** Context published on `graphql:execute:variableCoercion`. */
204
+ 'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;
205
+ /** Context published on `graphql:execute:rootSelectionSet`. */
206
+ 'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;
207
+ /** Context published on `graphql:subscribe`. */
208
+ 'graphql:subscribe': GraphQLSubscribeContext;
209
+ /** Context published on `graphql:resolve`. */
210
+ 'graphql:resolve': GraphQLResolveContext;
211
+ }
212
+ /**
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.
217
+ */
218
+ export interface GraphQLChannels {
219
+ /** Tracing channel for `graphql:execute`. */
220
+ execute: MinimalTracingChannel<GraphQLExecuteContext>;
221
+ /** Tracing channel for `graphql:execute:variableCoercion`. */
222
+ executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;
223
+ /** Tracing channel for `graphql:execute:rootSelectionSet`. */
224
+ executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;
225
+ /** Tracing channel for `graphql:parse`. */
226
+ parse: MinimalTracingChannel<GraphQLParseContext>;
227
+ /** Tracing channel for `graphql:validate`. */
228
+ validate: MinimalTracingChannel<GraphQLValidateContext>;
229
+ /** Tracing channel for `graphql:resolve`. */
230
+ resolve: MinimalTracingChannel<GraphQLResolveContext>;
231
+ /** Tracing channel for `graphql:subscribe`. */
232
+ subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;
233
+ }
234
+ /**
235
+ * Per-channel handles, resolved once at module load. `undefined` when
236
+ * `node:diagnostics_channel` isn't available. Emission sites read these
237
+ * directly to keep the no-subscriber fast path to a single property access
238
+ * plus a `hasSubscribers` check (no function calls, no closures).
239
+ *
240
+ * @internal
241
+ */
242
+ export declare const parseChannel: MinimalTracingChannel<GraphQLParseContext> | undefined;
243
+ /** @internal */
244
+ export declare const validateChannel: MinimalTracingChannel<GraphQLValidateContext> | undefined;
245
+ /** @internal */
246
+ export declare const executeChannel: MinimalTracingChannel<GraphQLExecuteContext> | undefined;
247
+ /** @internal */
248
+ export declare const executeVariableCoercionChannel: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext> | undefined;
249
+ /** @internal */
250
+ export declare const executeRootSelectionSetChannel: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext> | undefined;
251
+ /** @internal */
252
+ export declare const subscribeChannel: MinimalTracingChannel<GraphQLSubscribeContext> | undefined;
253
+ /** @internal */
254
+ export declare const resolveChannel: MinimalTracingChannel<GraphQLResolveContext> | undefined;
255
+ /**
256
+ * Whether emission sites should publish to `channel`. Trusts the
257
+ * `TracingChannel.hasSubscribers` aggregate when the runtime exposes it; if
258
+ * the getter is missing (e.g. Bun's `node:diagnostics_channel`, where
259
+ * `tracingChannel.hasSubscribers` is `undefined`), falls back to checking
260
+ * each of the five underlying lifecycle channels so a subscriber attached
261
+ * via `tracingChannel.subscribe(handlers)` is still observed.
262
+ *
263
+ * @internal
264
+ */
265
+ export declare function shouldTrace<TContext = unknown>(channel: MinimalTracingChannel<TContext> | undefined): channel is MinimalTracingChannel<TContext>;
266
+ interface TraceLifecycleContext {
267
+ error?: unknown;
268
+ result?: unknown;
269
+ }
270
+ type TraceStartContext<TContext extends TraceLifecycleContext> = Omit<TContext, 'error' | 'result'>;
271
+ /**
272
+ * Publish a mixed sync-or-promise operation through `channel`. Caller has
273
+ * already verified that a subscriber is attached.
274
+ *
275
+ * @internal
276
+ */
277
+ export declare function traceMixed<TResult, TContext extends TraceLifecycleContext>(channel: MinimalTracingChannel<TContext>, contextInput: TraceStartContext<TContext>, fn: () => TResult): TResult;
278
+ export {};
@@ -0,0 +1,278 @@
1
+ /**
2
+ * TracingChannel integration.
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.
11
+ * @category Diagnostics
12
+ */
13
+ import type { Maybe } from "./jsutils/Maybe.js";
14
+ import type { ObjMap } from "./jsutils/ObjMap.js";
15
+ import type { GraphQLError } from "./error/GraphQLError.js";
16
+ import type { DocumentNode, OperationDefinitionNode, OperationTypeNode } from "./language/ast.js";
17
+ import type { Source } from "./language/source.js";
18
+ import type { GraphQLSchema } from "./type/schema.js";
19
+ import type { ExecutionResult } from "./execution/Executor.js";
20
+ import type { ExperimentalIncrementalExecutionResults } from "./execution/incremental/IncrementalExecutor.js";
21
+ import type { VariableValues } from "./execution/values.js";
22
+ /**
23
+ * Structural subset of `DiagnosticsChannel` sufficient for publishing and
24
+ * subscriber gating. `node:diagnostics_channel`'s `Channel` satisfies this.
25
+ *
26
+ * @internal
27
+ */
28
+ export interface MinimalChannel<TMessage = unknown> {
29
+ readonly hasSubscribers?: boolean;
30
+ publish: (message: TMessage) => void;
31
+ runStores: <T, ContextType extends object>(context: ContextType, fn: (this: ContextType, ...args: Array<unknown>) => T, thisArg?: unknown, ...args: Array<unknown>) => T;
32
+ }
33
+ /**
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.
37
+ *
38
+ * @internal
39
+ */
40
+ export interface MinimalTracingChannel<TContext = unknown> {
41
+ readonly hasSubscribers: boolean | undefined;
42
+ readonly start: MinimalChannel<TContext>;
43
+ readonly end: MinimalChannel<TContext>;
44
+ readonly asyncStart: MinimalChannel<TContext>;
45
+ readonly asyncEnd: MinimalChannel<TContext>;
46
+ readonly error: MinimalChannel<TContext>;
47
+ traceSync: <T>(fn: (...args: Array<unknown>) => T, context: TContext extends object ? TContext : object, thisArg?: unknown, ...args: Array<unknown>) => T;
48
+ }
49
+ /**
50
+ * Context published on `graphql:parse`.
51
+ */
52
+ export interface GraphQLParseContext {
53
+ /** Source text or source object passed to the parser. */
54
+ source: string | Source;
55
+ /** Error thrown while parsing, when parsing fails. */
56
+ error?: unknown;
57
+ /** Parsed document, when parsing succeeds. */
58
+ result?: DocumentNode;
59
+ }
60
+ /**
61
+ * Context published on `graphql:validate`.
62
+ */
63
+ export interface GraphQLValidateContext {
64
+ /** Schema used for validation. */
65
+ schema: GraphQLSchema;
66
+ /** Parsed document being validated. */
67
+ document: DocumentNode;
68
+ /** Error thrown while validating, when validation fails abruptly. */
69
+ error?: unknown;
70
+ /** Validation errors returned by validation. */
71
+ result?: ReadonlyArray<GraphQLError>;
72
+ }
73
+ /**
74
+ * Context published on `graphql:execute`.
75
+ */
76
+ export interface GraphQLExecuteContext {
77
+ /** Schema used for execution. */
78
+ schema: GraphQLSchema;
79
+ /** Parsed document being executed. */
80
+ document: DocumentNode;
81
+ /** Raw variable values provided by the caller before coercion. */
82
+ rawVariableValues: Maybe<{
83
+ readonly [variable: string]: unknown;
84
+ }>;
85
+ /** Selected operation name, if one is available. */
86
+ operationName: string | undefined;
87
+ /** Selected operation type, if one is available. */
88
+ operationType: OperationTypeNode | undefined;
89
+ /** Error thrown while executing, when execution fails abruptly. */
90
+ error?: unknown;
91
+ /** Execution result returned by execution. */
92
+ result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
93
+ }
94
+ /**
95
+ * Context published on `graphql:execute:rootSelectionSet`.
96
+ */
97
+ export interface GraphQLExecuteRootSelectionSetContext {
98
+ /** Schema used for execution. */
99
+ schema: GraphQLSchema;
100
+ /** Parsed document being executed. */
101
+ document: DocumentNode;
102
+ /** Operation definition selected for execution. */
103
+ operation: OperationDefinitionNode;
104
+ /** Raw variable values provided by the caller before coercion. */
105
+ rawVariableValues: Maybe<{
106
+ readonly [variable: string]: unknown;
107
+ }>;
108
+ /** Selected operation name, if one is available. */
109
+ operationName: string | undefined;
110
+ /** Selected operation type. */
111
+ operationType: OperationTypeNode;
112
+ /** Error thrown while executing the root selection set. */
113
+ error?: unknown;
114
+ /** Execution result returned from the root selection set. */
115
+ result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
116
+ }
117
+ /**
118
+ * Context published on `graphql:execute:variableCoercion`.
119
+ *
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`.
124
+ */
125
+ export interface GraphQLExecuteVariableCoercionContext {
126
+ /** Schema used for variable coercion. */
127
+ schema: GraphQLSchema;
128
+ /** Parsed document being executed. */
129
+ document: DocumentNode;
130
+ /** Operation definition whose variables are being coerced. */
131
+ operation: OperationDefinitionNode;
132
+ /** Raw variable values provided by the caller before coercion. */
133
+ rawVariableValues: Maybe<{
134
+ readonly [variable: string]: unknown;
135
+ }>;
136
+ /** Selected operation name, if one is available. */
137
+ operationName: string | undefined;
138
+ /** Selected operation type. */
139
+ operationType: OperationTypeNode;
140
+ /** Error thrown while coercing variables, when coercion fails abruptly. */
141
+ error?: unknown;
142
+ /** Coerced variable values or coercion errors returned by coercion. */
143
+ result?: {
144
+ variableValues: VariableValues;
145
+ } | {
146
+ errors: ReadonlyArray<GraphQLError>;
147
+ };
148
+ }
149
+ /**
150
+ * Context published on `graphql:subscribe`.
151
+ */
152
+ export interface GraphQLSubscribeContext {
153
+ /** Schema used for subscription execution. */
154
+ schema: GraphQLSchema;
155
+ /** Parsed subscription document. */
156
+ document: DocumentNode;
157
+ /** Raw variable values provided by the caller before coercion. */
158
+ rawVariableValues: Maybe<{
159
+ readonly [variable: string]: unknown;
160
+ }>;
161
+ /** Selected operation name, if one is available. */
162
+ operationName: string | undefined;
163
+ /** Selected operation type, if one is available. */
164
+ operationType: OperationTypeNode | undefined;
165
+ /** Error thrown while subscribing, when subscription setup fails abruptly. */
166
+ error?: unknown;
167
+ /** Subscription response stream or execution result returned by subscribe. */
168
+ result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;
169
+ }
170
+ /**
171
+ * Context published on `graphql:resolve`.
172
+ */
173
+ export interface GraphQLResolveContext {
174
+ /** Field name being resolved. */
175
+ fieldName: string;
176
+ /** Response alias for the field being resolved. */
177
+ alias: string;
178
+ /** Parent type name for the field being resolved. */
179
+ parentType: string;
180
+ /** Return type string for the field being resolved. */
181
+ fieldType: string;
182
+ /** Argument values passed to the resolver. */
183
+ args: ObjMap<unknown>;
184
+ /** Whether the field is using the default resolver. */
185
+ isDefaultResolver: boolean;
186
+ /** Response path for the field being resolved. */
187
+ fieldPath: string;
188
+ /** Error thrown by the resolver, when resolution fails. */
189
+ error?: unknown;
190
+ /** Value returned by the resolver. */
191
+ result?: unknown;
192
+ }
193
+ /**
194
+ * Mapping from tracing channel name to the context type published on it.
195
+ */
196
+ export interface GraphQLChannelContextByName {
197
+ /** Context published on `graphql:parse`. */
198
+ 'graphql:parse': GraphQLParseContext;
199
+ /** Context published on `graphql:validate`. */
200
+ 'graphql:validate': GraphQLValidateContext;
201
+ /** Context published on `graphql:execute`. */
202
+ 'graphql:execute': GraphQLExecuteContext;
203
+ /** Context published on `graphql:execute:variableCoercion`. */
204
+ 'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;
205
+ /** Context published on `graphql:execute:rootSelectionSet`. */
206
+ 'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;
207
+ /** Context published on `graphql:subscribe`. */
208
+ 'graphql:subscribe': GraphQLSubscribeContext;
209
+ /** Context published on `graphql:resolve`. */
210
+ 'graphql:resolve': GraphQLResolveContext;
211
+ }
212
+ /**
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.
217
+ */
218
+ export interface GraphQLChannels {
219
+ /** Tracing channel for `graphql:execute`. */
220
+ execute: MinimalTracingChannel<GraphQLExecuteContext>;
221
+ /** Tracing channel for `graphql:execute:variableCoercion`. */
222
+ executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;
223
+ /** Tracing channel for `graphql:execute:rootSelectionSet`. */
224
+ executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;
225
+ /** Tracing channel for `graphql:parse`. */
226
+ parse: MinimalTracingChannel<GraphQLParseContext>;
227
+ /** Tracing channel for `graphql:validate`. */
228
+ validate: MinimalTracingChannel<GraphQLValidateContext>;
229
+ /** Tracing channel for `graphql:resolve`. */
230
+ resolve: MinimalTracingChannel<GraphQLResolveContext>;
231
+ /** Tracing channel for `graphql:subscribe`. */
232
+ subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;
233
+ }
234
+ /**
235
+ * Per-channel handles, resolved once at module load. `undefined` when
236
+ * `node:diagnostics_channel` isn't available. Emission sites read these
237
+ * directly to keep the no-subscriber fast path to a single property access
238
+ * plus a `hasSubscribers` check (no function calls, no closures).
239
+ *
240
+ * @internal
241
+ */
242
+ export declare const parseChannel: MinimalTracingChannel<GraphQLParseContext> | undefined;
243
+ /** @internal */
244
+ export declare const validateChannel: MinimalTracingChannel<GraphQLValidateContext> | undefined;
245
+ /** @internal */
246
+ export declare const executeChannel: MinimalTracingChannel<GraphQLExecuteContext> | undefined;
247
+ /** @internal */
248
+ export declare const executeVariableCoercionChannel: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext> | undefined;
249
+ /** @internal */
250
+ export declare const executeRootSelectionSetChannel: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext> | undefined;
251
+ /** @internal */
252
+ export declare const subscribeChannel: MinimalTracingChannel<GraphQLSubscribeContext> | undefined;
253
+ /** @internal */
254
+ export declare const resolveChannel: MinimalTracingChannel<GraphQLResolveContext> | undefined;
255
+ /**
256
+ * Whether emission sites should publish to `channel`. Trusts the
257
+ * `TracingChannel.hasSubscribers` aggregate when the runtime exposes it; if
258
+ * the getter is missing (e.g. Bun's `node:diagnostics_channel`, where
259
+ * `tracingChannel.hasSubscribers` is `undefined`), falls back to checking
260
+ * each of the five underlying lifecycle channels so a subscriber attached
261
+ * via `tracingChannel.subscribe(handlers)` is still observed.
262
+ *
263
+ * @internal
264
+ */
265
+ export declare function shouldTrace<TContext = unknown>(channel: MinimalTracingChannel<TContext> | undefined): channel is MinimalTracingChannel<TContext>;
266
+ interface TraceLifecycleContext {
267
+ error?: unknown;
268
+ result?: unknown;
269
+ }
270
+ type TraceStartContext<TContext extends TraceLifecycleContext> = Omit<TContext, 'error' | 'result'>;
271
+ /**
272
+ * Publish a mixed sync-or-promise operation through `channel`. Caller has
273
+ * already verified that a subscriber is attached.
274
+ *
275
+ * @internal
276
+ */
277
+ export declare function traceMixed<TResult, TContext extends TraceLifecycleContext>(channel: MinimalTracingChannel<TContext>, contextInput: TraceStartContext<TContext>, fn: () => TResult): TResult;
278
+ export {};
package/diagnostics.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveChannel = exports.subscribeChannel = exports.executeRootSelectionSetChannel = exports.executeVariableCoercionChannel = exports.executeChannel = exports.validateChannel = exports.parseChannel = void 0;
4
+ exports.shouldTrace = shouldTrace;
5
+ exports.traceMixed = traceMixed;
6
+ const isPromise_ts_1 = require("./jsutils/isPromise.js");
7
+ function resolveDiagnosticsChannel() {
8
+ let dc;
9
+ try {
10
+ const processRef = globalThis.process;
11
+ if (typeof processRef?.getBuiltinModule === 'function') {
12
+ dc = processRef.getBuiltinModule('node:diagnostics_channel');
13
+ }
14
+ }
15
+ catch {
16
+ }
17
+ return dc;
18
+ }
19
+ const dc = resolveDiagnosticsChannel();
20
+ exports.parseChannel = dc?.tracingChannel('graphql:parse');
21
+ exports.validateChannel = dc?.tracingChannel('graphql:validate');
22
+ exports.executeChannel = dc?.tracingChannel('graphql:execute');
23
+ exports.executeVariableCoercionChannel = dc?.tracingChannel('graphql:execute:variableCoercion');
24
+ exports.executeRootSelectionSetChannel = dc?.tracingChannel('graphql:execute:rootSelectionSet');
25
+ exports.subscribeChannel = dc?.tracingChannel('graphql:subscribe');
26
+ exports.resolveChannel = dc?.tracingChannel('graphql:resolve');
27
+ const SUB_CHANNEL_KEYS = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];
28
+ function shouldTrace(channel) {
29
+ if (channel == null) {
30
+ return false;
31
+ }
32
+ const aggregate = channel.hasSubscribers;
33
+ if (aggregate !== undefined) {
34
+ return aggregate;
35
+ }
36
+ for (const key of SUB_CHANNEL_KEYS) {
37
+ if (channel[key].hasSubscribers) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ function traceMixed(channel, contextInput, fn) {
44
+ const context = contextInput;
45
+ return channel.start.runStores(context, () => {
46
+ let result;
47
+ try {
48
+ result = fn();
49
+ }
50
+ catch (err) {
51
+ context.error = err;
52
+ channel.error.publish(context);
53
+ channel.end.publish(context);
54
+ throw err;
55
+ }
56
+ if (!(0, isPromise_ts_1.isPromiseLike)(result)) {
57
+ context.result = result;
58
+ channel.end.publish(context);
59
+ return result;
60
+ }
61
+ channel.end.publish(context);
62
+ channel.asyncStart.publish(context);
63
+ return result.then((value) => {
64
+ context.result = value;
65
+ channel.asyncEnd.publish(context);
66
+ return value;
67
+ }, (err) => {
68
+ context.error = err;
69
+ channel.error.publish(context);
70
+ channel.asyncEnd.publish(context);
71
+ throw err;
72
+ });
73
+ });
74
+ }
75
+ //# sourceMappingURL=diagnostics.js.map