Skip to content

Commit 0af568b

Browse files
committed
docs(diagnostics): document tracing public API
1 parent 3322438 commit 0af568b

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

src/diagnostics.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* APMs do not need to interact with the graphql API to enable tracing. On
1010
* runtimes that do not expose `node:diagnostics_channel` (e.g., browsers) the
1111
* load silently no-ops and emission sites short-circuit.
12+
* @category Diagnostics
1213
*/
1314

1415
import { isPromise } from './jsutils/isPromise.ts';
@@ -82,45 +83,67 @@ interface DiagnosticsChannelModule {
8283
* Context published on `graphql:parse`.
8384
*/
8485
export interface GraphQLParseContext {
86+
/** Source text or source object passed to the parser. */
8587
source: string | Source;
88+
/** Error thrown while parsing, when parsing fails. */
8689
error?: unknown;
90+
/** Parsed document, when parsing succeeds. */
8791
result?: DocumentNode;
8892
}
8993

9094
/**
9195
* Context published on `graphql:validate`.
9296
*/
9397
export interface GraphQLValidateContext {
98+
/** Schema used for validation. */
9499
schema: GraphQLSchema;
100+
/** Parsed document being validated. */
95101
document: DocumentNode;
102+
/** Error thrown while validating, when validation fails abruptly. */
96103
error?: unknown;
104+
/** Validation errors returned by validation. */
97105
result?: ReadonlyArray<GraphQLError>;
98106
}
99107

100108
/**
101109
* Context published on `graphql:execute`.
102110
*/
103111
export interface GraphQLExecuteContext {
112+
/** Schema used for execution. */
104113
schema: GraphQLSchema;
114+
/** Parsed document being executed. */
105115
document: DocumentNode;
116+
/** Raw variable values provided by the caller before coercion. */
106117
variableValues: Maybe<{ readonly [variable: string]: unknown }>;
118+
/** Selected operation name, if one is available. */
107119
operationName: string | undefined;
120+
/** Selected operation type, if one is available. */
108121
operationType: OperationTypeNode | undefined;
122+
/** Error thrown while executing, when execution fails abruptly. */
109123
error?: unknown;
124+
/** Execution result returned by execution. */
110125
result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
111126
}
112127

113128
/**
114129
* Context published on `graphql:execute:rootSelectionSet`.
115130
*/
116131
export interface GraphQLExecuteRootSelectionSetContext {
132+
/** Schema used for execution. */
117133
schema: GraphQLSchema;
134+
/** Parsed document being executed. */
118135
document: DocumentNode;
136+
/** Operation definition selected for execution. */
119137
operation: OperationDefinitionNode;
138+
/** Raw variable values provided by the caller before coercion. */
120139
variableValues: Maybe<{ readonly [variable: string]: unknown }>;
140+
/** Selected operation name, if one is available. */
121141
operationName: string | undefined;
142+
/** Selected operation type. */
122143
operationType: OperationTypeNode;
144+
/** Error thrown while executing the root selection set. */
123145
error?: unknown;
146+
/** Execution result returned from the root selection set. */
124147
result?: ExecutionResult | ExperimentalIncrementalExecutionResults;
125148
}
126149

@@ -133,13 +156,21 @@ export interface GraphQLExecuteRootSelectionSetContext {
133156
* carries the `errors` array, mirroring `graphql:validate`.
134157
*/
135158
export interface GraphQLExecuteVariableCoercionContext {
159+
/** Schema used for variable coercion. */
136160
schema: GraphQLSchema;
161+
/** Parsed document being executed. */
137162
document: DocumentNode;
163+
/** Operation definition whose variables are being coerced. */
138164
operation: OperationDefinitionNode;
165+
/** Raw variable values provided by the caller before coercion. */
139166
rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;
167+
/** Selected operation name, if one is available. */
140168
operationName: string | undefined;
169+
/** Selected operation type. */
141170
operationType: OperationTypeNode;
171+
/** Error thrown while coercing variables, when coercion fails abruptly. */
142172
error?: unknown;
173+
/** Coerced variable values or coercion errors returned by coercion. */
143174
result?:
144175
| { variableValues: VariableValues }
145176
| { errors: ReadonlyArray<GraphQLError> };
@@ -149,37 +180,63 @@ export interface GraphQLExecuteVariableCoercionContext {
149180
* Context published on `graphql:subscribe`.
150181
*/
151182
export interface GraphQLSubscribeContext {
183+
/** Schema used for subscription execution. */
152184
schema: GraphQLSchema;
185+
/** Parsed subscription document. */
153186
document: DocumentNode;
187+
/** Raw variable values provided by the caller before coercion. */
154188
variableValues: Maybe<{ readonly [variable: string]: unknown }>;
189+
/** Selected operation name, if one is available. */
155190
operationName: string | undefined;
191+
/** Selected operation type, if one is available. */
156192
operationType: OperationTypeNode | undefined;
193+
/** Error thrown while subscribing, when subscription setup fails abruptly. */
157194
error?: unknown;
195+
/** Subscription response stream or execution result returned by subscribe. */
158196
result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;
159197
}
160198

161199
/**
162200
* Context published on `graphql:resolve`.
163201
*/
164202
export interface GraphQLResolveContext {
203+
/** Field name being resolved. */
165204
fieldName: string;
205+
/** Response alias for the field being resolved. */
166206
alias: string;
207+
/** Parent type name for the field being resolved. */
167208
parentType: string;
209+
/** Return type string for the field being resolved. */
168210
fieldType: string;
211+
/** Argument values passed to the resolver. */
169212
args: ObjMap<unknown>;
213+
/** Whether the field is using the default resolver. */
170214
isDefaultResolver: boolean;
215+
/** Response path for the field being resolved. */
171216
fieldPath: string;
217+
/** Error thrown by the resolver, when resolution fails. */
172218
error?: unknown;
219+
/** Value returned by the resolver. */
173220
result?: unknown;
174221
}
175222

223+
/**
224+
* Mapping from tracing channel name to the context type published on it.
225+
*/
176226
export interface GraphQLChannelContextByName {
227+
/** Context published on `graphql:parse`. */
177228
'graphql:parse': GraphQLParseContext;
229+
/** Context published on `graphql:validate`. */
178230
'graphql:validate': GraphQLValidateContext;
231+
/** Context published on `graphql:execute`. */
179232
'graphql:execute': GraphQLExecuteContext;
233+
/** Context published on `graphql:execute:variableCoercion`. */
180234
'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;
235+
/** Context published on `graphql:execute:rootSelectionSet`. */
181236
'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;
237+
/** Context published on `graphql:subscribe`. */
182238
'graphql:subscribe': GraphQLSubscribeContext;
239+
/** Context published on `graphql:resolve`. */
183240
'graphql:resolve': GraphQLResolveContext;
184241
}
185242

@@ -190,12 +247,19 @@ export interface GraphQLChannelContextByName {
190247
* by name.
191248
*/
192249
export interface GraphQLChannels {
250+
/** Tracing channel for `graphql:execute`. */
193251
execute: MinimalTracingChannel<GraphQLExecuteContext>;
252+
/** Tracing channel for `graphql:execute:variableCoercion`. */
194253
executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;
254+
/** Tracing channel for `graphql:execute:rootSelectionSet`. */
195255
executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;
256+
/** Tracing channel for `graphql:parse`. */
196257
parse: MinimalTracingChannel<GraphQLParseContext>;
258+
/** Tracing channel for `graphql:validate`. */
197259
validate: MinimalTracingChannel<GraphQLValidateContext>;
260+
/** Tracing channel for `graphql:resolve`. */
198261
resolve: MinimalTracingChannel<GraphQLResolveContext>;
262+
/** Tracing channel for `graphql:subscribe`. */
199263
subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;
200264
}
201265

src/execution/Executor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ export class Executor<
267267
* Build an operation-scoped diagnostics context from ValidatedExecutionArgs.
268268
* Used after the operation has already been resolved during argument
269269
* validation.
270+
* @internal
270271
*/
271272
buildExecuteContextFromValidatedArgs(
272273
args: ValidatedExecutionArgs,
@@ -676,6 +677,7 @@ export class Executor<
676677
* `fieldPath` is exposed as a lazy getter because serializing the response
677678
* path is O(depth) and APMs that depth-filter or skip default resolvers
678679
* often never read it. `args` is passed through by reference.
680+
* @internal
679681
*/
680682
buildResolveContext(
681683
args: ObjMap<unknown>,

src/execution/execute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
123123
* Build a graphql:execute channel context from raw ExecutionArgs. Defers
124124
* resolution of the operation AST to a lazy getter so the cost of walking
125125
* the document is only paid if a subscriber reads it.
126+
* @internal
126127
*/
127128
function buildOperationContextFromArgs(
128129
args: ExecutionArgs,

0 commit comments

Comments
 (0)