graphql 17.0.0-beta.2 → 17.0.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/README.md +3 -5
- 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 +307 -0
- package/diagnostics.d.ts +307 -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/error/locatedError.d.mts +1 -3
- package/error/locatedError.d.ts +1 -3
- package/error/locatedError.js.map +1 -1
- package/error/locatedError.mjs.map +1 -1
- package/execution/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.d.mts +65 -44
- package/execution/execute.d.ts +65 -44
- package/execution/execute.js +73 -4
- package/execution/execute.js.map +1 -1
- package/execution/execute.mjs +73 -4
- package/execution/execute.mjs.map +1 -1
- package/execution/values.d.mts +17 -17
- package/execution/values.d.ts +17 -17
- package/execution/values.js.map +1 -1
- package/execution/values.mjs.map +1 -1
- package/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.d.mts +20 -30
- package/language/parser.d.ts +20 -30
- package/language/parser.js +9 -9
- package/language/parser.js.map +1 -1
- package/language/parser.mjs +9 -9
- package/language/parser.mjs.map +1 -1
- package/language/predicates.d.mts +5 -1
- package/language/predicates.d.ts +5 -1
- package/language/predicates.js.map +1 -1
- package/language/predicates.mjs.map +1 -1
- package/language/source.d.mts +4 -5
- package/language/source.d.ts +4 -5
- package/language/source.js.map +1 -1
- package/language/source.mjs.map +1 -1
- package/language/visitor.d.mts +10 -2
- package/language/visitor.d.ts +10 -2
- package/language/visitor.js.map +1 -1
- package/language/visitor.mjs.map +1 -1
- package/package.json +2 -2
- package/type/definition.d.mts +96 -64
- package/type/definition.d.ts +96 -64
- package/type/definition.js.map +1 -1
- package/type/definition.mjs.map +1 -1
- package/type/directives.d.mts +3 -3
- package/type/directives.d.ts +3 -3
- package/type/directives.js.map +1 -1
- package/type/directives.mjs.map +1 -1
- package/type/schema.d.mts +4 -8
- package/type/schema.d.ts +4 -8
- package/type/schema.js.map +1 -1
- package/type/schema.mjs.map +1 -1
- package/type/validate.js +101 -30
- package/type/validate.js.map +1 -1
- package/type/validate.mjs +101 -30
- package/type/validate.mjs.map +1 -1
- package/utilities/TypeInfo.d.mts +1 -1
- package/utilities/TypeInfo.d.ts +1 -1
- package/utilities/TypeInfo.js.map +1 -1
- package/utilities/TypeInfo.mjs.map +1 -1
- package/utilities/buildASTSchema.d.mts +0 -1
- package/utilities/buildASTSchema.d.ts +0 -1
- package/utilities/buildASTSchema.js +0 -1
- package/utilities/buildASTSchema.js.map +1 -1
- package/utilities/buildASTSchema.mjs +0 -1
- package/utilities/buildASTSchema.mjs.map +1 -1
- package/utilities/buildClientSchema.d.mts +5 -1
- package/utilities/buildClientSchema.d.ts +5 -1
- package/utilities/buildClientSchema.js.map +1 -1
- package/utilities/buildClientSchema.mjs.map +1 -1
- package/utilities/coerceInputValue.d.mts +7 -6
- package/utilities/coerceInputValue.d.ts +7 -6
- package/utilities/coerceInputValue.js.map +1 -1
- package/utilities/coerceInputValue.mjs.map +1 -1
- package/utilities/concatAST.d.mts +4 -1
- package/utilities/concatAST.d.ts +4 -1
- package/utilities/concatAST.js.map +1 -1
- package/utilities/concatAST.mjs.map +1 -1
- package/utilities/extendSchema.d.mts +3 -3
- package/utilities/extendSchema.d.ts +3 -3
- package/utilities/extendSchema.js +5 -1
- package/utilities/extendSchema.js.map +1 -1
- package/utilities/extendSchema.mjs +5 -1
- package/utilities/extendSchema.mjs.map +1 -1
- package/utilities/introspectionFromSchema.d.mts +6 -2
- package/utilities/introspectionFromSchema.d.ts +6 -2
- package/utilities/introspectionFromSchema.js.map +1 -1
- package/utilities/introspectionFromSchema.mjs.map +1 -1
- package/utilities/lexicographicSortSchema.d.mts +5 -1
- package/utilities/lexicographicSortSchema.d.ts +5 -1
- package/utilities/lexicographicSortSchema.js.map +1 -1
- package/utilities/lexicographicSortSchema.mjs.map +1 -1
- package/utilities/printSchema.d.mts +5 -1
- package/utilities/printSchema.d.ts +5 -1
- package/utilities/printSchema.js.map +1 -1
- package/utilities/printSchema.mjs.map +1 -1
- package/utilities/replaceVariables.d.mts +4 -8
- package/utilities/replaceVariables.d.ts +4 -8
- package/utilities/replaceVariables.js.map +1 -1
- package/utilities/replaceVariables.mjs.map +1 -1
- package/utilities/stripIgnoredCharacters.d.mts +2 -2
- package/utilities/stripIgnoredCharacters.d.ts +2 -2
- package/utilities/stripIgnoredCharacters.js.map +1 -1
- package/utilities/stripIgnoredCharacters.mjs.map +1 -1
- package/utilities/typeComparators.d.mts +1 -5
- package/utilities/typeComparators.d.ts +1 -5
- package/utilities/typeComparators.js.map +1 -1
- package/utilities/typeComparators.mjs.map +1 -1
- package/utilities/validateInputValue.d.mts +10 -8
- package/utilities/validateInputValue.d.ts +10 -8
- package/utilities/validateInputValue.js.map +1 -1
- package/utilities/validateInputValue.mjs.map +1 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.mts +4 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.ts +4 -1
- package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js +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/rules/ExecutableDefinitionsRule.d.mts +6 -2
- package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -2
- package/validation/rules/ExecutableDefinitionsRule.js.map +1 -1
- package/validation/rules/ExecutableDefinitionsRule.mjs.map +1 -1
- package/validation/rules/FieldsOnCorrectTypeRule.d.mts +3 -1
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +3 -1
- package/validation/rules/FieldsOnCorrectTypeRule.js.map +1 -1
- package/validation/rules/FieldsOnCorrectTypeRule.mjs.map +1 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.d.mts +6 -2
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -2
- package/validation/rules/FragmentsOnCompositeTypesRule.js.map +1 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs.map +1 -1
- package/validation/rules/KnownArgumentNamesRule.d.mts +3 -1
- package/validation/rules/KnownArgumentNamesRule.d.ts +3 -1
- package/validation/rules/KnownArgumentNamesRule.js.map +1 -1
- package/validation/rules/KnownArgumentNamesRule.mjs.map +1 -1
- package/validation/rules/KnownDirectivesRule.js +2 -1
- package/validation/rules/KnownDirectivesRule.js.map +1 -1
- package/validation/rules/KnownDirectivesRule.mjs +2 -1
- package/validation/rules/KnownDirectivesRule.mjs.map +1 -1
- package/validation/rules/KnownFragmentNamesRule.d.mts +3 -1
- package/validation/rules/KnownFragmentNamesRule.d.ts +3 -1
- package/validation/rules/KnownFragmentNamesRule.js.map +1 -1
- package/validation/rules/KnownFragmentNamesRule.mjs.map +1 -1
- package/validation/rules/LoneAnonymousOperationRule.d.mts +6 -2
- package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -2
- package/validation/rules/LoneAnonymousOperationRule.js.map +1 -1
- package/validation/rules/LoneAnonymousOperationRule.mjs.map +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.d.mts +6 -2
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -2
- package/validation/rules/MaxIntrospectionDepthRule.js.map +1 -1
- package/validation/rules/MaxIntrospectionDepthRule.mjs.map +1 -1
- package/validation/rules/NoUndefinedVariablesRule.d.mts +3 -1
- package/validation/rules/NoUndefinedVariablesRule.d.ts +3 -1
- package/validation/rules/NoUndefinedVariablesRule.js.map +1 -1
- package/validation/rules/NoUndefinedVariablesRule.mjs.map +1 -1
- package/validation/rules/NoUnusedFragmentsRule.d.mts +3 -1
- package/validation/rules/NoUnusedFragmentsRule.d.ts +3 -1
- package/validation/rules/NoUnusedFragmentsRule.js.map +1 -1
- package/validation/rules/NoUnusedFragmentsRule.mjs.map +1 -1
- package/validation/rules/NoUnusedVariablesRule.d.mts +3 -1
- package/validation/rules/NoUnusedVariablesRule.d.ts +3 -1
- package/validation/rules/NoUnusedVariablesRule.js.map +1 -1
- package/validation/rules/NoUnusedVariablesRule.mjs.map +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.mts +6 -2
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +6 -2
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.map +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs.map +1 -1
- package/validation/rules/PossibleFragmentSpreadsRule.d.mts +6 -2
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -2
- package/validation/rules/PossibleFragmentSpreadsRule.js.map +1 -1
- package/validation/rules/PossibleFragmentSpreadsRule.mjs.map +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.d.mts +6 -2
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -2
- package/validation/rules/ProvidedRequiredArgumentsRule.js.map +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs.map +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.d.mts +6 -2
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -2
- package/validation/rules/SingleFieldSubscriptionsRule.js.map +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.mjs.map +1 -1
- package/validation/rules/UniqueArgumentNamesRule.d.mts +3 -1
- package/validation/rules/UniqueArgumentNamesRule.d.ts +3 -1
- package/validation/rules/UniqueArgumentNamesRule.js.map +1 -1
- package/validation/rules/UniqueArgumentNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.d.mts +6 -2
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -2
- package/validation/rules/UniqueDirectivesPerLocationRule.js.map +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs.map +1 -1
- package/validation/rules/UniqueFragmentNamesRule.d.mts +3 -1
- package/validation/rules/UniqueFragmentNamesRule.d.ts +3 -1
- package/validation/rules/UniqueFragmentNamesRule.js.map +1 -1
- package/validation/rules/UniqueFragmentNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.d.mts +6 -2
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -2
- package/validation/rules/UniqueInputFieldNamesRule.js.map +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueOperationNamesRule.d.mts +3 -1
- package/validation/rules/UniqueOperationNamesRule.d.ts +3 -1
- package/validation/rules/UniqueOperationNamesRule.js.map +1 -1
- package/validation/rules/UniqueOperationNamesRule.mjs.map +1 -1
- package/validation/rules/UniqueVariableNamesRule.d.mts +3 -1
- package/validation/rules/UniqueVariableNamesRule.d.ts +3 -1
- package/validation/rules/UniqueVariableNamesRule.js.map +1 -1
- package/validation/rules/UniqueVariableNamesRule.mjs.map +1 -1
- package/validation/rules/ValuesOfCorrectTypeRule.d.mts +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js.map +1 -1
- package/validation/rules/ValuesOfCorrectTypeRule.mjs.map +1 -1
- package/validation/rules/VariablesAreInputTypesRule.d.mts +6 -2
- package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -2
- package/validation/rules/VariablesAreInputTypesRule.js.map +1 -1
- package/validation/rules/VariablesAreInputTypesRule.mjs.map +1 -1
- package/validation/rules/VariablesInAllowedPositionRule.d.mts +6 -2
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -2
- package/validation/rules/VariablesInAllowedPositionRule.js.map +1 -1
- package/validation/rules/VariablesInAllowedPositionRule.mjs.map +1 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.mts +3 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +3 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.js.map +1 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs.map +1 -1
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.mts +6 -2
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +6 -2
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.map +1 -1
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs.map +1 -1
- package/validation/validate.d.mts +3 -6
- package/validation/validate.d.ts +3 -6
- package/validation/validate.js +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
package/diagnostics.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveChannel = exports.subscribeChannel = exports.executeRootSelectionSetChannel = exports.executeVariableCoercionChannel = exports.executeChannel = exports.validateChannel = exports.parseChannel = void 0;
|
|
4
|
+
exports.shouldTrace = shouldTrace;
|
|
5
|
+
exports.traceMixed = traceMixed;
|
|
6
|
+
const isPromise_ts_1 = require("./jsutils/isPromise.js");
|
|
7
|
+
function resolveDiagnosticsChannel() {
|
|
8
|
+
let dc;
|
|
9
|
+
try {
|
|
10
|
+
const processRef = globalThis.process;
|
|
11
|
+
if (typeof processRef?.getBuiltinModule === 'function') {
|
|
12
|
+
dc = processRef.getBuiltinModule('node:diagnostics_channel');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
}
|
|
17
|
+
return dc;
|
|
18
|
+
}
|
|
19
|
+
const dc = resolveDiagnosticsChannel();
|
|
20
|
+
exports.parseChannel = dc?.tracingChannel('graphql:parse');
|
|
21
|
+
exports.validateChannel = dc?.tracingChannel('graphql:validate');
|
|
22
|
+
exports.executeChannel = dc?.tracingChannel('graphql:execute');
|
|
23
|
+
exports.executeVariableCoercionChannel = dc?.tracingChannel('graphql:execute:variableCoercion');
|
|
24
|
+
exports.executeRootSelectionSetChannel = dc?.tracingChannel('graphql:execute:rootSelectionSet');
|
|
25
|
+
exports.subscribeChannel = dc?.tracingChannel('graphql:subscribe');
|
|
26
|
+
exports.resolveChannel = dc?.tracingChannel('graphql:resolve');
|
|
27
|
+
const SUB_CHANNEL_KEYS = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];
|
|
28
|
+
function shouldTrace(channel) {
|
|
29
|
+
if (channel == null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const aggregate = channel.hasSubscribers;
|
|
33
|
+
if (aggregate !== undefined) {
|
|
34
|
+
return aggregate;
|
|
35
|
+
}
|
|
36
|
+
for (const key of SUB_CHANNEL_KEYS) {
|
|
37
|
+
if (channel[key].hasSubscribers) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function traceMixed(channel, contextInput, fn) {
|
|
44
|
+
const context = contextInput;
|
|
45
|
+
return channel.start.runStores(context, () => {
|
|
46
|
+
let result;
|
|
47
|
+
try {
|
|
48
|
+
result = fn();
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
context.error = err;
|
|
52
|
+
channel.error.publish(context);
|
|
53
|
+
channel.end.publish(context);
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
if (!(0, isPromise_ts_1.isPromiseLike)(result)) {
|
|
57
|
+
context.result = result;
|
|
58
|
+
channel.end.publish(context);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
channel.end.publish(context);
|
|
62
|
+
channel.asyncStart.publish(context);
|
|
63
|
+
return result.then((value) => {
|
|
64
|
+
context.result = value;
|
|
65
|
+
channel.asyncEnd.publish(context);
|
|
66
|
+
return value;
|
|
67
|
+
}, (err) => {
|
|
68
|
+
context.error = err;
|
|
69
|
+
channel.error.publish(context);
|
|
70
|
+
channel.asyncEnd.publish(context);
|
|
71
|
+
throw err;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":";;;AA6WA,kCAiBC;AAsBD,gCAyCC;AAvaD,yDAAuD;AA2QvD,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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CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * TracingChannel integration.\n *\n * GraphQL.js publishes lifecycle events on a set of named tracing channels\n * that application performance monitoring (APM) tools can subscribe to in\n * order to observe parse, validate, execute, subscribe, and resolver behavior,\n * plus selected executor internals. At module load time GraphQL.js resolves\n * `node:diagnostics_channel` itself so APMs do not need to interact with the\n * GraphQL API to enable tracing. On runtimes that do not expose\n * `node:diagnostics_channel` (e.g., browsers) the load silently no-ops and\n * emission sites short-circuit.\n *\n * Within the tracing context types, `error` means the traced JavaScript call\n * threw or rejected; it does not mean every `GraphQLError` returned by\n * GraphQL.js. Some channels complete normally and publish GraphQL errors on\n * `result`. Resolver errors can appear both as `message.error` on\n * `graphql:resolve` and as formatted errors in an enclosing execution or\n * subscription result. `graphql:parse`, `graphql:validate`, and\n * `graphql:execute:variableCoercion` are sync-only channels.\n * @category Diagnostics\n */\n\nimport { isPromiseLike } from './jsutils/isPromise.ts';\nimport type { Maybe } from './jsutils/Maybe.ts';\nimport type { ObjMap } from './jsutils/ObjMap.ts';\n\nimport type { GraphQLError } from './error/GraphQLError.ts';\n\nimport type {\n DocumentNode,\n OperationDefinitionNode,\n OperationTypeNode,\n} from './language/ast.ts';\nimport type { Source } from './language/source.ts';\n\nimport type { GraphQLSchema } from './type/schema.ts';\n\nimport type { ExecutionResult } from './execution/Executor.ts';\nimport type { ExperimentalIncrementalExecutionResults } from './execution/incremental/IncrementalExecutor.ts';\nimport type { VariableValues } from './execution/values.ts';\n\n/**\n * Structural subset of `DiagnosticsChannel` sufficient for publishing and\n * subscriber gating. The `node:diagnostics_channel` `Channel` satisfies this.\n *\n * @internal\n */\nexport interface MinimalChannel<TMessage = unknown> {\n readonly hasSubscribers?: boolean;\n publish: (message: TMessage) => void;\n runStores: <T, ContextType extends object>(\n context: ContextType,\n fn: (this: ContextType, ...args: Array<unknown>) => T,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\n/**\n * Structural subset of the Node.js `TracingChannel` API. The\n * `node:diagnostics_channel` `TracingChannel` satisfies this by duck typing,\n * so GraphQL.js does not need a dependency on `@types/node` or on the runtime\n * itself.\n *\n * @internal\n */\nexport interface MinimalTracingChannel<TContext = unknown> {\n // `undefined` accommodates runtimes (e.g. Bun) that ship `tracingChannel`\n // without exposing the aggregate `hasSubscribers` getter.\n readonly hasSubscribers: boolean | undefined;\n readonly start: MinimalChannel<TContext>;\n readonly end: MinimalChannel<TContext>;\n readonly asyncStart: MinimalChannel<TContext>;\n readonly asyncEnd: MinimalChannel<TContext>;\n readonly error: MinimalChannel<TContext>;\n\n traceSync: <T>(\n fn: (...args: Array<unknown>) => T,\n context: TContext extends object ? TContext : object,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\ninterface DiagnosticsChannelModule {\n tracingChannel: <TContext = unknown>(\n name: string,\n ) => MinimalTracingChannel<TContext>;\n}\n\n/** Context published on the sync-only `graphql:parse` channel. */\nexport interface GraphQLParseContext {\n /** Source text or source object passed to the parser. */\n source: string | Source;\n /** Error thrown while parsing, when parsing fails. */\n error?: unknown;\n /** Parsed document, when parsing succeeds. */\n result?: DocumentNode;\n}\n\n/** Context published on the sync-only `graphql:validate` channel. */\nexport interface GraphQLValidateContext {\n /** Schema used for validation. */\n schema: GraphQLSchema;\n /** Parsed document being validated. */\n document: DocumentNode;\n /** Error thrown while validating, when validation fails abruptly. */\n error?: unknown;\n /** Validation errors returned by validation. */\n result?: ReadonlyArray<GraphQLError>;\n}\n\n/**\n * Context published on `graphql:execute`.\n *\n * Returned results may contain GraphQL errors collected during execution.\n */\nexport interface GraphQLExecuteContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown or rejected while executing, when execution fails abruptly. */\n error?: unknown;\n /** Execution result returned by execution, including GraphQL errors. */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:rootSelectionSet`.\n *\n * Returned results may contain GraphQL errors collected during execution.\n */\nexport interface GraphQLExecuteRootSelectionSetContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown or rejected while executing the root selection set. */\n error?: unknown;\n /**\n * Execution result returned from the root selection set, including GraphQL\n * errors.\n */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:variableCoercion`.\n *\n * Coercion runs synchronously while execution arguments are validated, so only\n * the `start`/`end` (and, on an abrupt throw, `error`) lifecycle fires.\n * Ordinary variable coercion failures are returned on `result.errors`; when\n * execution is invoked through APIs such as `execute()` or `subscribe()`, they\n * surface as GraphQL result errors rather than as the tracing `error`\n * lifecycle event.\n */\nexport interface GraphQLExecuteVariableCoercionContext {\n /** Schema used for variable coercion. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition whose variables are being coerced. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown while coercing variables, when coercion fails abruptly. */\n error?: unknown;\n /** Coerced variable values or coercion errors returned by coercion. */\n result?:\n | { variableValues: VariableValues }\n | { errors: ReadonlyArray<GraphQLError> };\n}\n\n/**\n * Context published on `graphql:subscribe`.\n *\n * Subscription source resolver errors and invalid source stream results are\n * returned on `result` as ExecutionResult errors; they do not publish the\n * `error` lifecycle event unless subscription setup fails abruptly before\n * GraphQL can form a result.\n */\nexport interface GraphQLSubscribeContext {\n /** Schema used for subscription execution. */\n schema: GraphQLSchema;\n /** Parsed subscription document. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown or rejected while subscribing, when setup fails abruptly. */\n error?: unknown;\n /**\n * Subscription response stream, or an ExecutionResult containing GraphQL\n * errors.\n */\n result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;\n}\n\n/**\n * Context published on `graphql:resolve`.\n *\n * Resolver throws and rejections publish the `error` lifecycle event here.\n * The same failure may also be formatted into the enclosing execution or\n * subscription result.\n */\nexport interface GraphQLResolveContext {\n /** Field name being resolved. */\n fieldName: string;\n /** Response alias for the field being resolved. */\n alias: string;\n /** Parent type name for the field being resolved. */\n parentType: string;\n /** Return type string for the field being resolved. */\n fieldType: string;\n /** Argument values passed to the resolver. */\n args: ObjMap<unknown>;\n /** Whether the field is using the default resolver. */\n isDefaultResolver: boolean;\n /** Response path for the field being resolved. */\n fieldPath: string;\n /** Error thrown or rejected by the resolver, when resolution fails. */\n error?: unknown;\n /** Value returned by the resolver, when resolution succeeds. */\n result?: unknown;\n}\n\n/** Mapping from tracing channel name to the context type published on it. */\nexport interface GraphQLChannelContextByName {\n /** Context published on `graphql:parse`. */\n 'graphql:parse': GraphQLParseContext;\n /** Context published on `graphql:validate`. */\n 'graphql:validate': GraphQLValidateContext;\n /** Context published on `graphql:execute`. */\n 'graphql:execute': GraphQLExecuteContext;\n /** Context published on `graphql:execute:variableCoercion`. */\n 'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;\n /** Context published on `graphql:execute:rootSelectionSet`. */\n 'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;\n /** Context published on `graphql:subscribe`. */\n 'graphql:subscribe': GraphQLSubscribeContext;\n /** Context published on `graphql:resolve`. */\n 'graphql:resolve': GraphQLResolveContext;\n}\n\n/**\n * The collection of tracing channels GraphQL.js emits on. Application\n * performance monitoring (APM) tools subscribe to these by name on their own\n * `node:diagnostics_channel` import; both paths land on the same channel\n * instance because `tracingChannel(name)` is cached by name.\n */\nexport interface GraphQLChannels {\n /** Tracing channel for `graphql:execute`. */\n execute: MinimalTracingChannel<GraphQLExecuteContext>;\n /** Tracing channel for `graphql:execute:variableCoercion`. */\n executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;\n /** Tracing channel for `graphql:execute:rootSelectionSet`. */\n executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;\n /** Tracing channel for `graphql:parse`. */\n parse: MinimalTracingChannel<GraphQLParseContext>;\n /** Tracing channel for `graphql:validate`. */\n validate: MinimalTracingChannel<GraphQLValidateContext>;\n /** Tracing channel for `graphql:resolve`. */\n resolve: MinimalTracingChannel<GraphQLResolveContext>;\n /** Tracing channel for `graphql:subscribe`. */\n subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;\n}\n\nfunction resolveDiagnosticsChannel(): DiagnosticsChannelModule | undefined {\n let dc: DiagnosticsChannelModule | undefined;\n try {\n const processRef = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown };\n }\n ).process;\n if (\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n typeof processRef?.getBuiltinModule === 'function'\n ) {\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n dc = processRef.getBuiltinModule(\n 'node:diagnostics_channel',\n ) as DiagnosticsChannelModule;\n }\n /* node:coverage ignore next 3 */\n } catch {\n // diagnostics_channel not available on this runtime; tracing is a no-op.\n }\n return dc;\n}\n\nconst dc = resolveDiagnosticsChannel();\n\n/**\n * Per-channel handles, resolved once at module load. `undefined` when\n * `node:diagnostics_channel` isn't available. Emission sites read these\n * directly to keep the no-subscriber fast path to a single property access\n * plus a `hasSubscribers` check (no function calls, no closures).\n *\n * @internal\n */\nexport const parseChannel:\n | MinimalTracingChannel<GraphQLParseContext>\n | undefined = dc?.tracingChannel('graphql:parse');\n/** @internal */\nexport const validateChannel:\n | MinimalTracingChannel<GraphQLValidateContext>\n | undefined = dc?.tracingChannel('graphql:validate');\n/** @internal */\nexport const executeChannel:\n | MinimalTracingChannel<GraphQLExecuteContext>\n | undefined = dc?.tracingChannel('graphql:execute');\n/** @internal */\nexport const executeVariableCoercionChannel:\n | MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>\n | undefined = dc?.tracingChannel('graphql:execute:variableCoercion');\n/** @internal */\nexport const executeRootSelectionSetChannel:\n | MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>\n | undefined = dc?.tracingChannel('graphql:execute:rootSelectionSet');\n/** @internal */\nexport const subscribeChannel:\n | MinimalTracingChannel<GraphQLSubscribeContext>\n | undefined = dc?.tracingChannel('graphql:subscribe');\n/** @internal */\nexport const resolveChannel:\n | MinimalTracingChannel<GraphQLResolveContext>\n | undefined = dc?.tracingChannel('graphql:resolve');\n\nconst SUB_CHANNEL_KEYS: ReadonlyArray<\n 'start' | 'end' | 'asyncStart' | 'asyncEnd' | 'error'\n> = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];\n\n/**\n * Whether emission sites should publish to `channel`. Trusts the\n * `TracingChannel.hasSubscribers` aggregate when the runtime exposes it; if\n * the getter is missing (e.g. Bun's `node:diagnostics_channel`, where\n * `tracingChannel.hasSubscribers` is `undefined`), falls back to checking\n * each of the five underlying lifecycle channels so a subscriber attached\n * via `tracingChannel.subscribe(handlers)` is still observed.\n *\n * @internal\n */\nexport function shouldTrace<TContext = unknown>(\n channel: MinimalTracingChannel<TContext> | undefined,\n): channel is MinimalTracingChannel<TContext> {\n if (channel == null) {\n return false;\n }\n const aggregate = channel.hasSubscribers;\n if (aggregate !== undefined) {\n return aggregate;\n }\n // Bun-only fallback, exercised by integrationTests/diagnostics-bun.\n for (const key of SUB_CHANNEL_KEYS) {\n if (channel[key].hasSubscribers) {\n return true;\n }\n }\n return false;\n}\n\ninterface TraceLifecycleContext {\n error?: unknown;\n result?: unknown;\n}\n\ntype TraceStartContext<TContext extends TraceLifecycleContext> = Omit<\n TContext,\n 'error' | 'result'\n>;\n\n/**\n * Publish a traced call that may complete synchronously or with a promise.\n * Caller has already verified that a subscriber is attached. On normal\n * completion, `result` is attached before the terminal `end` or `asyncEnd`\n * event. When the traced call throws or rejects, `error` is attached, the\n * `error` sub-channel fires, and the terminal `end` or `asyncEnd` event is\n * published before the original failure is propagated.\n *\n * @internal\n */\nexport function traceMixed<TResult, TContext extends TraceLifecycleContext>(\n channel: MinimalTracingChannel<TContext>,\n contextInput: TraceStartContext<TContext>,\n fn: () => TResult,\n): TResult {\n const context = contextInput as TContext;\n\n return channel.start.runStores(context, () => {\n let result: TResult;\n try {\n result = fn();\n } catch (err) {\n context.error = err;\n channel.error.publish(context);\n channel.end.publish(context);\n throw err;\n }\n\n if (!isPromiseLike(result)) {\n context.result = result;\n channel.end.publish(context);\n return result;\n }\n\n channel.end.publish(context);\n 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":"AAsBA,OAAO,EAAE,aAAa,EAAE,gCAA+B;AA2QvD,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,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AAI,CAAC,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 application performance monitoring (APM) tools can subscribe to in\n * order to observe parse, validate, execute, subscribe, and resolver behavior,\n * plus selected executor internals. At module load time GraphQL.js resolves\n * `node:diagnostics_channel` itself so APMs do not need to interact with the\n * GraphQL API to enable tracing. On runtimes that do not expose\n * `node:diagnostics_channel` (e.g., browsers) the load silently no-ops and\n * emission sites short-circuit.\n *\n * Within the tracing context types, `error` means the traced JavaScript call\n * threw or rejected; it does not mean every `GraphQLError` returned by\n * GraphQL.js. Some channels complete normally and publish GraphQL errors on\n * `result`. Resolver errors can appear both as `message.error` on\n * `graphql:resolve` and as formatted errors in an enclosing execution or\n * subscription result. `graphql:parse`, `graphql:validate`, and\n * `graphql:execute:variableCoercion` are sync-only channels.\n * @category Diagnostics\n */\n\nimport { isPromiseLike } from './jsutils/isPromise.ts';\nimport type { Maybe } from './jsutils/Maybe.ts';\nimport type { ObjMap } from './jsutils/ObjMap.ts';\n\nimport type { GraphQLError } from './error/GraphQLError.ts';\n\nimport type {\n DocumentNode,\n OperationDefinitionNode,\n OperationTypeNode,\n} from './language/ast.ts';\nimport type { Source } from './language/source.ts';\n\nimport type { GraphQLSchema } from './type/schema.ts';\n\nimport type { ExecutionResult } from './execution/Executor.ts';\nimport type { ExperimentalIncrementalExecutionResults } from './execution/incremental/IncrementalExecutor.ts';\nimport type { VariableValues } from './execution/values.ts';\n\n/**\n * Structural subset of `DiagnosticsChannel` sufficient for publishing and\n * subscriber gating. The `node:diagnostics_channel` `Channel` satisfies this.\n *\n * @internal\n */\nexport interface MinimalChannel<TMessage = unknown> {\n readonly hasSubscribers?: boolean;\n publish: (message: TMessage) => void;\n runStores: <T, ContextType extends object>(\n context: ContextType,\n fn: (this: ContextType, ...args: Array<unknown>) => T,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\n/**\n * Structural subset of the Node.js `TracingChannel` API. The\n * `node:diagnostics_channel` `TracingChannel` satisfies this by duck typing,\n * so GraphQL.js does not need a dependency on `@types/node` or on the runtime\n * itself.\n *\n * @internal\n */\nexport interface MinimalTracingChannel<TContext = unknown> {\n // `undefined` accommodates runtimes (e.g. Bun) that ship `tracingChannel`\n // without exposing the aggregate `hasSubscribers` getter.\n readonly hasSubscribers: boolean | undefined;\n readonly start: MinimalChannel<TContext>;\n readonly end: MinimalChannel<TContext>;\n readonly asyncStart: MinimalChannel<TContext>;\n readonly asyncEnd: MinimalChannel<TContext>;\n readonly error: MinimalChannel<TContext>;\n\n traceSync: <T>(\n fn: (...args: Array<unknown>) => T,\n context: TContext extends object ? TContext : object,\n thisArg?: unknown,\n ...args: Array<unknown>\n ) => T;\n}\n\ninterface DiagnosticsChannelModule {\n tracingChannel: <TContext = unknown>(\n name: string,\n ) => MinimalTracingChannel<TContext>;\n}\n\n/** Context published on the sync-only `graphql:parse` channel. */\nexport interface GraphQLParseContext {\n /** Source text or source object passed to the parser. */\n source: string | Source;\n /** Error thrown while parsing, when parsing fails. */\n error?: unknown;\n /** Parsed document, when parsing succeeds. */\n result?: DocumentNode;\n}\n\n/** Context published on the sync-only `graphql:validate` channel. */\nexport interface GraphQLValidateContext {\n /** Schema used for validation. */\n schema: GraphQLSchema;\n /** Parsed document being validated. */\n document: DocumentNode;\n /** Error thrown while validating, when validation fails abruptly. */\n error?: unknown;\n /** Validation errors returned by validation. */\n result?: ReadonlyArray<GraphQLError>;\n}\n\n/**\n * Context published on `graphql:execute`.\n *\n * Returned results may contain GraphQL errors collected during execution.\n */\nexport interface GraphQLExecuteContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown or rejected while executing, when execution fails abruptly. */\n error?: unknown;\n /** Execution result returned by execution, including GraphQL errors. */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:rootSelectionSet`.\n *\n * Returned results may contain GraphQL errors collected during execution.\n */\nexport interface GraphQLExecuteRootSelectionSetContext {\n /** Schema used for execution. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition selected for execution. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown or rejected while executing the root selection set. */\n error?: unknown;\n /**\n * Execution result returned from the root selection set, including GraphQL\n * errors.\n */\n result?: ExecutionResult | ExperimentalIncrementalExecutionResults;\n}\n\n/**\n * Context published on `graphql:execute:variableCoercion`.\n *\n * Coercion runs synchronously while execution arguments are validated, so only\n * the `start`/`end` (and, on an abrupt throw, `error`) lifecycle fires.\n * Ordinary variable coercion failures are returned on `result.errors`; when\n * execution is invoked through APIs such as `execute()` or `subscribe()`, they\n * surface as GraphQL result errors rather than as the tracing `error`\n * lifecycle event.\n */\nexport interface GraphQLExecuteVariableCoercionContext {\n /** Schema used for variable coercion. */\n schema: GraphQLSchema;\n /** Parsed document being executed. */\n document: DocumentNode;\n /** Operation definition whose variables are being coerced. */\n operation: OperationDefinitionNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type. */\n operationType: OperationTypeNode;\n /** Error thrown while coercing variables, when coercion fails abruptly. */\n error?: unknown;\n /** Coerced variable values or coercion errors returned by coercion. */\n result?:\n | { variableValues: VariableValues }\n | { errors: ReadonlyArray<GraphQLError> };\n}\n\n/**\n * Context published on `graphql:subscribe`.\n *\n * Subscription source resolver errors and invalid source stream results are\n * returned on `result` as ExecutionResult errors; they do not publish the\n * `error` lifecycle event unless subscription setup fails abruptly before\n * GraphQL can form a result.\n */\nexport interface GraphQLSubscribeContext {\n /** Schema used for subscription execution. */\n schema: GraphQLSchema;\n /** Parsed subscription document. */\n document: DocumentNode;\n /** Raw variable values provided by the caller before coercion. */\n rawVariableValues: Maybe<{ readonly [variable: string]: unknown }>;\n /** Selected operation name, if one is available. */\n operationName: string | undefined;\n /** Selected operation type, if one is available. */\n operationType: OperationTypeNode | undefined;\n /** Error thrown or rejected while subscribing, when setup fails abruptly. */\n error?: unknown;\n /**\n * Subscription response stream, or an ExecutionResult containing GraphQL\n * errors.\n */\n result?: AsyncGenerator<ExecutionResult, void, void> | ExecutionResult;\n}\n\n/**\n * Context published on `graphql:resolve`.\n *\n * Resolver throws and rejections publish the `error` lifecycle event here.\n * The same failure may also be formatted into the enclosing execution or\n * subscription result.\n */\nexport interface GraphQLResolveContext {\n /** Field name being resolved. */\n fieldName: string;\n /** Response alias for the field being resolved. */\n alias: string;\n /** Parent type name for the field being resolved. */\n parentType: string;\n /** Return type string for the field being resolved. */\n fieldType: string;\n /** Argument values passed to the resolver. */\n args: ObjMap<unknown>;\n /** Whether the field is using the default resolver. */\n isDefaultResolver: boolean;\n /** Response path for the field being resolved. */\n fieldPath: string;\n /** Error thrown or rejected by the resolver, when resolution fails. */\n error?: unknown;\n /** Value returned by the resolver, when resolution succeeds. */\n result?: unknown;\n}\n\n/** Mapping from tracing channel name to the context type published on it. */\nexport interface GraphQLChannelContextByName {\n /** Context published on `graphql:parse`. */\n 'graphql:parse': GraphQLParseContext;\n /** Context published on `graphql:validate`. */\n 'graphql:validate': GraphQLValidateContext;\n /** Context published on `graphql:execute`. */\n 'graphql:execute': GraphQLExecuteContext;\n /** Context published on `graphql:execute:variableCoercion`. */\n 'graphql:execute:variableCoercion': GraphQLExecuteVariableCoercionContext;\n /** Context published on `graphql:execute:rootSelectionSet`. */\n 'graphql:execute:rootSelectionSet': GraphQLExecuteRootSelectionSetContext;\n /** Context published on `graphql:subscribe`. */\n 'graphql:subscribe': GraphQLSubscribeContext;\n /** Context published on `graphql:resolve`. */\n 'graphql:resolve': GraphQLResolveContext;\n}\n\n/**\n * The collection of tracing channels GraphQL.js emits on. Application\n * performance monitoring (APM) tools subscribe to these by name on their own\n * `node:diagnostics_channel` import; both paths land on the same channel\n * instance because `tracingChannel(name)` is cached by name.\n */\nexport interface GraphQLChannels {\n /** Tracing channel for `graphql:execute`. */\n execute: MinimalTracingChannel<GraphQLExecuteContext>;\n /** Tracing channel for `graphql:execute:variableCoercion`. */\n executeVariableCoercion: MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>;\n /** Tracing channel for `graphql:execute:rootSelectionSet`. */\n executeRootSelectionSet: MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>;\n /** Tracing channel for `graphql:parse`. */\n parse: MinimalTracingChannel<GraphQLParseContext>;\n /** Tracing channel for `graphql:validate`. */\n validate: MinimalTracingChannel<GraphQLValidateContext>;\n /** Tracing channel for `graphql:resolve`. */\n resolve: MinimalTracingChannel<GraphQLResolveContext>;\n /** Tracing channel for `graphql:subscribe`. */\n subscribe: MinimalTracingChannel<GraphQLSubscribeContext>;\n}\n\nfunction resolveDiagnosticsChannel(): DiagnosticsChannelModule | undefined {\n let dc: DiagnosticsChannelModule | undefined;\n try {\n const processRef = (\n globalThis as {\n process?: { getBuiltinModule?: (id: string) => unknown };\n }\n ).process;\n if (\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n typeof processRef?.getBuiltinModule === 'function'\n ) {\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n dc = processRef.getBuiltinModule(\n 'node:diagnostics_channel',\n ) as DiagnosticsChannelModule;\n }\n /* node:coverage ignore next 3 */\n } catch {\n // diagnostics_channel not available on this runtime; tracing is a no-op.\n }\n return dc;\n}\n\nconst dc = resolveDiagnosticsChannel();\n\n/**\n * Per-channel handles, resolved once at module load. `undefined` when\n * `node:diagnostics_channel` isn't available. Emission sites read these\n * directly to keep the no-subscriber fast path to a single property access\n * plus a `hasSubscribers` check (no function calls, no closures).\n *\n * @internal\n */\nexport const parseChannel:\n | MinimalTracingChannel<GraphQLParseContext>\n | undefined = dc?.tracingChannel('graphql:parse');\n/** @internal */\nexport const validateChannel:\n | MinimalTracingChannel<GraphQLValidateContext>\n | undefined = dc?.tracingChannel('graphql:validate');\n/** @internal */\nexport const executeChannel:\n | MinimalTracingChannel<GraphQLExecuteContext>\n | undefined = dc?.tracingChannel('graphql:execute');\n/** @internal */\nexport const executeVariableCoercionChannel:\n | MinimalTracingChannel<GraphQLExecuteVariableCoercionContext>\n | undefined = dc?.tracingChannel('graphql:execute:variableCoercion');\n/** @internal */\nexport const executeRootSelectionSetChannel:\n | MinimalTracingChannel<GraphQLExecuteRootSelectionSetContext>\n | undefined = dc?.tracingChannel('graphql:execute:rootSelectionSet');\n/** @internal */\nexport const subscribeChannel:\n | MinimalTracingChannel<GraphQLSubscribeContext>\n | undefined = dc?.tracingChannel('graphql:subscribe');\n/** @internal */\nexport const resolveChannel:\n | MinimalTracingChannel<GraphQLResolveContext>\n | undefined = dc?.tracingChannel('graphql:resolve');\n\nconst SUB_CHANNEL_KEYS: ReadonlyArray<\n 'start' | 'end' | 'asyncStart' | 'asyncEnd' | 'error'\n> = ['start', 'end', 'asyncStart', 'asyncEnd', 'error'];\n\n/**\n * Whether emission sites should publish to `channel`. Trusts the\n * `TracingChannel.hasSubscribers` aggregate when the runtime exposes it; if\n * the getter is missing (e.g. Bun's `node:diagnostics_channel`, where\n * `tracingChannel.hasSubscribers` is `undefined`), falls back to checking\n * each of the five underlying lifecycle channels so a subscriber attached\n * via `tracingChannel.subscribe(handlers)` is still observed.\n *\n * @internal\n */\nexport function shouldTrace<TContext = unknown>(\n channel: MinimalTracingChannel<TContext> | undefined,\n): channel is MinimalTracingChannel<TContext> {\n if (channel == null) {\n return false;\n }\n const aggregate = channel.hasSubscribers;\n if (aggregate !== undefined) {\n return aggregate;\n }\n // Bun-only fallback, exercised by integrationTests/diagnostics-bun.\n for (const key of SUB_CHANNEL_KEYS) {\n if (channel[key].hasSubscribers) {\n return true;\n }\n }\n return false;\n}\n\ninterface TraceLifecycleContext {\n error?: unknown;\n result?: unknown;\n}\n\ntype TraceStartContext<TContext extends TraceLifecycleContext> = Omit<\n TContext,\n 'error' | 'result'\n>;\n\n/**\n * Publish a traced call that may complete synchronously or with a promise.\n * Caller has already verified that a subscriber is attached. On normal\n * completion, `result` is attached before the terminal `end` or `asyncEnd`\n * event. When the traced call throws or rejects, `error` is attached, the\n * `error` sub-channel fires, and the terminal `end` or `asyncEnd` event is\n * published before the original failure is propagated.\n *\n * @internal\n */\nexport function traceMixed<TResult, TContext extends TraceLifecycleContext>(\n channel: MinimalTracingChannel<TContext>,\n contextInput: TraceStartContext<TContext>,\n fn: () => TResult,\n): TResult {\n const context = contextInput as TContext;\n\n return channel.start.runStores(context, () => {\n let result: TResult;\n try {\n result = fn();\n } catch (err) {\n context.error = err;\n channel.error.publish(context);\n channel.end.publish(context);\n throw err;\n }\n\n if (!isPromiseLike(result)) {\n context.result = result;\n channel.end.publish(context);\n return result;\n }\n\n channel.end.publish(context);\n 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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C,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;AAu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AAI,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","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;AAsDtC,MAAM,OAAO,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,QA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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,EA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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"]}
|
package/error/locatedError.d.mts
CHANGED
|
@@ -17,9 +17,7 @@ import { GraphQLError } from "./GraphQLError.mjs";
|
|
|
17
17
|
*
|
|
18
18
|
* const document = parse('{ viewer { name } }');
|
|
19
19
|
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
20
|
-
* const error = locatedError(new Error('Resolver failed'), fieldNode, [
|
|
21
|
-
* 'viewer',
|
|
22
|
-
* ]);
|
|
20
|
+
* const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);
|
|
23
21
|
*
|
|
24
22
|
* error.message; // => 'Resolver failed'
|
|
25
23
|
* error.locations; // => [{ line: 1, column: 3 }]
|
package/error/locatedError.d.ts
CHANGED
|
@@ -17,9 +17,7 @@ import { GraphQLError } from "./GraphQLError.js";
|
|
|
17
17
|
*
|
|
18
18
|
* const document = parse('{ viewer { name } }');
|
|
19
19
|
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
20
|
-
* const error = locatedError(new Error('Resolver failed'), fieldNode, [
|
|
21
|
-
* 'viewer',
|
|
22
|
-
* ]);
|
|
20
|
+
* const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);
|
|
23
21
|
*
|
|
24
22
|
* error.message; // => 'Resolver failed'
|
|
25
23
|
* error.locations; // => [{ line: 1, column: 3 }]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locatedError.js","sourceRoot":"","sources":["../../src/error/locatedError.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"locatedError.js","sourceRoot":"","sources":["../../src/error/locatedError.ts"],"names":[],"mappings":";;AA+BA,oCAmBC;AA/CD,sDAAgD;AAIhD,uDAAiD;AAwBjD,SAAgB,YAAY,CAC1B,gBAAyB,EACzB,KAA0D,EAC1D,IAA4C;IAE5C,MAAM,aAAa,GAAG,IAAA,oBAAO,EAAC,gBAAgB,CAAC,CAAC;IAGhD,IAAI,qBAAqB,CAAC,aAAa,CAAC,EAAE,CAAC;QACzC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,8BAAY,CAAC,aAAa,CAAC,OAAO,EAAE;QAC7C,KAAK,EAAG,aAA8B,CAAC,KAAK,IAAI,KAAK;QACrD,MAAM,EAAG,aAA8B,CAAC,MAAM;QAC9C,SAAS,EAAG,aAA8B,CAAC,SAAS;QACpD,IAAI;QACJ,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAU;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/** @category Errors */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport { toError } from '../jsutils/toError.ts';\n\nimport type { ASTNode } from '../language/ast.ts';\n\nimport { GraphQLError } from './GraphQLError.ts';\n\n/**\n * Given an arbitrary value, presumably thrown while attempting to execute a\n * GraphQL operation, produce a new GraphQLError aware of the location in the\n * document responsible for the original Error.\n * @param rawOriginalError - The original error value to wrap.\n * @param nodes - The AST nodes associated with the error.\n * @param path - The response path associated with the error.\n * @returns The GraphQL error.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { locatedError } from 'graphql/error';\n *\n * const document = parse('{ viewer { name } }');\n * const fieldNode = document.definitions[0].selectionSet.selections[0];\n * const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);\n *\n * error.message; // => 'Resolver failed'\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['viewer']\n * ```\n */\nexport function locatedError(\n rawOriginalError: unknown,\n nodes: ASTNode | ReadonlyArray<ASTNode> | undefined | null,\n path?: Maybe<ReadonlyArray<string | number>>,\n): GraphQLError {\n const originalError = toError(rawOriginalError);\n\n // Note: this uses a brand-check to support GraphQL errors originating from other contexts.\n if (isLocatedGraphQLError(originalError)) {\n return originalError;\n }\n\n return new GraphQLError(originalError.message, {\n nodes: (originalError as GraphQLError).nodes ?? nodes,\n source: (originalError as GraphQLError).source,\n positions: (originalError as GraphQLError).positions,\n path,\n originalError,\n });\n}\n\nfunction isLocatedGraphQLError(error: any): error is GraphQLError {\n return Array.isArray(error.path);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locatedError.js","sourceRoot":"","sources":["../../src/error/locatedError.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,+BAA8B;AAIhD,OAAO,EAAE,YAAY,EAAE,2BAA0B;
|
|
1
|
+
{"version":3,"file":"locatedError.js","sourceRoot":"","sources":["../../src/error/locatedError.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,+BAA8B;AAIhD,OAAO,EAAE,YAAY,EAAE,2BAA0B;AAwBjD,MAAM,UAAU,YAAY,CAC1B,gBAAyB,EACzB,KAA0D,EAC1D,IAA4C;IAE5C,MAAM,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAGhD,IAAI,qBAAqB,CAAC,aAAa,CAAC,EAAE,CAAC;QACzC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,aAAa,CAAC,OAAO,EAAE;QAC7C,KAAK,EAAG,aAA8B,CAAC,KAAK,IAAI,KAAK;QACrD,MAAM,EAAG,aAA8B,CAAC,MAAM;QAC9C,SAAS,EAAG,aAA8B,CAAC,SAAS;QACpD,IAAI;QACJ,aAAa;KACd,CAAC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAU;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/** @category Errors */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport { toError } from '../jsutils/toError.ts';\n\nimport type { ASTNode } from '../language/ast.ts';\n\nimport { GraphQLError } from './GraphQLError.ts';\n\n/**\n * Given an arbitrary value, presumably thrown while attempting to execute a\n * GraphQL operation, produce a new GraphQLError aware of the location in the\n * document responsible for the original Error.\n * @param rawOriginalError - The original error value to wrap.\n * @param nodes - The AST nodes associated with the error.\n * @param path - The response path associated with the error.\n * @returns The GraphQL error.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { locatedError } from 'graphql/error';\n *\n * const document = parse('{ viewer { name } }');\n * const fieldNode = document.definitions[0].selectionSet.selections[0];\n * const error = locatedError(new Error('Resolver failed'), fieldNode, ['viewer']);\n *\n * error.message; // => 'Resolver failed'\n * error.locations; // => [{ line: 1, column: 3 }]\n * error.path; // => ['viewer']\n * ```\n */\nexport function locatedError(\n rawOriginalError: unknown,\n nodes: ASTNode | ReadonlyArray<ASTNode> | undefined | null,\n path?: Maybe<ReadonlyArray<string | number>>,\n): GraphQLError {\n const originalError = toError(rawOriginalError);\n\n // Note: this uses a brand-check to support GraphQL errors originating from other contexts.\n if (isLocatedGraphQLError(originalError)) {\n return originalError;\n }\n\n return new GraphQLError(originalError.message, {\n nodes: (originalError as GraphQLError).nodes ?? nodes,\n source: (originalError as GraphQLError).source,\n positions: (originalError as GraphQLError).positions,\n path,\n originalError,\n });\n}\n\nfunction isLocatedGraphQLError(error: any): error is GraphQLError {\n return Array.isArray(error.path);\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. */
|