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.
- package/__dev__/diagnostics.d.mts +1 -0
- package/__dev__/diagnostics.d.ts +1 -0
- package/__dev__/diagnostics.js +3 -0
- package/__dev__/diagnostics.mjs +3 -0
- package/diagnostics.d.mts +278 -0
- package/diagnostics.d.ts +278 -0
- package/diagnostics.js +75 -0
- package/diagnostics.js.map +1 -0
- package/diagnostics.mjs +70 -0
- package/diagnostics.mjs.map +1 -0
- package/error/GraphQLError.d.mts +3 -1
- package/error/GraphQLError.d.ts +3 -1
- package/error/GraphQLError.js +3 -3
- package/error/GraphQLError.js.map +1 -1
- package/error/GraphQLError.mjs +3 -3
- package/error/GraphQLError.mjs.map +1 -1
- package/execution/ExecutionArgs.d.mts +6 -0
- package/execution/ExecutionArgs.d.ts +6 -0
- package/execution/ExecutionArgs.js.map +1 -1
- package/execution/ExecutionArgs.mjs.map +1 -1
- package/execution/Executor.d.mts +19 -1
- package/execution/Executor.d.ts +19 -1
- package/execution/Executor.js +49 -4
- package/execution/Executor.js.map +1 -1
- package/execution/Executor.mjs +49 -4
- package/execution/Executor.mjs.map +1 -1
- package/execution/execute.js +62 -2
- package/execution/execute.js.map +1 -1
- package/execution/execute.mjs +62 -2
- package/execution/execute.mjs.map +1 -1
- package/index.d.mts +1 -0
- package/index.d.ts +1 -0
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/language/parser.js +6 -0
- package/language/parser.js.map +1 -1
- package/language/parser.mjs +6 -0
- package/language/parser.mjs.map +1 -1
- package/package.json +2 -2
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js +70 -17
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs +70 -17
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.mts +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.ts +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js +90 -21
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs +91 -22
- package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs.map +1 -1
- package/validation/validate.js +6 -0
- package/validation/validate.js.map +1 -1
- package/validation/validate.mjs +6 -0
- package/validation/validate.mjs.map +1 -1
- package/version.js +2 -2
- package/version.js.map +1 -1
- package/version.mjs +2 -2
- package/version.mjs.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":";;;AAoVA,kCAiBC;AAkBD,gCAyCC;AAnZD,yDAAuD;AA2PvD,SAAS,yBAAyB;IAChC,IAAI,EAAwC,CAAC;IAC7C,IAAI,CAAC;QACH,MAAM,UAAU,GACd,UAGD,CAAC,OAAO,CAAC;QACV,IAEE,OAAO,UAAU,EAAE,gBAAgB,KAAK,UAAU,EAClD,CAAC;YAED,EAAE,GAAG,UAAU,CAAC,gBAAgB,CAC9B,0BAA0B,CACC,CAAC;QAChC,CAAC;IAEH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,EAAE,GAAG,yBAAyB,EAAE,CAAC;AAU1B,QAAA,YAAY,GAET,EAAE,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;AAEvC,QAAA,eAAe,GAEZ,EAAE,EAAE,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAE1C,QAAA,cAAc,GAEX,EAAE,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAEzC,QAAA,8BAA8B,GAE3B,EAAE,EAAE,cAAc,CAAC,kCAAkC,CAAC,CAAC;AAE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AED,IAAI,CAAC,IAAA,4BAAa,EAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpC,OAAO,MAAM,CAAC,IAAI,CAChB,CAAC,KAAK,EAAE,EAAE;YACR,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;YACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC,EACD,CAAC,GAAY,EAAE,EAAE;YACf,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAClC,MAAM,GAAG,CAAC;QACZ,CAAC,CACS,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC","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"]}
|
package/diagnostics.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isPromiseLike } from "./jsutils/isPromise.mjs";
|
|
2
|
+
function resolveDiagnosticsChannel() {
|
|
3
|
+
let dc;
|
|
4
|
+
try {
|
|
5
|
+
const processRef = globalThis.process;
|
|
6
|
+
if (typeof processRef?.getBuiltinModule === 'function') {
|
|
7
|
+
dc = processRef.getBuiltinModule('node:diagnostics_channel');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
}
|
|
12
|
+
return dc;
|
|
13
|
+
}
|
|
14
|
+
const dc = resolveDiagnosticsChannel();
|
|
15
|
+
export const parseChannel = dc?.tracingChannel('graphql:parse');
|
|
16
|
+
export const validateChannel = dc?.tracingChannel('graphql:validate');
|
|
17
|
+
export const executeChannel = dc?.tracingChannel('graphql:execute');
|
|
18
|
+
export const executeVariableCoercionChannel = dc?.tracingChannel('graphql:execute:variableCoercion');
|
|
19
|
+
export const executeRootSelectionSetChannel = dc?.tracingChannel('graphql:execute:rootSelectionSet');
|
|
20
|
+
export const subscribeChannel = dc?.tracingChannel('graphql:subscribe');
|
|
21
|
+
export const resolveChannel = dc?.tracingChannel('graphql:resolve');
|
|
22
|
+
const SUB_CHANNEL_KEYS = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];
|
|
23
|
+
export function shouldTrace(channel) {
|
|
24
|
+
if (channel == null) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const aggregate = channel.hasSubscribers;
|
|
28
|
+
if (aggregate !== undefined) {
|
|
29
|
+
return aggregate;
|
|
30
|
+
}
|
|
31
|
+
for (const key of SUB_CHANNEL_KEYS) {
|
|
32
|
+
if (channel[key].hasSubscribers) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
export function traceMixed(channel, contextInput, fn) {
|
|
39
|
+
const context = contextInput;
|
|
40
|
+
return channel.start.runStores(context, () => {
|
|
41
|
+
let result;
|
|
42
|
+
try {
|
|
43
|
+
result = fn();
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
context.error = err;
|
|
47
|
+
channel.error.publish(context);
|
|
48
|
+
channel.end.publish(context);
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
if (!isPromiseLike(result)) {
|
|
52
|
+
context.result = result;
|
|
53
|
+
channel.end.publish(context);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
channel.end.publish(context);
|
|
57
|
+
channel.asyncStart.publish(context);
|
|
58
|
+
return result.then((value) => {
|
|
59
|
+
context.result = value;
|
|
60
|
+
channel.asyncEnd.publish(context);
|
|
61
|
+
return value;
|
|
62
|
+
}, (err) => {
|
|
63
|
+
context.error = err;
|
|
64
|
+
channel.error.publish(context);
|
|
65
|
+
channel.asyncEnd.publish(context);
|
|
66
|
+
throw err;
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,gCAA+B;AA2PvD,SAAS,yBAAyB;IAChC,IAAI,EAAwC,CAAC;IAC7C,IAAI,CAAC;QACH,MAAM,UAAU,GACd,UAGD,CAAC,OAAO,CAAC;QACV,IAEE,OAAO,UAAU,EAAE,gBAAgB,KAAK,UAAU,EAClD,CAAC;YAED,EAAE,GAAG,UAAU,CAAC,gBAAgB,CAC9B,0BAA0B,CACC,CAAC;QAChC,CAAC;IAEH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,EAAE,GAAG,yBAAyB,EAAE,CAAC;AAUvC,MAAM,CAAC,MAAM,YAAY,GAET,EAAE,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,eAAe,GAEZ,EAAE,EAAE,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAEX,EAAE,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,8BAA8B,GAE3B,EAAE,EAAE,cAAc,CAAC,kCAAkC,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,8BAA8B,GAE3B,EAAE,EAAE,cAAc,C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AC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpC,OAAO,MAAM,CAAC,IAAI,CAChB,CAAC,KAAK,EAAE,EAAE;YACR,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;YACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC,EACD,CAAC,GAAY,EAAE,EAAE;YACf,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAClC,MAAM,GAAG,CAAC;QACZ,CAAC,CACS,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC","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"]}
|
package/error/GraphQLError.d.mts
CHANGED
|
@@ -37,6 +37,7 @@ export interface GraphQLErrorOptions {
|
|
|
37
37
|
path?: Maybe<ReadonlyArray<string | number>>;
|
|
38
38
|
/**
|
|
39
39
|
* Original error that caused this GraphQLError, if one exists.
|
|
40
|
+
* Deprecated in favor of `cause` to better align with JavaScript standards.
|
|
40
41
|
* @deprecated Prefer `cause` instead.
|
|
41
42
|
*/
|
|
42
43
|
originalError?: Maybe<Error & {
|
|
@@ -87,7 +88,8 @@ export declare class GraphQLError extends Error {
|
|
|
87
88
|
*/
|
|
88
89
|
readonly positions: ReadonlyArray<number> | undefined;
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
+
* Original error that caused this GraphQLError, if one exists.
|
|
92
|
+
* Deprecated in favor of `cause` to better align with JavaScript standards.
|
|
91
93
|
* @deprecated Use `cause` instead.
|
|
92
94
|
*/
|
|
93
95
|
readonly originalError: Error | undefined;
|
package/error/GraphQLError.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface GraphQLErrorOptions {
|
|
|
37
37
|
path?: Maybe<ReadonlyArray<string | number>>;
|
|
38
38
|
/**
|
|
39
39
|
* Original error that caused this GraphQLError, if one exists.
|
|
40
|
+
* Deprecated in favor of `cause` to better align with JavaScript standards.
|
|
40
41
|
* @deprecated Prefer `cause` instead.
|
|
41
42
|
*/
|
|
42
43
|
originalError?: Maybe<Error & {
|
|
@@ -87,7 +88,8 @@ export declare class GraphQLError extends Error {
|
|
|
87
88
|
*/
|
|
88
89
|
readonly positions: ReadonlyArray<number> | undefined;
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
+
* Original error that caused this GraphQLError, if one exists.
|
|
92
|
+
* Deprecated in favor of `cause` to better align with JavaScript standards.
|
|
91
93
|
* @deprecated Use `cause` instead.
|
|
92
94
|
*/
|
|
93
95
|
readonly originalError: Error | undefined;
|
package/error/GraphQLError.js
CHANGED
|
@@ -13,7 +13,7 @@ class GraphQLError extends Error {
|
|
|
13
13
|
super(message, errorOptions);
|
|
14
14
|
this.name = 'GraphQLError';
|
|
15
15
|
this.path = path ?? undefined;
|
|
16
|
-
const underlyingError = originalError ?? (
|
|
16
|
+
const underlyingError = originalError ?? (cause instanceof Error ? cause : undefined);
|
|
17
17
|
this.originalError = underlyingError;
|
|
18
18
|
this.nodes = undefinedIfEmpty(Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined);
|
|
19
19
|
const nodeLocations = undefinedIfEmpty(this.nodes
|
|
@@ -40,9 +40,9 @@ class GraphQLError extends Error {
|
|
|
40
40
|
positions: { enumerable: false },
|
|
41
41
|
originalError: { enumerable: false },
|
|
42
42
|
});
|
|
43
|
-
if (
|
|
43
|
+
if (originalError?.stack != null) {
|
|
44
44
|
Object.defineProperty(this, 'stack', {
|
|
45
|
-
value:
|
|
45
|
+
value: originalError.stack,
|
|
46
46
|
writable: true,
|
|
47
47
|
configurable: true,
|
|
48
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphQLError.js","sourceRoot":"","sources":["../../src/error/GraphQLError.ts"],"names":[],"mappings":";;;AAEA,gEAA0D;AAK1D,yDAAsD;AACtD,mEAGsC;AAsDtC,MAAa,YAAa,SAAQ,KAAK;IA0FrC,YAAY,OAAe,EAAE,UAA+B,EAAE;QAC5D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GACxE,OAAO,CAAC;QAEV,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC;QACpC,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;QACpD,MAAM,YAAY,GAChB,QAAQ,IAAI,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAE7B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,SAAS,CAAC;QAC9B,MAAM,eAAe,GAGnB,aAAa,IAAI,CAAC,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC1E,IAAI,CAAC,aAAa,GAAG,eAAe,CAAC;QAGrC,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAC3B,KAAK,CAAC,OAAO,CAAC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ACH,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACzC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACtC,MAAM,IAAI,MAAM,GAAG,IAAA,sCAAmB,EAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAiBD,MAAM;QAKJ,MAAM,cAAc,GAA2B;YAC7C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC3B,cAAc,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAClC,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvE,cAAc,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAC9C,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAxPD,oCAwPC;AAED,SAAS,gBAAgB,CACvB,KAA2B;IAE3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACvE,CAAC","sourcesContent":["/** @category Errors */\n\nimport { isObjectLike } from '../jsutils/isObjectLike.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport type { ASTNode, Location } from '../language/ast.ts';\nimport type { SourceLocation } from '../language/location.ts';\nimport { getLocation } from '../language/location.ts';\nimport {\n printLocation,\n printSourceLocation,\n} from '../language/printLocation.ts';\nimport type { Source } from '../language/source.ts';\n\n/**\n * Custom extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/**\n * Custom formatted extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLFormattedErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/** Options used to construct a GraphQLError. */\nexport interface GraphQLErrorOptions {\n /** AST node or nodes associated with this error. */\n nodes?: ReadonlyArray<ASTNode> | ASTNode | null | undefined;\n /** Source document used to derive error locations. */\n source?: Maybe<Source>;\n /** Character offsets in the source document associated with this error. */\n positions?: Maybe<ReadonlyArray<number>>;\n /** Response path where this error occurred during execution. */\n path?: Maybe<ReadonlyArray<string | number>>;\n /**\n * Original error that caused this GraphQLError, if one exists.\n * @deprecated Prefer `cause` instead.\n */\n originalError?: Maybe<Error & { readonly extensions?: unknown }>;\n /** Cause of this GraphQLError, if one exists. */\n cause?: unknown;\n /** Extension fields to include in the formatted result. */\n extensions?: Maybe<GraphQLErrorExtensions>;\n}\n\n/**\n * A GraphQLError describes an Error found during the parse, validate, or\n * execute phases of performing a GraphQL operation. In addition to a message\n * and stack trace, it also includes information about the locations in a\n * GraphQL document and/or execution result that correspond to the Error.\n */\nexport class GraphQLError extends Error {\n /**\n * An array of `{ line, column }` locations within the source GraphQL document\n * which correspond to this error.\n *\n * Errors during validation often contain multiple locations, for example to\n * point out two things with the same name. Errors during execution include a\n * single location, the field which produced the error.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly locations: ReadonlyArray<SourceLocation> | undefined;\n\n /**\n * An array describing the JSON-path into the execution response which\n * corresponds to this error. Only included for errors during execution.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly path: ReadonlyArray<string | number> | undefined;\n\n /** An array of GraphQL AST Nodes corresponding to this error. */\n readonly nodes: ReadonlyArray<ASTNode> | undefined;\n\n /**\n * The source GraphQL document for the first location of this error.\n *\n * Note that if this Error represents more than one node, the source may not\n * represent nodes after the first node.\n */\n readonly source: Source | undefined;\n\n /**\n * An array of character offsets within the source GraphQL document\n * which correspond to this error.\n */\n readonly positions: ReadonlyArray<number> | undefined;\n\n /**\n * The original error thrown from a field resolver during execution.\n * @deprecated Use `cause` instead.\n */\n readonly originalError: Error | undefined;\n\n /** Extension fields to add to the formatted error. */\n readonly extensions: GraphQLErrorExtensions;\n\n /**\n * Creates a GraphQLError instance.\n * @param message - Human-readable error message.\n * @param options - Error metadata such as source locations, response path, cause, original error, and extensions.\n * @example\n * ```ts\n * // Create an error from AST nodes and response metadata.\n * import { parse } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const document = parse('{ greeting }');\n * const fieldNode = document.definitions[0].selectionSet.selections[0];\n * const error = new GraphQLError('Cannot query this field.', {\n * nodes: fieldNode,\n * path: ['greeting'],\n * extensions: { code: 'FORBIDDEN' },\n * });\n *\n * error.message; // => 'Cannot query this field.'\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.extensions; // => { code: 'FORBIDDEN' }\n * ```\n * @example\n * ```ts\n * // This variant derives locations from source positions and preserves the cause.\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const source = new Source('{ greeting }');\n * const cause = new Error('Database unavailable.');\n * const error = new GraphQLError('Resolver failed.', {\n * source,\n * positions: [2],\n * path: ['greeting'],\n * cause,\n * });\n *\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.cause; // => cause\n * ```\n */\n constructor(message: string, options: GraphQLErrorOptions = {}) {\n const { nodes, source, positions, path, originalError, cause, extensions } =\n options;\n\n const hasCause = 'cause' in options;\n const errorCause = hasCause ? cause : originalError;\n const errorOptions =\n hasCause || originalError != null ? { cause: errorCause } : undefined;\n super(message, errorOptions);\n\n this.name = 'GraphQLError';\n this.path = path ?? undefined;\n const underlyingError:\n | (Error & { readonly extensions?: unknown })\n | undefined =\n originalError ?? (errorCause instanceof Error ? errorCause : undefined);\n this.originalError = underlyingError;\n\n // Compute list of blame nodes.\n this.nodes = undefinedIfEmpty(\n Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,\n );\n\n const nodeLocations = undefinedIfEmpty(\n this.nodes\n ?.map((node) => node.loc)\n .filter((loc): loc is Location => loc != null),\n );\n\n // Compute locations in the source for the given nodes/positions.\n this.source = source ?? nodeLocations?.[0]?.source;\n\n this.positions = positions ?? nodeLocations?.map((loc) => loc.start);\n\n this.locations =\n positions && source\n ? positions.map((pos) => getLocation(source, pos))\n : nodeLocations?.map((loc) => getLocation(loc.source, loc.start));\n\n const originalExtensions = isObjectLike(underlyingError?.extensions)\n ? underlyingError.extensions\n : undefined;\n this.extensions = extensions ?? originalExtensions ?? Object.create(null);\n\n // Only properties prescribed by the spec should be enumerable.\n // Keep the rest as non-enumerable.\n Object.defineProperties(this, {\n message: {\n writable: true,\n enumerable: true,\n },\n name: { enumerable: false },\n nodes: { enumerable: false },\n source: { enumerable: false },\n positions: { enumerable: false },\n originalError: { enumerable: false },\n });\n\n // Include (non-enumerable) stack trace.\n if (underlyingError?.stack != null) {\n Object.defineProperty(this, 'stack', {\n value: underlyingError.stack,\n writable: true,\n configurable: true,\n });\n } else if (Error.captureStackTrace != null) {\n Error.captureStackTrace(this, GraphQLError);\n // See: https://github.com/graphql/graphql-js/issues/2317\n /* node:coverage ignore next 7 */\n } else {\n Object.defineProperty(this, 'stack', {\n value: Error().stack,\n writable: true,\n configurable: true,\n });\n }\n }\n\n /**\n * Returns the value used by `Object.prototype.toString`.\n * @returns The built-in string tag for this object.\n */\n get [Symbol.toStringTag](): string {\n return 'GraphQLError';\n }\n\n /**\n * Returns this error as a human-readable message with source locations.\n * @returns The formatted error string.\n * @example\n * ```ts\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Cannot query field \"name\".', {\n * source: new Source('{ name }'),\n * positions: [2],\n * });\n *\n * error.toString(); // => 'Cannot query field \"name\".\\n\\nGraphQL request:1:3\\n1 | { name }\\n | ^'\n * ```\n */\n override toString(): string {\n let output = this.message;\n\n if (this.nodes) {\n for (const node of this.nodes) {\n if (node.loc) {\n output += '\\n\\n' + printLocation(node.loc);\n }\n }\n } else if (this.source && this.locations) {\n for (const location of this.locations) {\n output += '\\n\\n' + printSourceLocation(this.source, location);\n }\n }\n\n return output;\n }\n\n /**\n * Returns the JSON representation used when this object is serialized.\n * @returns The JSON-serializable representation.\n * @example\n * ```ts\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Resolver failed.', {\n * path: ['viewer', 'name'],\n * extensions: { code: 'INTERNAL' },\n * });\n *\n * error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }\n * ```\n */\n toJSON(): GraphQLFormattedError {\n type WritableFormattedError = {\n -readonly [P in keyof GraphQLFormattedError]: GraphQLFormattedError[P];\n };\n\n const formattedError: WritableFormattedError = {\n message: this.message,\n };\n\n if (this.locations != null) {\n formattedError.locations = this.locations;\n }\n\n if (this.path != null) {\n formattedError.path = this.path;\n }\n\n if (this.extensions != null && Object.keys(this.extensions).length > 0) {\n formattedError.extensions = this.extensions;\n }\n\n return formattedError;\n }\n}\n\nfunction undefinedIfEmpty<T>(\n array: Array<T> | undefined,\n): Array<T> | undefined {\n return array === undefined || array.length === 0 ? undefined : array;\n}\n\n/** See: https://spec.graphql.org/draft/#sec-Errors */\nexport interface GraphQLFormattedError {\n /**\n * A short, human-readable summary of the problem that **SHOULD NOT** change\n * from occurrence to occurrence of the problem, except for purposes of\n * localization.\n */\n readonly message: string;\n /**\n * If an error can be associated to a particular point in the requested\n * GraphQL document, it should contain a list of locations.\n */\n readonly locations?: ReadonlyArray<SourceLocation>;\n /**\n * If an error can be associated to a particular field in the GraphQL result,\n * it _must_ contain an entry with the key `path` that details the path of\n * the response field which experienced the error. This allows clients to\n * identify whether a null result is intentional or caused by a runtime error.\n */\n readonly path?: ReadonlyArray<string | number>;\n /**\n * Reserved for implementors to extend the protocol however they see fit,\n * and hence there are no additional restrictions on its contents.\n */\n readonly extensions?: GraphQLFormattedErrorExtensions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GraphQLError.js","sourceRoot":"","sources":["../../src/error/GraphQLError.ts"],"names":[],"mappings":";;;AAEA,gEAA0D;AAK1D,yDAAsD;AACtD,mEAGsC;AAuDtC,MAAa,YAAa,SAAQ,KAAK;IA2FrC,YAAY,OAAe,EAAE,UAA+B,EAAE;QAC5D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GACxE,OAAO,CAAC;QAEV,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC;QACpC,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;QACpD,MAAM,YAAY,GAChB,QAAQ,IAAI,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAE7B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,SAAS,CAAC;QAC9B,MAAM,eAAe,GACnB,aAAa,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,aAAa,GAAG,eAAe,CAAC;QAGrC,IAAI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,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;QACH,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACzC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACtC,MAAM,IAAI,MAAM,GAAG,IAAA,sCAAmB,EAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAiBD,MAAM;QAKJ,MAAM,cAAc,GAA2B;YAC7C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC3B,cAAc,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAClC,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvE,cAAc,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAC9C,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AA3PD,oCA2PC;AAED,SAAS,gBAAgB,CACvB,KAA2B;IAE3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACvE,CAAC","sourcesContent":["/** @category Errors */\n\nimport { isObjectLike } from '../jsutils/isObjectLike.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport type { ASTNode, Location } from '../language/ast.ts';\nimport type { SourceLocation } from '../language/location.ts';\nimport { getLocation } from '../language/location.ts';\nimport {\n printLocation,\n printSourceLocation,\n} from '../language/printLocation.ts';\nimport type { Source } from '../language/source.ts';\n\n/**\n * Custom extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/**\n * Custom formatted extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLFormattedErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/** Options used to construct a GraphQLError. */\nexport interface GraphQLErrorOptions {\n /** AST node or nodes associated with this error. */\n nodes?: ReadonlyArray<ASTNode> | ASTNode | null | undefined;\n /** Source document used to derive error locations. */\n source?: Maybe<Source>;\n /** Character offsets in the source document associated with this error. */\n positions?: Maybe<ReadonlyArray<number>>;\n /** Response path where this error occurred during execution. */\n path?: Maybe<ReadonlyArray<string | number>>;\n /**\n * Original error that caused this GraphQLError, if one exists.\n * Deprecated in favor of `cause` to better align with JavaScript standards.\n * @deprecated Prefer `cause` instead.\n */\n originalError?: Maybe<Error & { readonly extensions?: unknown }>;\n /** Cause of this GraphQLError, if one exists. */\n cause?: unknown;\n /** Extension fields to include in the formatted result. */\n extensions?: Maybe<GraphQLErrorExtensions>;\n}\n\n/**\n * A GraphQLError describes an Error found during the parse, validate, or\n * execute phases of performing a GraphQL operation. In addition to a message\n * and stack trace, it also includes information about the locations in a\n * GraphQL document and/or execution result that correspond to the Error.\n */\nexport class GraphQLError extends Error {\n /**\n * An array of `{ line, column }` locations within the source GraphQL document\n * which correspond to this error.\n *\n * Errors during validation often contain multiple locations, for example to\n * point out two things with the same name. Errors during execution include a\n * single location, the field which produced the error.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly locations: ReadonlyArray<SourceLocation> | undefined;\n\n /**\n * An array describing the JSON-path into the execution response which\n * corresponds to this error. Only included for errors during execution.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly path: ReadonlyArray<string | number> | undefined;\n\n /** An array of GraphQL AST Nodes corresponding to this error. */\n readonly nodes: ReadonlyArray<ASTNode> | undefined;\n\n /**\n * The source GraphQL document for the first location of this error.\n *\n * Note that if this Error represents more than one node, the source may not\n * represent nodes after the first node.\n */\n readonly source: Source | undefined;\n\n /**\n * An array of character offsets within the source GraphQL document\n * which correspond to this error.\n */\n readonly positions: ReadonlyArray<number> | undefined;\n\n /**\n * Original error that caused this GraphQLError, if one exists.\n * Deprecated in favor of `cause` to better align with JavaScript standards.\n * @deprecated Use `cause` instead.\n */\n readonly originalError: Error | undefined;\n\n /** Extension fields to add to the formatted error. */\n readonly extensions: GraphQLErrorExtensions;\n\n /**\n * Creates a GraphQLError instance.\n * @param message - Human-readable error message.\n * @param options - Error metadata such as source locations, response path, cause, original error, and extensions.\n * @example\n * ```ts\n * // Create an error from AST nodes and response metadata.\n * import { parse } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const document = parse('{ greeting }');\n * const fieldNode = document.definitions[0].selectionSet.selections[0];\n * const error = new GraphQLError('Cannot query this field.', {\n * nodes: fieldNode,\n * path: ['greeting'],\n * extensions: { code: 'FORBIDDEN' },\n * });\n *\n * error.message; // => 'Cannot query this field.'\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.extensions; // => { code: 'FORBIDDEN' }\n * ```\n * @example\n * ```ts\n * // This variant derives locations from source positions and preserves the cause.\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const source = new Source('{ greeting }');\n * const cause = new Error('Database unavailable.');\n * const error = new GraphQLError('Resolver failed.', {\n * source,\n * positions: [2],\n * path: ['greeting'],\n * cause,\n * });\n *\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.cause; // => cause\n * ```\n */\n constructor(message: string, options: GraphQLErrorOptions = {}) {\n const { nodes, source, positions, path, originalError, cause, extensions } =\n options;\n\n const hasCause = 'cause' in options;\n const errorCause = hasCause ? cause : originalError;\n const errorOptions =\n hasCause || originalError != null ? { cause: errorCause } : undefined;\n super(message, errorOptions);\n\n this.name = 'GraphQLError';\n this.path = path ?? undefined;\n const underlyingError: typeof originalError =\n originalError ?? (cause instanceof Error ? cause : undefined);\n this.originalError = underlyingError;\n\n // Compute list of blame nodes.\n this.nodes = undefinedIfEmpty(\n Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,\n );\n\n const nodeLocations = undefinedIfEmpty(\n this.nodes\n ?.map((node) => node.loc)\n .filter((loc): loc is Location => loc != null),\n );\n\n // Compute locations in the source for the given nodes/positions.\n this.source = source ?? nodeLocations?.[0]?.source;\n\n this.positions = positions ?? nodeLocations?.map((loc) => loc.start);\n\n this.locations =\n positions && source\n ? positions.map((pos) => getLocation(source, pos))\n : nodeLocations?.map((loc) => getLocation(loc.source, loc.start));\n\n const originalExtensions = isObjectLike(underlyingError?.extensions)\n ? underlyingError.extensions\n : undefined;\n this.extensions = extensions ?? originalExtensions ?? Object.create(null);\n\n // Only properties prescribed by the spec should be enumerable.\n // Keep the rest as non-enumerable.\n Object.defineProperties(this, {\n message: {\n writable: true,\n enumerable: true,\n },\n name: { enumerable: false },\n nodes: { enumerable: false },\n source: { enumerable: false },\n positions: { enumerable: false },\n originalError: { enumerable: false },\n });\n\n // Include (non-enumerable) stack trace.\n // Do not copy over the stack trace of the Error.cause, since the tooling\n // already nicely prints/reports the cause chains.\n // Preserve the copy-over behavior of the `originalError`, since users may\n // expect it to work the way it did originally.\n if (originalError?.stack != null) {\n Object.defineProperty(this, 'stack', {\n value: originalError.stack,\n writable: true,\n configurable: true,\n });\n } else if (Error.captureStackTrace != null) {\n Error.captureStackTrace(this, GraphQLError);\n // See: https://github.com/graphql/graphql-js/issues/2317\n /* node:coverage ignore next 7 */\n } else {\n Object.defineProperty(this, 'stack', {\n value: Error().stack,\n writable: true,\n configurable: true,\n });\n }\n }\n\n /**\n * Returns the value used by `Object.prototype.toString`.\n * @returns The built-in string tag for this object.\n */\n get [Symbol.toStringTag](): string {\n return 'GraphQLError';\n }\n\n /**\n * Returns this error as a human-readable message with source locations.\n * @returns The formatted error string.\n * @example\n * ```ts\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Cannot query field \"name\".', {\n * source: new Source('{ name }'),\n * positions: [2],\n * });\n *\n * error.toString(); // => 'Cannot query field \"name\".\\n\\nGraphQL request:1:3\\n1 | { name }\\n | ^'\n * ```\n */\n override toString(): string {\n let output = this.message;\n\n if (this.nodes) {\n for (const node of this.nodes) {\n if (node.loc) {\n output += '\\n\\n' + printLocation(node.loc);\n }\n }\n } else if (this.source && this.locations) {\n for (const location of this.locations) {\n output += '\\n\\n' + printSourceLocation(this.source, location);\n }\n }\n\n return output;\n }\n\n /**\n * Returns the JSON representation used when this object is serialized.\n * @returns The JSON-serializable representation.\n * @example\n * ```ts\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Resolver failed.', {\n * path: ['viewer', 'name'],\n * extensions: { code: 'INTERNAL' },\n * });\n *\n * error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }\n * ```\n */\n toJSON(): GraphQLFormattedError {\n type WritableFormattedError = {\n -readonly [P in keyof GraphQLFormattedError]: GraphQLFormattedError[P];\n };\n\n const formattedError: WritableFormattedError = {\n message: this.message,\n };\n\n if (this.locations != null) {\n formattedError.locations = this.locations;\n }\n\n if (this.path != null) {\n formattedError.path = this.path;\n }\n\n if (this.extensions != null && Object.keys(this.extensions).length > 0) {\n formattedError.extensions = this.extensions;\n }\n\n return formattedError;\n }\n}\n\nfunction undefinedIfEmpty<T>(\n array: Array<T> | undefined,\n): Array<T> | undefined {\n return array === undefined || array.length === 0 ? undefined : array;\n}\n\n/** See: https://spec.graphql.org/draft/#sec-Errors */\nexport interface GraphQLFormattedError {\n /**\n * A short, human-readable summary of the problem that **SHOULD NOT** change\n * from occurrence to occurrence of the problem, except for purposes of\n * localization.\n */\n readonly message: string;\n /**\n * If an error can be associated to a particular point in the requested\n * GraphQL document, it should contain a list of locations.\n */\n readonly locations?: ReadonlyArray<SourceLocation>;\n /**\n * If an error can be associated to a particular field in the GraphQL result,\n * it _must_ contain an entry with the key `path` that details the path of\n * the response field which experienced the error. This allows clients to\n * identify whether a null result is intentional or caused by a runtime error.\n */\n readonly path?: ReadonlyArray<string | number>;\n /**\n * Reserved for implementors to extend the protocol however they see fit,\n * and hence there are no additional restrictions on its contents.\n */\n readonly extensions?: GraphQLFormattedErrorExtensions;\n}\n"]}
|
package/error/GraphQLError.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export class GraphQLError extends Error {
|
|
|
10
10
|
super(message, errorOptions);
|
|
11
11
|
this.name = 'GraphQLError';
|
|
12
12
|
this.path = path ?? undefined;
|
|
13
|
-
const underlyingError = originalError ?? (
|
|
13
|
+
const underlyingError = originalError ?? (cause instanceof Error ? cause : undefined);
|
|
14
14
|
this.originalError = underlyingError;
|
|
15
15
|
this.nodes = undefinedIfEmpty(Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined);
|
|
16
16
|
const nodeLocations = undefinedIfEmpty(this.nodes
|
|
@@ -37,9 +37,9 @@ export class GraphQLError extends Error {
|
|
|
37
37
|
positions: { enumerable: false },
|
|
38
38
|
originalError: { enumerable: false },
|
|
39
39
|
});
|
|
40
|
-
if (
|
|
40
|
+
if (originalError?.stack != null) {
|
|
41
41
|
Object.defineProperty(this, 'stack', {
|
|
42
|
-
value:
|
|
42
|
+
value: originalError.stack,
|
|
43
43
|
writable: true,
|
|
44
44
|
configurable: true,
|
|
45
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphQLError.js","sourceR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C;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAiBD,MAAM;QAKJ,MAAM,cAAc,GAA2B;YAC7C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC3B,cAAc,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAClC,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvE,cAAc,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAC9C,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,KAA2B;IAE3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACvE,CAAC","sourcesContent":["/** @category Errors */\n\nimport { isObjectLike } from '../jsutils/isObjectLike.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport type { ASTNode, Location } from '../language/ast.ts';\nimport type { SourceLocation } from '../language/location.ts';\nimport { getLocation } from '../language/location.ts';\nimport {\n printLocation,\n printSourceLocation,\n} from '../language/printLocation.ts';\nimport type { Source } from '../language/source.ts';\n\n/**\n * Custom extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/**\n * Custom formatted extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLFormattedErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/** Options used to construct a GraphQLError. */\nexport interface GraphQLErrorOptions {\n /** AST node or nodes associated with this error. */\n nodes?: ReadonlyArray<ASTNode> | ASTNode | null | undefined;\n /** Source document used to derive error locations. */\n source?: Maybe<Source>;\n /** Character offsets in the source document associated with this error. */\n positions?: Maybe<ReadonlyArray<number>>;\n /** Response path where this error occurred during execution. */\n path?: Maybe<ReadonlyArray<string | number>>;\n /**\n * Original error that caused this GraphQLError, if one exists.\n * @deprecated Prefer `cause` instead.\n */\n originalError?: Maybe<Error & { readonly extensions?: unknown }>;\n /** Cause of this GraphQLError, if one exists. */\n cause?: unknown;\n /** Extension fields to include in the formatted result. */\n extensions?: Maybe<GraphQLErrorExtensions>;\n}\n\n/**\n * A GraphQLError describes an Error found during the parse, validate, or\n * execute phases of performing a GraphQL operation. In addition to a message\n * and stack trace, it also includes information about the locations in a\n * GraphQL document and/or execution result that correspond to the Error.\n */\nexport class GraphQLError extends Error {\n /**\n * An array of `{ line, column }` locations within the source GraphQL document\n * which correspond to this error.\n *\n * Errors during validation often contain multiple locations, for example to\n * point out two things with the same name. Errors during execution include a\n * single location, the field which produced the error.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly locations: ReadonlyArray<SourceLocation> | undefined;\n\n /**\n * An array describing the JSON-path into the execution response which\n * corresponds to this error. Only included for errors during execution.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly path: ReadonlyArray<string | number> | undefined;\n\n /** An array of GraphQL AST Nodes corresponding to this error. */\n readonly nodes: ReadonlyArray<ASTNode> | undefined;\n\n /**\n * The source GraphQL document for the first location of this error.\n *\n * Note that if this Error represents more than one node, the source may not\n * represent nodes after the first node.\n */\n readonly source: Source | undefined;\n\n /**\n * An array of character offsets within the source GraphQL document\n * which correspond to this error.\n */\n readonly positions: ReadonlyArray<number> | undefined;\n\n /**\n * The original error thrown from a field resolver during execution.\n * @deprecated Use `cause` instead.\n */\n readonly originalError: Error | undefined;\n\n /** Extension fields to add to the formatted error. */\n readonly extensions: GraphQLErrorExtensions;\n\n /**\n * Creates a GraphQLError instance.\n * @param message - Human-readable error message.\n * @param options - Error metadata such as source locations, response path, cause, original error, and extensions.\n * @example\n * ```ts\n * // Create an error from AST nodes and response metadata.\n * import { parse } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const document = parse('{ greeting }');\n * const fieldNode = document.definitions[0].selectionSet.selections[0];\n * const error = new GraphQLError('Cannot query this field.', {\n * nodes: fieldNode,\n * path: ['greeting'],\n * extensions: { code: 'FORBIDDEN' },\n * });\n *\n * error.message; // => 'Cannot query this field.'\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.extensions; // => { code: 'FORBIDDEN' }\n * ```\n * @example\n * ```ts\n * // This variant derives locations from source positions and preserves the cause.\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const source = new Source('{ greeting }');\n * const cause = new Error('Database unavailable.');\n * const error = new GraphQLError('Resolver failed.', {\n * source,\n * positions: [2],\n * path: ['greeting'],\n * cause,\n * });\n *\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.cause; // => cause\n * ```\n */\n constructor(message: string, options: GraphQLErrorOptions = {}) {\n const { nodes, source, positions, path, originalError, cause, extensions } =\n options;\n\n const hasCause = 'cause' in options;\n const errorCause = hasCause ? cause : originalError;\n const errorOptions =\n hasCause || originalError != null ? { cause: errorCause } : undefined;\n super(message, errorOptions);\n\n this.name = 'GraphQLError';\n this.path = path ?? undefined;\n const underlyingError:\n | (Error & { readonly extensions?: unknown })\n | undefined =\n originalError ?? (errorCause instanceof Error ? errorCause : undefined);\n this.originalError = underlyingError;\n\n // Compute list of blame nodes.\n this.nodes = undefinedIfEmpty(\n Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,\n );\n\n const nodeLocations = undefinedIfEmpty(\n this.nodes\n ?.map((node) => node.loc)\n .filter((loc): loc is Location => loc != null),\n );\n\n // Compute locations in the source for the given nodes/positions.\n this.source = source ?? nodeLocations?.[0]?.source;\n\n this.positions = positions ?? nodeLocations?.map((loc) => loc.start);\n\n this.locations =\n positions && source\n ? positions.map((pos) => getLocation(source, pos))\n : nodeLocations?.map((loc) => getLocation(loc.source, loc.start));\n\n const originalExtensions = isObjectLike(underlyingError?.extensions)\n ? underlyingError.extensions\n : undefined;\n this.extensions = extensions ?? originalExtensions ?? Object.create(null);\n\n // Only properties prescribed by the spec should be enumerable.\n // Keep the rest as non-enumerable.\n Object.defineProperties(this, {\n message: {\n writable: true,\n enumerable: true,\n },\n name: { enumerable: false },\n nodes: { enumerable: false },\n source: { enumerable: false },\n positions: { enumerable: false },\n originalError: { enumerable: false },\n });\n\n // Include (non-enumerable) stack trace.\n if (underlyingError?.stack != null) {\n Object.defineProperty(this, 'stack', {\n value: underlyingError.stack,\n writable: true,\n configurable: true,\n });\n } else if (Error.captureStackTrace != null) {\n Error.captureStackTrace(this, GraphQLError);\n // See: https://github.com/graphql/graphql-js/issues/2317\n /* node:coverage ignore next 7 */\n } else {\n Object.defineProperty(this, 'stack', {\n value: Error().stack,\n writable: true,\n configurable: true,\n });\n }\n }\n\n /**\n * Returns the value used by `Object.prototype.toString`.\n * @returns The built-in string tag for this object.\n */\n get [Symbol.toStringTag](): string {\n return 'GraphQLError';\n }\n\n /**\n * Returns this error as a human-readable message with source locations.\n * @returns The formatted error string.\n * @example\n * ```ts\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Cannot query field \"name\".', {\n * source: new Source('{ name }'),\n * positions: [2],\n * });\n *\n * error.toString(); // => 'Cannot query field \"name\".\\n\\nGraphQL request:1:3\\n1 | { name }\\n | ^'\n * ```\n */\n override toString(): string {\n let output = this.message;\n\n if (this.nodes) {\n for (const node of this.nodes) {\n if (node.loc) {\n output += '\\n\\n' + printLocation(node.loc);\n }\n }\n } else if (this.source && this.locations) {\n for (const location of this.locations) {\n output += '\\n\\n' + printSourceLocation(this.source, location);\n }\n }\n\n return output;\n }\n\n /**\n * Returns the JSON representation used when this object is serialized.\n * @returns The JSON-serializable representation.\n * @example\n * ```ts\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Resolver failed.', {\n * path: ['viewer', 'name'],\n * extensions: { code: 'INTERNAL' },\n * });\n *\n * error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }\n * ```\n */\n toJSON(): GraphQLFormattedError {\n type WritableFormattedError = {\n -readonly [P in keyof GraphQLFormattedError]: GraphQLFormattedError[P];\n };\n\n const formattedError: WritableFormattedError = {\n message: this.message,\n };\n\n if (this.locations != null) {\n formattedError.locations = this.locations;\n }\n\n if (this.path != null) {\n formattedError.path = this.path;\n }\n\n if (this.extensions != null && Object.keys(this.extensions).length > 0) {\n formattedError.extensions = this.extensions;\n }\n\n return formattedError;\n }\n}\n\nfunction undefinedIfEmpty<T>(\n array: Array<T> | undefined,\n): Array<T> | undefined {\n return array === undefined || array.length === 0 ? undefined : array;\n}\n\n/** See: https://spec.graphql.org/draft/#sec-Errors */\nexport interface GraphQLFormattedError {\n /**\n * A short, human-readable summary of the problem that **SHOULD NOT** change\n * from occurrence to occurrence of the problem, except for purposes of\n * localization.\n */\n readonly message: string;\n /**\n * If an error can be associated to a particular point in the requested\n * GraphQL document, it should contain a list of locations.\n */\n readonly locations?: ReadonlyArray<SourceLocation>;\n /**\n * If an error can be associated to a particular field in the GraphQL result,\n * it _must_ contain an entry with the key `path` that details the path of\n * the response field which experienced the error. This allows clients to\n * identify whether a null result is intentional or caused by a runtime error.\n */\n readonly path?: ReadonlyArray<string | number>;\n /**\n * Reserved for implementors to extend the protocol however they see fit,\n * and hence there are no additional restrictions on its contents.\n */\n readonly extensions?: GraphQLFormattedErrorExtensions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GraphQLError.js","sourceRoot":"","sources":["../../src/error/GraphQLError.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,oCAAmC;AAK1D,OAAO,EAAE,WAAW,EAAE,iCAAgC;AACtD,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,sCAAqC;AAuDtC,MAAM,OAAO,YAAa,SAAQ,KAAK;IA2FrC,YAAY,OAAe,EAAE,UAA+B,EAAE;QAC5D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GACxE,OAAO,CAAC;QAEV,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC;QACpC,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;QACpD,MAAM,YAAY,GAChB,QAAQ,IAAI,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAE7B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,SAAS,CAAC;QAC9B,MAAM,eAAe,GACnB,aAAa,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,aAAa,GAAG,eAAe,CAAC;QAGrC,IAAI,CAAC,KAAK,GAAG,gBAAgB,CAC3B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CA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tC,MAAM,IAAI,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAiBD,MAAM;QAKJ,MAAM,cAAc,GAA2B;YAC7C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YAC3B,cAAc,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAClC,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvE,cAAc,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAC9C,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,KAA2B;IAE3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACvE,CAAC","sourcesContent":["/** @category Errors */\n\nimport { isObjectLike } from '../jsutils/isObjectLike.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport type { ASTNode, Location } from '../language/ast.ts';\nimport type { SourceLocation } from '../language/location.ts';\nimport { getLocation } from '../language/location.ts';\nimport {\n printLocation,\n printSourceLocation,\n} from '../language/printLocation.ts';\nimport type { Source } from '../language/source.ts';\n\n/**\n * Custom extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/**\n * Custom formatted extensions\n * @remarks\n * Use a unique identifier name for your extension, for example the name of\n * your library or project. Do not use a shortened identifier as this increases\n * the risk of conflicts. We recommend you add at most one extension field,\n * an object which can contain all the values you need.\n */\nexport interface GraphQLFormattedErrorExtensions {\n [attributeName: string]: unknown;\n}\n\n/** Options used to construct a GraphQLError. */\nexport interface GraphQLErrorOptions {\n /** AST node or nodes associated with this error. */\n nodes?: ReadonlyArray<ASTNode> | ASTNode | null | undefined;\n /** Source document used to derive error locations. */\n source?: Maybe<Source>;\n /** Character offsets in the source document associated with this error. */\n positions?: Maybe<ReadonlyArray<number>>;\n /** Response path where this error occurred during execution. */\n path?: Maybe<ReadonlyArray<string | number>>;\n /**\n * Original error that caused this GraphQLError, if one exists.\n * Deprecated in favor of `cause` to better align with JavaScript standards.\n * @deprecated Prefer `cause` instead.\n */\n originalError?: Maybe<Error & { readonly extensions?: unknown }>;\n /** Cause of this GraphQLError, if one exists. */\n cause?: unknown;\n /** Extension fields to include in the formatted result. */\n extensions?: Maybe<GraphQLErrorExtensions>;\n}\n\n/**\n * A GraphQLError describes an Error found during the parse, validate, or\n * execute phases of performing a GraphQL operation. In addition to a message\n * and stack trace, it also includes information about the locations in a\n * GraphQL document and/or execution result that correspond to the Error.\n */\nexport class GraphQLError extends Error {\n /**\n * An array of `{ line, column }` locations within the source GraphQL document\n * which correspond to this error.\n *\n * Errors during validation often contain multiple locations, for example to\n * point out two things with the same name. Errors during execution include a\n * single location, the field which produced the error.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly locations: ReadonlyArray<SourceLocation> | undefined;\n\n /**\n * An array describing the JSON-path into the execution response which\n * corresponds to this error. Only included for errors during execution.\n *\n * Enumerable, and appears in the result of JSON.stringify().\n */\n readonly path: ReadonlyArray<string | number> | undefined;\n\n /** An array of GraphQL AST Nodes corresponding to this error. */\n readonly nodes: ReadonlyArray<ASTNode> | undefined;\n\n /**\n * The source GraphQL document for the first location of this error.\n *\n * Note that if this Error represents more than one node, the source may not\n * represent nodes after the first node.\n */\n readonly source: Source | undefined;\n\n /**\n * An array of character offsets within the source GraphQL document\n * which correspond to this error.\n */\n readonly positions: ReadonlyArray<number> | undefined;\n\n /**\n * Original error that caused this GraphQLError, if one exists.\n * Deprecated in favor of `cause` to better align with JavaScript standards.\n * @deprecated Use `cause` instead.\n */\n readonly originalError: Error | undefined;\n\n /** Extension fields to add to the formatted error. */\n readonly extensions: GraphQLErrorExtensions;\n\n /**\n * Creates a GraphQLError instance.\n * @param message - Human-readable error message.\n * @param options - Error metadata such as source locations, response path, cause, original error, and extensions.\n * @example\n * ```ts\n * // Create an error from AST nodes and response metadata.\n * import { parse } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const document = parse('{ greeting }');\n * const fieldNode = document.definitions[0].selectionSet.selections[0];\n * const error = new GraphQLError('Cannot query this field.', {\n * nodes: fieldNode,\n * path: ['greeting'],\n * extensions: { code: 'FORBIDDEN' },\n * });\n *\n * error.message; // => 'Cannot query this field.'\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.extensions; // => { code: 'FORBIDDEN' }\n * ```\n * @example\n * ```ts\n * // This variant derives locations from source positions and preserves the cause.\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const source = new Source('{ greeting }');\n * const cause = new Error('Database unavailable.');\n * const error = new GraphQLError('Resolver failed.', {\n * source,\n * positions: [2],\n * path: ['greeting'],\n * cause,\n * });\n *\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['greeting']\n * error.cause; // => cause\n * ```\n */\n constructor(message: string, options: GraphQLErrorOptions = {}) {\n const { nodes, source, positions, path, originalError, cause, extensions } =\n options;\n\n const hasCause = 'cause' in options;\n const errorCause = hasCause ? cause : originalError;\n const errorOptions =\n hasCause || originalError != null ? { cause: errorCause } : undefined;\n super(message, errorOptions);\n\n this.name = 'GraphQLError';\n this.path = path ?? undefined;\n const underlyingError: typeof originalError =\n originalError ?? (cause instanceof Error ? cause : undefined);\n this.originalError = underlyingError;\n\n // Compute list of blame nodes.\n this.nodes = undefinedIfEmpty(\n Array.isArray(nodes) ? nodes : nodes ? [nodes] : undefined,\n );\n\n const nodeLocations = undefinedIfEmpty(\n this.nodes\n ?.map((node) => node.loc)\n .filter((loc): loc is Location => loc != null),\n );\n\n // Compute locations in the source for the given nodes/positions.\n this.source = source ?? nodeLocations?.[0]?.source;\n\n this.positions = positions ?? nodeLocations?.map((loc) => loc.start);\n\n this.locations =\n positions && source\n ? positions.map((pos) => getLocation(source, pos))\n : nodeLocations?.map((loc) => getLocation(loc.source, loc.start));\n\n const originalExtensions = isObjectLike(underlyingError?.extensions)\n ? underlyingError.extensions\n : undefined;\n this.extensions = extensions ?? originalExtensions ?? Object.create(null);\n\n // Only properties prescribed by the spec should be enumerable.\n // Keep the rest as non-enumerable.\n Object.defineProperties(this, {\n message: {\n writable: true,\n enumerable: true,\n },\n name: { enumerable: false },\n nodes: { enumerable: false },\n source: { enumerable: false },\n positions: { enumerable: false },\n originalError: { enumerable: false },\n });\n\n // Include (non-enumerable) stack trace.\n // Do not copy over the stack trace of the Error.cause, since the tooling\n // already nicely prints/reports the cause chains.\n // Preserve the copy-over behavior of the `originalError`, since users may\n // expect it to work the way it did originally.\n if (originalError?.stack != null) {\n Object.defineProperty(this, 'stack', {\n value: originalError.stack,\n writable: true,\n configurable: true,\n });\n } else if (Error.captureStackTrace != null) {\n Error.captureStackTrace(this, GraphQLError);\n // See: https://github.com/graphql/graphql-js/issues/2317\n /* node:coverage ignore next 7 */\n } else {\n Object.defineProperty(this, 'stack', {\n value: Error().stack,\n writable: true,\n configurable: true,\n });\n }\n }\n\n /**\n * Returns the value used by `Object.prototype.toString`.\n * @returns The built-in string tag for this object.\n */\n get [Symbol.toStringTag](): string {\n return 'GraphQLError';\n }\n\n /**\n * Returns this error as a human-readable message with source locations.\n * @returns The formatted error string.\n * @example\n * ```ts\n * import { Source } from 'graphql/language';\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Cannot query field \"name\".', {\n * source: new Source('{ name }'),\n * positions: [2],\n * });\n *\n * error.toString(); // => 'Cannot query field \"name\".\\n\\nGraphQL request:1:3\\n1 | { name }\\n | ^'\n * ```\n */\n override toString(): string {\n let output = this.message;\n\n if (this.nodes) {\n for (const node of this.nodes) {\n if (node.loc) {\n output += '\\n\\n' + printLocation(node.loc);\n }\n }\n } else if (this.source && this.locations) {\n for (const location of this.locations) {\n output += '\\n\\n' + printSourceLocation(this.source, location);\n }\n }\n\n return output;\n }\n\n /**\n * Returns the JSON representation used when this object is serialized.\n * @returns The JSON-serializable representation.\n * @example\n * ```ts\n * import { GraphQLError } from 'graphql/error';\n *\n * const error = new GraphQLError('Resolver failed.', {\n * path: ['viewer', 'name'],\n * extensions: { code: 'INTERNAL' },\n * });\n *\n * error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }\n * ```\n */\n toJSON(): GraphQLFormattedError {\n type WritableFormattedError = {\n -readonly [P in keyof GraphQLFormattedError]: GraphQLFormattedError[P];\n };\n\n const formattedError: WritableFormattedError = {\n message: this.message,\n };\n\n if (this.locations != null) {\n formattedError.locations = this.locations;\n }\n\n if (this.path != null) {\n formattedError.path = this.path;\n }\n\n if (this.extensions != null && Object.keys(this.extensions).length > 0) {\n formattedError.extensions = this.extensions;\n }\n\n return formattedError;\n }\n}\n\nfunction undefinedIfEmpty<T>(\n array: Array<T> | undefined,\n): Array<T> | undefined {\n return array === undefined || array.length === 0 ? undefined : array;\n}\n\n/** See: https://spec.graphql.org/draft/#sec-Errors */\nexport interface GraphQLFormattedError {\n /**\n * A short, human-readable summary of the problem that **SHOULD NOT** change\n * from occurrence to occurrence of the problem, except for purposes of\n * localization.\n */\n readonly message: string;\n /**\n * If an error can be associated to a particular point in the requested\n * GraphQL document, it should contain a list of locations.\n */\n readonly locations?: ReadonlyArray<SourceLocation>;\n /**\n * If an error can be associated to a particular field in the GraphQL result,\n * it _must_ contain an entry with the key `path` that details the path of\n * the response field which experienced the error. This allows clients to\n * identify whether a null result is intentional or caused by a runtime error.\n */\n readonly path?: ReadonlyArray<string | number>;\n /**\n * Reserved for implementors to extend the protocol however they see fit,\n * and hence there are no additional restrictions on its contents.\n */\n readonly extensions?: GraphQLFormattedErrorExtensions;\n}\n"]}
|
|
@@ -55,6 +55,8 @@ export interface ExecutionArgs {
|
|
|
55
55
|
export interface ValidatedExecutionArgs {
|
|
56
56
|
/** Schema used for execution. */
|
|
57
57
|
schema: GraphQLSchema;
|
|
58
|
+
/** Parsed GraphQL document being executed. */
|
|
59
|
+
document: DocumentNode;
|
|
58
60
|
/** Fragment definitions keyed by fragment name. */
|
|
59
61
|
fragmentDefinitions: ObjMap<FragmentDefinitionNode>;
|
|
60
62
|
/** Fragment details keyed by fragment name. */
|
|
@@ -67,6 +69,10 @@ export interface ValidatedExecutionArgs {
|
|
|
67
69
|
operation: OperationDefinitionNode;
|
|
68
70
|
/** Operation variable values with source metadata and coerced runtime values. */
|
|
69
71
|
variableValues: VariableValues;
|
|
72
|
+
/** Raw variable values provided by the caller before coercion. */
|
|
73
|
+
rawVariableValues: Maybe<{
|
|
74
|
+
readonly [variable: string]: unknown;
|
|
75
|
+
}>;
|
|
70
76
|
/** Resolver used for fields without an explicit resolver. */
|
|
71
77
|
fieldResolver: GraphQLFieldResolver<any, any>;
|
|
72
78
|
/** Resolver used for abstract types without an explicit type resolver. */
|
|
@@ -55,6 +55,8 @@ export interface ExecutionArgs {
|
|
|
55
55
|
export interface ValidatedExecutionArgs {
|
|
56
56
|
/** Schema used for execution. */
|
|
57
57
|
schema: GraphQLSchema;
|
|
58
|
+
/** Parsed GraphQL document being executed. */
|
|
59
|
+
document: DocumentNode;
|
|
58
60
|
/** Fragment definitions keyed by fragment name. */
|
|
59
61
|
fragmentDefinitions: ObjMap<FragmentDefinitionNode>;
|
|
60
62
|
/** Fragment details keyed by fragment name. */
|
|
@@ -67,6 +69,10 @@ export interface ValidatedExecutionArgs {
|
|
|
67
69
|
operation: OperationDefinitionNode;
|
|
68
70
|
/** Operation variable values with source metadata and coerced runtime values. */
|
|
69
71
|
variableValues: VariableValues;
|
|
72
|
+
/** Raw variable values provided by the caller before coercion. */
|
|
73
|
+
rawVariableValues: Maybe<{
|
|
74
|
+
readonly [variable: string]: unknown;
|
|
75
|
+
}>;
|
|
70
76
|
/** Resolver used for fields without an explicit resolver. */
|
|
71
77
|
fieldResolver: GraphQLFieldResolver<any, any>;
|
|
72
78
|
/** Resolver used for abstract types without an explicit type resolver. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionArgs.js","sourceRoot":"","sources":["../../src/execution/ExecutionArgs.ts"],"names":[],"mappings":"","sourcesContent":["/** @category Execution */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport type { ObjMap } from '../jsutils/ObjMap.ts';\n\nimport type {\n DocumentNode,\n FragmentDefinitionNode,\n OperationDefinitionNode,\n SubscriptionOperationDefinitionNode,\n} from '../language/ast.ts';\n\nimport type {\n GraphQLFieldResolver,\n GraphQLTypeResolver,\n} from '../type/definition.ts';\nimport type { GraphQLSchema } from '../type/schema.ts';\n\nimport type { FragmentDetails } from './collectFields.ts';\nimport type { VariableValues } from './values.ts';\n\n/** Arguments accepted by execute and executeSync. */\nexport interface ExecutionArgs {\n /** The schema used for validation or execution. */\n schema: GraphQLSchema;\n /** The parsed GraphQL document to execute. */\n document: DocumentNode;\n /** Initial root value passed to the operation. */\n rootValue?: unknown;\n /** Application context value passed to every resolver. */\n contextValue?: unknown;\n /** Runtime variable values keyed by variable name. */\n variableValues?: Maybe<{ readonly [variable: string]: unknown }>;\n /** Name of the operation to execute when the document contains multiple operations. */\n operationName?: Maybe<string>;\n /** Resolver used when a field does not define its own resolver. */\n fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Resolver used when an abstract type does not define its own resolver. */\n typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;\n /** Resolver used for the root subscription field. */\n subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Whether suggestion text should be omitted from request errors. */\n hideSuggestions?: Maybe<boolean>;\n /** AbortSignal used to cancel execution. */\n abortSignal?: Maybe<AbortSignal>;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution?: Maybe<boolean>;\n /** Execution hooks invoked during this operation. */\n hooks?: Maybe<ExecutionHooks>;\n /** Additional execution options. */\n options?: {\n /**\n * Set the maximum number of errors allowed for coercing (defaults to 50).\n *\n * @internal\n */\n maxCoercionErrors?: number;\n };\n}\n\n/**\n * Data that must be available at all points during query execution.\n *\n * Namely, schema of the type system that is currently executing,\n * and the fragments defined in the query document\n */\nexport interface ValidatedExecutionArgs {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n // TODO: consider deprecating/removing fragmentDefinitions if/when fragment\n // arguments are officially supported and/or the full fragment details are\n // exposed within GraphQLResolveInfo.\n /** Fragment definitions keyed by fragment name. */\n fragmentDefinitions: ObjMap<FragmentDefinitionNode>;\n /** Fragment details keyed by fragment name. */\n fragments: ObjMap<FragmentDetails>;\n /** Root value passed to the operation. */\n rootValue: unknown;\n /** Application context value passed to every resolver. */\n contextValue: unknown;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Operation variable values with source metadata and coerced runtime values. */\n variableValues: VariableValues;\n /** Resolver used for fields without an explicit resolver. */\n fieldResolver: GraphQLFieldResolver<any, any>;\n /** Resolver used for abstract types without an explicit type resolver. */\n typeResolver: GraphQLTypeResolver<any, any>;\n /** Resolver used for subscription fields without an explicit subscribe resolver. */\n subscribeFieldResolver: GraphQLFieldResolver<any, any>;\n /** Whether suggestion text should be omitted from execution errors. */\n hideSuggestions: boolean;\n /** Whether execution should use error propagation. */\n errorPropagation: boolean;\n /** External signal that may abort execution. */\n externalAbortSignal: AbortSignal | undefined;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution: boolean;\n /** Execution hooks supplied by the caller. */\n hooks: ExecutionHooks | undefined;\n}\n\n/** Validated execution arguments for a subscription operation. */\nexport interface ValidatedSubscriptionArgs extends ValidatedExecutionArgs {\n /** Subscription operation definition selected for execution. */\n operation: SubscriptionOperationDefinitionNode;\n}\n\n/** Information passed to hooks after asynchronous execution work has finished. */\nexport interface AsyncWorkFinishedInfo {\n /** Validated execution arguments for the operation that finished async work. */\n validatedExecutionArgs: ValidatedExecutionArgs;\n}\n\n/** Optional hooks invoked during GraphQL execution. */\nexport interface ExecutionHooks {\n /** Called after all tracked asynchronous execution work has settled. */\n asyncWorkFinished?: (info: AsyncWorkFinishedInfo) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExecutionArgs.js","sourceRoot":"","sources":["../../src/execution/ExecutionArgs.ts"],"names":[],"mappings":"","sourcesContent":["/** @category Execution */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport type { ObjMap } from '../jsutils/ObjMap.ts';\n\nimport type {\n DocumentNode,\n FragmentDefinitionNode,\n OperationDefinitionNode,\n SubscriptionOperationDefinitionNode,\n} from '../language/ast.ts';\n\nimport type {\n GraphQLFieldResolver,\n GraphQLTypeResolver,\n} from '../type/definition.ts';\nimport type { GraphQLSchema } from '../type/schema.ts';\n\nimport type { FragmentDetails } from './collectFields.ts';\nimport type { VariableValues } from './values.ts';\n\n/** Arguments accepted by execute and executeSync. */\nexport interface ExecutionArgs {\n /** The schema used for validation or execution. */\n schema: GraphQLSchema;\n /** The parsed GraphQL document to execute. */\n document: DocumentNode;\n /** Initial root value passed to the operation. */\n rootValue?: unknown;\n /** Application context value passed to every resolver. */\n contextValue?: unknown;\n /** Runtime variable values keyed by variable name. */\n variableValues?: Maybe<{ readonly [variable: string]: unknown }>;\n /** Name of the operation to execute when the document contains multiple operations. */\n operationName?: Maybe<string>;\n /** Resolver used when a field does not define its own resolver. */\n fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Resolver used when an abstract type does not define its own resolver. */\n typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;\n /** Resolver used for the root subscription field. */\n subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Whether suggestion text should be omitted from request errors. */\n hideSuggestions?: Maybe<boolean>;\n /** AbortSignal used to cancel execution. */\n abortSignal?: Maybe<AbortSignal>;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution?: Maybe<boolean>;\n /** Execution hooks invoked during this operation. */\n hooks?: Maybe<ExecutionHooks>;\n /** Additional execution options. */\n options?: {\n /**\n * Set the maximum number of errors allowed for coercing (defaults to 50).\n *\n * @internal\n */\n maxCoercionErrors?: number;\n };\n}\n\n/**\n * Data that must be available at all points during query execution.\n *\n * Namely, schema of the type system that is currently executing,\n * and the fragments defined in the query document\n */\nexport interface ValidatedExecutionArgs {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed GraphQL document being executed. */\n document: DocumentNode;\n // TODO: consider deprecating/removing fragmentDefinitions if/when fragment\n // arguments are officially supported and/or the full fragment details are\n // exposed within GraphQLResolveInfo.\n /** Fragment definitions keyed by fragment name. */\n fragmentDefinitions: ObjMap<FragmentDefinitionNode>;\n /** Fragment details keyed by fragment name. */\n fragments: ObjMap<FragmentDetails>;\n /** Root value passed to the operation. */\n rootValue: unknown;\n /** Application context value passed to every resolver. */\n contextValue: unknown;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Operation variable values with source metadata and coerced runtime values. */\n variableValues: VariableValues;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Resolver used for fields without an explicit resolver. */\n fieldResolver: GraphQLFieldResolver<any, any>;\n /** Resolver used for abstract types without an explicit type resolver. */\n typeResolver: GraphQLTypeResolver<any, any>;\n /** Resolver used for subscription fields without an explicit subscribe resolver. */\n subscribeFieldResolver: GraphQLFieldResolver<any, any>;\n /** Whether suggestion text should be omitted from execution errors. */\n hideSuggestions: boolean;\n /** Whether execution should use error propagation. */\n errorPropagation: boolean;\n /** External signal that may abort execution. */\n externalAbortSignal: AbortSignal | undefined;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution: boolean;\n /** Execution hooks supplied by the caller. */\n hooks: ExecutionHooks | undefined;\n}\n\n/** Validated execution arguments for a subscription operation. */\nexport interface ValidatedSubscriptionArgs extends ValidatedExecutionArgs {\n /** Subscription operation definition selected for execution. */\n operation: SubscriptionOperationDefinitionNode;\n}\n\n/** Information passed to hooks after asynchronous execution work has finished. */\nexport interface AsyncWorkFinishedInfo {\n /** Validated execution arguments for the operation that finished async work. */\n validatedExecutionArgs: ValidatedExecutionArgs;\n}\n\n/** Optional hooks invoked during GraphQL execution. */\nexport interface ExecutionHooks {\n /** Called after all tracked asynchronous execution work has settled. */\n asyncWorkFinished?: (info: AsyncWorkFinishedInfo) => void;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionArgs.js","sourceRoot":"","sources":["../../src/execution/ExecutionArgs.ts"],"names":[],"mappings":"","sourcesContent":["/** @category Execution */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport type { ObjMap } from '../jsutils/ObjMap.ts';\n\nimport type {\n DocumentNode,\n FragmentDefinitionNode,\n OperationDefinitionNode,\n SubscriptionOperationDefinitionNode,\n} from '../language/ast.ts';\n\nimport type {\n GraphQLFieldResolver,\n GraphQLTypeResolver,\n} from '../type/definition.ts';\nimport type { GraphQLSchema } from '../type/schema.ts';\n\nimport type { FragmentDetails } from './collectFields.ts';\nimport type { VariableValues } from './values.ts';\n\n/** Arguments accepted by execute and executeSync. */\nexport interface ExecutionArgs {\n /** The schema used for validation or execution. */\n schema: GraphQLSchema;\n /** The parsed GraphQL document to execute. */\n document: DocumentNode;\n /** Initial root value passed to the operation. */\n rootValue?: unknown;\n /** Application context value passed to every resolver. */\n contextValue?: unknown;\n /** Runtime variable values keyed by variable name. */\n variableValues?: Maybe<{ readonly [variable: string]: unknown }>;\n /** Name of the operation to execute when the document contains multiple operations. */\n operationName?: Maybe<string>;\n /** Resolver used when a field does not define its own resolver. */\n fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Resolver used when an abstract type does not define its own resolver. */\n typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;\n /** Resolver used for the root subscription field. */\n subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Whether suggestion text should be omitted from request errors. */\n hideSuggestions?: Maybe<boolean>;\n /** AbortSignal used to cancel execution. */\n abortSignal?: Maybe<AbortSignal>;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution?: Maybe<boolean>;\n /** Execution hooks invoked during this operation. */\n hooks?: Maybe<ExecutionHooks>;\n /** Additional execution options. */\n options?: {\n /**\n * Set the maximum number of errors allowed for coercing (defaults to 50).\n *\n * @internal\n */\n maxCoercionErrors?: number;\n };\n}\n\n/**\n * Data that must be available at all points during query execution.\n *\n * Namely, schema of the type system that is currently executing,\n * and the fragments defined in the query document\n */\nexport interface ValidatedExecutionArgs {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n // TODO: consider deprecating/removing fragmentDefinitions if/when fragment\n // arguments are officially supported and/or the full fragment details are\n // exposed within GraphQLResolveInfo.\n /** Fragment definitions keyed by fragment name. */\n fragmentDefinitions: ObjMap<FragmentDefinitionNode>;\n /** Fragment details keyed by fragment name. */\n fragments: ObjMap<FragmentDetails>;\n /** Root value passed to the operation. */\n rootValue: unknown;\n /** Application context value passed to every resolver. */\n contextValue: unknown;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Operation variable values with source metadata and coerced runtime values. */\n variableValues: VariableValues;\n /** Resolver used for fields without an explicit resolver. */\n fieldResolver: GraphQLFieldResolver<any, any>;\n /** Resolver used for abstract types without an explicit type resolver. */\n typeResolver: GraphQLTypeResolver<any, any>;\n /** Resolver used for subscription fields without an explicit subscribe resolver. */\n subscribeFieldResolver: GraphQLFieldResolver<any, any>;\n /** Whether suggestion text should be omitted from execution errors. */\n hideSuggestions: boolean;\n /** Whether execution should use error propagation. */\n errorPropagation: boolean;\n /** External signal that may abort execution. */\n externalAbortSignal: AbortSignal | undefined;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution: boolean;\n /** Execution hooks supplied by the caller. */\n hooks: ExecutionHooks | undefined;\n}\n\n/** Validated execution arguments for a subscription operation. */\nexport interface ValidatedSubscriptionArgs extends ValidatedExecutionArgs {\n /** Subscription operation definition selected for execution. */\n operation: SubscriptionOperationDefinitionNode;\n}\n\n/** Information passed to hooks after asynchronous execution work has finished. */\nexport interface AsyncWorkFinishedInfo {\n /** Validated execution arguments for the operation that finished async work. */\n validatedExecutionArgs: ValidatedExecutionArgs;\n}\n\n/** Optional hooks invoked during GraphQL execution. */\nexport interface ExecutionHooks {\n /** Called after all tracked asynchronous execution work has settled. */\n asyncWorkFinished?: (info: AsyncWorkFinishedInfo) => void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExecutionArgs.js","sourceRoot":"","sources":["../../src/execution/ExecutionArgs.ts"],"names":[],"mappings":"","sourcesContent":["/** @category Execution */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport type { ObjMap } from '../jsutils/ObjMap.ts';\n\nimport type {\n DocumentNode,\n FragmentDefinitionNode,\n OperationDefinitionNode,\n SubscriptionOperationDefinitionNode,\n} from '../language/ast.ts';\n\nimport type {\n GraphQLFieldResolver,\n GraphQLTypeResolver,\n} from '../type/definition.ts';\nimport type { GraphQLSchema } from '../type/schema.ts';\n\nimport type { FragmentDetails } from './collectFields.ts';\nimport type { VariableValues } from './values.ts';\n\n/** Arguments accepted by execute and executeSync. */\nexport interface ExecutionArgs {\n /** The schema used for validation or execution. */\n schema: GraphQLSchema;\n /** The parsed GraphQL document to execute. */\n document: DocumentNode;\n /** Initial root value passed to the operation. */\n rootValue?: unknown;\n /** Application context value passed to every resolver. */\n contextValue?: unknown;\n /** Runtime variable values keyed by variable name. */\n variableValues?: Maybe<{ readonly [variable: string]: unknown }>;\n /** Name of the operation to execute when the document contains multiple operations. */\n operationName?: Maybe<string>;\n /** Resolver used when a field does not define its own resolver. */\n fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Resolver used when an abstract type does not define its own resolver. */\n typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;\n /** Resolver used for the root subscription field. */\n subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;\n /** Whether suggestion text should be omitted from request errors. */\n hideSuggestions?: Maybe<boolean>;\n /** AbortSignal used to cancel execution. */\n abortSignal?: Maybe<AbortSignal>;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution?: Maybe<boolean>;\n /** Execution hooks invoked during this operation. */\n hooks?: Maybe<ExecutionHooks>;\n /** Additional execution options. */\n options?: {\n /**\n * Set the maximum number of errors allowed for coercing (defaults to 50).\n *\n * @internal\n */\n maxCoercionErrors?: number;\n };\n}\n\n/**\n * Data that must be available at all points during query execution.\n *\n * Namely, schema of the type system that is currently executing,\n * and the fragments defined in the query document\n */\nexport interface ValidatedExecutionArgs {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed GraphQL document being executed. */\n document: DocumentNode;\n // TODO: consider deprecating/removing fragmentDefinitions if/when fragment\n // arguments are officially supported and/or the full fragment details are\n // exposed within GraphQLResolveInfo.\n /** Fragment definitions keyed by fragment name. */\n fragmentDefinitions: ObjMap<FragmentDefinitionNode>;\n /** Fragment details keyed by fragment name. */\n fragments: ObjMap<FragmentDetails>;\n /** Root value passed to the operation. */\n rootValue: unknown;\n /** Application context value passed to every resolver. */\n contextValue: unknown;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Operation variable values with source metadata and coerced runtime values. */\n variableValues: VariableValues;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Resolver used for fields without an explicit resolver. */\n fieldResolver: GraphQLFieldResolver<any, any>;\n /** Resolver used for abstract types without an explicit type resolver. */\n typeResolver: GraphQLTypeResolver<any, any>;\n /** Resolver used for subscription fields without an explicit subscribe resolver. */\n subscribeFieldResolver: GraphQLFieldResolver<any, any>;\n /** Whether suggestion text should be omitted from execution errors. */\n hideSuggestions: boolean;\n /** Whether execution should use error propagation. */\n errorPropagation: boolean;\n /** External signal that may abort execution. */\n externalAbortSignal: AbortSignal | undefined;\n /** Whether incremental execution may begin eligible work early. */\n enableEarlyExecution: boolean;\n /** Execution hooks supplied by the caller. */\n hooks: ExecutionHooks | undefined;\n}\n\n/** Validated execution arguments for a subscription operation. */\nexport interface ValidatedSubscriptionArgs extends ValidatedExecutionArgs {\n /** Subscription operation definition selected for execution. */\n operation: SubscriptionOperationDefinitionNode;\n}\n\n/** Information passed to hooks after asynchronous execution work has finished. */\nexport interface AsyncWorkFinishedInfo {\n /** Validated execution arguments for the operation that finished async work. */\n validatedExecutionArgs: ValidatedExecutionArgs;\n}\n\n/** Optional hooks invoked during GraphQL execution. */\nexport interface ExecutionHooks {\n /** Called after all tracked asynchronous execution work has settled. */\n asyncWorkFinished?: (info: AsyncWorkFinishedInfo) => void;\n}\n"]}
|
package/execution/Executor.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ import type { GraphQLFormattedError } from "../error/GraphQLError.mjs";
|
|
|
6
6
|
import { GraphQLError } from "../error/GraphQLError.mjs";
|
|
7
7
|
import type { GraphQLAbstractType, GraphQLLeafType, GraphQLList, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLResolveInfoHelpers } from "../type/definition.mjs";
|
|
8
8
|
import type { GraphQLSchema } from "../type/schema.mjs";
|
|
9
|
+
import type { GraphQLExecuteRootSelectionSetContext, GraphQLResolveContext, MinimalTracingChannel } from "../diagnostics.mjs";
|
|
9
10
|
import { AbortedGraphQLExecutionError } from "./AbortedGraphQLExecutionError.mjs";
|
|
10
11
|
import type { DeferUsage, FieldDetailsList, GroupedFieldSet } from "./collectFields.mjs";
|
|
11
12
|
import { collectSubfields as _collectSubfields } from "./collectFields.mjs";
|
|
@@ -93,6 +94,14 @@ TAlternativeInitialResponse = ExecutionResult> {
|
|
|
93
94
|
promiseAll: <T>(values: ReadonlyArray<PromiseOrValue<T>>) => Promise<Array<T>>;
|
|
94
95
|
constructor(validatedExecutionArgs: ValidatedExecutionArgs, sharedExecutionContext?: SharedExecutionContext);
|
|
95
96
|
executeRootSelectionSet(serially?: boolean): PromiseOrValue<ExecutionResult | TAlternativeInitialResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* Build an operation-scoped diagnostics context from ValidatedExecutionArgs.
|
|
99
|
+
* Used after the operation has already been resolved during argument
|
|
100
|
+
* validation.
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
buildExecuteContextFromValidatedArgs(args: ValidatedExecutionArgs): GraphQLExecuteRootSelectionSetContext;
|
|
104
|
+
executeRootSelectionSetImpl(serially?: boolean): PromiseOrValue<ExecutionResult | TAlternativeInitialResponse>;
|
|
96
105
|
abort(reason?: unknown): void;
|
|
97
106
|
finish<T>(result: T): T;
|
|
98
107
|
createAbortedExecutionError<T>(result: PromiseOrValue<T>): AbortedGraphQLExecutionError<T>;
|
|
@@ -128,7 +137,16 @@ TAlternativeInitialResponse = ExecutionResult> {
|
|
|
128
137
|
*
|
|
129
138
|
* @internal
|
|
130
139
|
*/
|
|
131
|
-
executeField(parentType: GraphQLObjectType, source: unknown, fieldDetailsList: FieldDetailsList, path: Path, positionContext: TPositionContext | undefined): PromiseOrValue<unknown>;
|
|
140
|
+
executeField(parentType: GraphQLObjectType, source: unknown, fieldDetailsList: FieldDetailsList, path: Path, positionContext: TPositionContext | undefined, tracingChannel: MinimalTracingChannel<GraphQLResolveContext> | undefined): PromiseOrValue<unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* Build a graphql:resolve channel context for a single field invocation.
|
|
143
|
+
*
|
|
144
|
+
* `fieldPath` is exposed as a lazy getter because serializing the response
|
|
145
|
+
* path is O(depth) and APMs that depth-filter or skip default resolvers
|
|
146
|
+
* often never read it. `args` is passed through by reference.
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
buildResolveContext(args: ObjMap<unknown>, info: GraphQLResolveInfo, isDefaultResolver: boolean): GraphQLResolveContext;
|
|
132
150
|
handleFieldError(rawError: unknown, returnType: GraphQLOutputType, fieldDetailsList: FieldDetailsList, path: Path): void;
|
|
133
151
|
/**
|
|
134
152
|
* Implements the instructions for completeValue as defined in the
|
package/execution/Executor.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { GraphQLFormattedError } from "../error/GraphQLError.js";
|
|
|
6
6
|
import { GraphQLError } from "../error/GraphQLError.js";
|
|
7
7
|
import type { GraphQLAbstractType, GraphQLLeafType, GraphQLList, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLResolveInfoHelpers } from "../type/definition.js";
|
|
8
8
|
import type { GraphQLSchema } from "../type/schema.js";
|
|
9
|
+
import type { GraphQLExecuteRootSelectionSetContext, GraphQLResolveContext, MinimalTracingChannel } from "../diagnostics.js";
|
|
9
10
|
import { AbortedGraphQLExecutionError } from "./AbortedGraphQLExecutionError.js";
|
|
10
11
|
import type { DeferUsage, FieldDetailsList, GroupedFieldSet } from "./collectFields.js";
|
|
11
12
|
import { collectSubfields as _collectSubfields } from "./collectFields.js";
|
|
@@ -93,6 +94,14 @@ TAlternativeInitialResponse = ExecutionResult> {
|
|
|
93
94
|
promiseAll: <T>(values: ReadonlyArray<PromiseOrValue<T>>) => Promise<Array<T>>;
|
|
94
95
|
constructor(validatedExecutionArgs: ValidatedExecutionArgs, sharedExecutionContext?: SharedExecutionContext);
|
|
95
96
|
executeRootSelectionSet(serially?: boolean): PromiseOrValue<ExecutionResult | TAlternativeInitialResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* Build an operation-scoped diagnostics context from ValidatedExecutionArgs.
|
|
99
|
+
* Used after the operation has already been resolved during argument
|
|
100
|
+
* validation.
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
buildExecuteContextFromValidatedArgs(args: ValidatedExecutionArgs): GraphQLExecuteRootSelectionSetContext;
|
|
104
|
+
executeRootSelectionSetImpl(serially?: boolean): PromiseOrValue<ExecutionResult | TAlternativeInitialResponse>;
|
|
96
105
|
abort(reason?: unknown): void;
|
|
97
106
|
finish<T>(result: T): T;
|
|
98
107
|
createAbortedExecutionError<T>(result: PromiseOrValue<T>): AbortedGraphQLExecutionError<T>;
|
|
@@ -128,7 +137,16 @@ TAlternativeInitialResponse = ExecutionResult> {
|
|
|
128
137
|
*
|
|
129
138
|
* @internal
|
|
130
139
|
*/
|
|
131
|
-
executeField(parentType: GraphQLObjectType, source: unknown, fieldDetailsList: FieldDetailsList, path: Path, positionContext: TPositionContext | undefined): PromiseOrValue<unknown>;
|
|
140
|
+
executeField(parentType: GraphQLObjectType, source: unknown, fieldDetailsList: FieldDetailsList, path: Path, positionContext: TPositionContext | undefined, tracingChannel: MinimalTracingChannel<GraphQLResolveContext> | undefined): PromiseOrValue<unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* Build a graphql:resolve channel context for a single field invocation.
|
|
143
|
+
*
|
|
144
|
+
* `fieldPath` is exposed as a lazy getter because serializing the response
|
|
145
|
+
* path is O(depth) and APMs that depth-filter or skip default resolvers
|
|
146
|
+
* often never read it. `args` is passed through by reference.
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
buildResolveContext(args: ObjMap<unknown>, info: GraphQLResolveInfo, isDefaultResolver: boolean): GraphQLResolveContext;
|
|
132
150
|
handleFieldError(rawError: unknown, returnType: GraphQLOutputType, fieldDetailsList: FieldDetailsList, path: Path): void;
|
|
133
151
|
/**
|
|
134
152
|
* Implements the instructions for completeValue as defined in the
|