graphql 16.14.0 → 16.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/error/GraphQLError.d.ts +151 -15
- package/error/GraphQLError.js +143 -12
- package/error/GraphQLError.mjs +143 -12
- package/error/index.d.ts +6 -0
- package/error/index.mjs +6 -0
- package/error/locatedError.d.ts +20 -0
- package/error/locatedError.js +21 -0
- package/error/locatedError.mjs +20 -0
- package/error/syntaxError.d.ts +15 -0
- package/error/syntaxError.js +16 -0
- package/error/syntaxError.mjs +15 -0
- package/execution/collectFields.js +6 -0
- package/execution/collectFields.mjs +6 -0
- package/execution/execute.d.ts +211 -12
- package/execution/execute.js +214 -23
- package/execution/execute.mjs +213 -23
- package/execution/index.d.ts +6 -0
- package/execution/index.mjs +6 -0
- package/execution/mapAsyncIterator.d.ts +2 -0
- package/execution/mapAsyncIterator.js +2 -0
- package/execution/mapAsyncIterator.mjs +2 -0
- package/execution/subscribe.d.ts +195 -5
- package/execution/subscribe.js +154 -11
- package/execution/subscribe.mjs +153 -11
- package/execution/values.d.ts +167 -10
- package/execution/values.js +149 -5
- package/execution/values.mjs +148 -5
- package/graphql.d.ts +163 -41
- package/graphql.js +126 -4
- package/graphql.mjs +131 -41
- package/index.d.ts +11 -17
- package/index.mjs +13 -19
- package/jsutils/Maybe.d.ts +5 -1
- package/jsutils/ObjMap.d.ts +4 -0
- package/jsutils/Path.d.ts +30 -0
- package/jsutils/Path.js +29 -0
- package/jsutils/Path.mjs +29 -0
- package/jsutils/PromiseOrValue.d.ts +1 -0
- package/jsutils/devAssert.d.ts +1 -0
- package/jsutils/devAssert.js +1 -0
- package/jsutils/devAssert.mjs +1 -0
- package/jsutils/didYouMean.d.ts +4 -1
- package/jsutils/didYouMean.js +4 -1
- package/jsutils/didYouMean.mjs +4 -1
- package/jsutils/groupBy.d.ts +2 -0
- package/jsutils/groupBy.js +2 -0
- package/jsutils/groupBy.mjs +2 -0
- package/jsutils/identityFunc.d.ts +2 -0
- package/jsutils/identityFunc.js +2 -0
- package/jsutils/identityFunc.mjs +2 -0
- package/jsutils/inspect.d.ts +2 -0
- package/jsutils/inspect.js +2 -0
- package/jsutils/inspect.mjs +2 -0
- package/jsutils/instanceOf.d.ts +2 -0
- package/jsutils/instanceOf.js +2 -0
- package/jsutils/instanceOf.mjs +2 -0
- package/jsutils/invariant.d.ts +1 -0
- package/jsutils/invariant.js +1 -0
- package/jsutils/invariant.mjs +1 -0
- package/jsutils/isAsyncIterable.d.ts +2 -0
- package/jsutils/isAsyncIterable.js +2 -0
- package/jsutils/isAsyncIterable.mjs +2 -0
- package/jsutils/isIterableObject.d.ts +6 -5
- package/jsutils/isIterableObject.js +6 -5
- package/jsutils/isIterableObject.mjs +6 -5
- package/jsutils/isObjectLike.d.ts +2 -0
- package/jsutils/isObjectLike.js +2 -0
- package/jsutils/isObjectLike.mjs +2 -0
- package/jsutils/isPromise.d.ts +2 -0
- package/jsutils/isPromise.js +2 -0
- package/jsutils/isPromise.mjs +2 -0
- package/jsutils/keyMap.d.ts +7 -14
- package/jsutils/keyMap.js +7 -14
- package/jsutils/keyMap.mjs +7 -14
- package/jsutils/keyValMap.d.ts +9 -6
- package/jsutils/keyValMap.js +9 -6
- package/jsutils/keyValMap.mjs +9 -6
- package/jsutils/mapValue.d.ts +2 -0
- package/jsutils/mapValue.js +2 -0
- package/jsutils/mapValue.mjs +2 -0
- package/jsutils/memoize3.d.ts +2 -0
- package/jsutils/memoize3.js +2 -0
- package/jsutils/memoize3.mjs +2 -0
- package/jsutils/naturalCompare.d.ts +2 -0
- package/jsutils/naturalCompare.js +2 -0
- package/jsutils/naturalCompare.mjs +2 -0
- package/jsutils/printPathArray.d.ts +2 -0
- package/jsutils/printPathArray.js +2 -0
- package/jsutils/printPathArray.mjs +2 -0
- package/jsutils/promiseForObject.d.ts +2 -0
- package/jsutils/promiseForObject.js +2 -0
- package/jsutils/promiseForObject.mjs +2 -0
- package/jsutils/promiseReduce.d.ts +2 -0
- package/jsutils/promiseReduce.js +2 -0
- package/jsutils/promiseReduce.mjs +2 -0
- package/jsutils/suggestionList.d.ts +2 -0
- package/jsutils/suggestionList.js +4 -0
- package/jsutils/suggestionList.mjs +4 -0
- package/jsutils/toError.d.ts +2 -0
- package/jsutils/toError.js +2 -0
- package/jsutils/toError.mjs +2 -0
- package/jsutils/toObjMap.d.ts +1 -0
- package/jsutils/toObjMap.js +1 -0
- package/jsutils/toObjMap.mjs +1 -0
- package/language/ast.d.ts +412 -54
- package/language/ast.js +95 -38
- package/language/ast.mjs +95 -38
- package/language/blockString.d.ts +1 -3
- package/language/blockString.js +1 -3
- package/language/blockString.mjs +1 -3
- package/language/directiveLocation.d.ts +28 -8
- package/language/directiveLocation.js +9 -6
- package/language/directiveLocation.mjs +9 -6
- package/language/index.d.ts +6 -0
- package/language/index.mjs +6 -0
- package/language/kinds.d.ts +57 -18
- package/language/kinds.js +9 -6
- package/language/kinds.mjs +9 -6
- package/language/lexer.d.ts +47 -14
- package/language/lexer.js +71 -13
- package/language/lexer.mjs +70 -13
- package/language/location.d.ts +16 -3
- package/language/location.js +14 -3
- package/language/location.mjs +14 -3
- package/language/parser.d.ts +236 -13
- package/language/parser.js +224 -0
- package/language/parser.mjs +224 -3
- package/language/predicates.d.ts +169 -0
- package/language/predicates.js +170 -0
- package/language/predicates.mjs +180 -0
- package/language/printLocation.d.ts +28 -0
- package/language/printLocation.js +29 -0
- package/language/printLocation.mjs +28 -0
- package/language/printString.d.ts +2 -0
- package/language/printString.js +5 -1
- package/language/printString.mjs +5 -1
- package/language/printer.d.ts +12 -0
- package/language/printer.js +19 -0
- package/language/printer.mjs +18 -0
- package/language/schemaCoordinateLexer.d.ts +8 -6
- package/language/schemaCoordinateLexer.js +10 -6
- package/language/schemaCoordinateLexer.mjs +10 -6
- package/language/source.d.ts +28 -0
- package/language/source.js +32 -0
- package/language/source.mjs +31 -0
- package/language/tokenKind.d.ts +30 -3
- package/language/tokenKind.js +8 -3
- package/language/tokenKind.mjs +8 -3
- package/language/visitor.d.ts +200 -72
- package/language/visitor.js +122 -50
- package/language/visitor.mjs +122 -54
- package/package.json +1 -1
- package/subscription/index.d.ts +9 -3
- package/subscription/index.mjs +9 -3
- package/type/assertName.d.ts +18 -1
- package/type/assertName.js +19 -1
- package/type/assertName.mjs +18 -1
- package/type/definition.d.ts +2540 -79
- package/type/definition.js +2214 -61
- package/type/definition.mjs +2241 -60
- package/type/directives.d.ts +193 -18
- package/type/directives.js +196 -19
- package/type/directives.mjs +196 -19
- package/type/index.d.ts +6 -0
- package/type/index.mjs +6 -0
- package/type/introspection.d.ts +36 -0
- package/type/introspection.js +33 -0
- package/type/introspection.mjs +41 -0
- package/type/scalars.d.ts +29 -2
- package/type/scalars.js +37 -2
- package/type/scalars.mjs +36 -2
- package/type/schema.d.ts +490 -28
- package/type/schema.js +484 -26
- package/type/schema.mjs +484 -26
- package/type/validate.d.ts +31 -0
- package/type/validate.js +32 -0
- package/type/validate.mjs +31 -0
- package/utilities/TypeInfo.d.ts +441 -1
- package/utilities/TypeInfo.js +444 -1
- package/utilities/TypeInfo.mjs +443 -1
- package/utilities/assertValidName.d.ts +27 -2
- package/utilities/assertValidName.js +28 -2
- package/utilities/assertValidName.mjs +27 -2
- package/utilities/astFromValue.d.ts +33 -3
- package/utilities/astFromValue.js +36 -3
- package/utilities/astFromValue.mjs +35 -3
- package/utilities/buildASTSchema.d.ts +65 -6
- package/utilities/buildASTSchema.js +65 -6
- package/utilities/buildASTSchema.mjs +65 -6
- package/utilities/buildClientSchema.d.ts +15 -0
- package/utilities/buildClientSchema.js +16 -0
- package/utilities/buildClientSchema.mjs +15 -0
- package/utilities/coerceInputValue.d.ts +46 -0
- package/utilities/coerceInputValue.js +47 -0
- package/utilities/coerceInputValue.mjs +46 -0
- package/utilities/concatAST.d.ts +12 -0
- package/utilities/concatAST.js +13 -0
- package/utilities/concatAST.mjs +12 -0
- package/utilities/extendSchema.d.ts +56 -3
- package/utilities/extendSchema.js +63 -3
- package/utilities/extendSchema.mjs +62 -3
- package/utilities/findBreakingChanges.d.ts +95 -0
- package/utilities/findBreakingChanges.js +68 -0
- package/utilities/findBreakingChanges.mjs +70 -0
- package/utilities/getIntrospectionQuery.d.ts +132 -0
- package/utilities/getIntrospectionQuery.js +41 -0
- package/utilities/getIntrospectionQuery.mjs +41 -0
- package/utilities/getOperationAST.d.ts +15 -0
- package/utilities/getOperationAST.js +16 -0
- package/utilities/getOperationAST.mjs +15 -0
- package/utilities/getOperationRootType.d.ts +18 -1
- package/utilities/getOperationRootType.js +19 -1
- package/utilities/getOperationRootType.mjs +18 -1
- package/utilities/index.d.ts +7 -0
- package/utilities/index.mjs +7 -0
- package/utilities/introspectionFromSchema.d.ts +54 -0
- package/utilities/introspectionFromSchema.js +55 -0
- package/utilities/introspectionFromSchema.mjs +54 -0
- package/utilities/lexicographicSortSchema.d.ts +35 -0
- package/utilities/lexicographicSortSchema.js +36 -0
- package/utilities/lexicographicSortSchema.mjs +35 -0
- package/utilities/printSchema.d.ts +63 -0
- package/utilities/printSchema.js +66 -0
- package/utilities/printSchema.mjs +67 -0
- package/utilities/resolveSchemaCoordinate.d.ts +62 -0
- package/utilities/resolveSchemaCoordinate.js +64 -0
- package/utilities/resolveSchemaCoordinate.mjs +63 -0
- package/utilities/separateOperations.d.ts +30 -0
- package/utilities/separateOperations.js +31 -0
- package/utilities/separateOperations.mjs +30 -0
- package/utilities/stripIgnoredCharacters.d.ts +13 -6
- package/utilities/stripIgnoredCharacters.js +16 -6
- package/utilities/stripIgnoredCharacters.mjs +15 -6
- package/utilities/typeComparators.d.ts +84 -0
- package/utilities/typeComparators.js +85 -0
- package/utilities/typeComparators.mjs +84 -0
- package/utilities/typeFromAST.d.ts +86 -0
- package/utilities/typeFromAST.js +3 -0
- package/utilities/typeFromAST.mjs +3 -0
- package/utilities/typedQueryDocumentNode.d.ts +4 -0
- package/utilities/valueFromAST.d.ts +38 -0
- package/utilities/valueFromAST.js +39 -0
- package/utilities/valueFromAST.mjs +38 -0
- package/utilities/valueFromASTUntyped.d.ts +15 -2
- package/utilities/valueFromASTUntyped.js +16 -2
- package/utilities/valueFromASTUntyped.mjs +15 -2
- package/validation/ValidationContext.d.ts +399 -0
- package/validation/ValidationContext.js +400 -0
- package/validation/ValidationContext.mjs +401 -0
- package/validation/index.d.ts +6 -0
- package/validation/index.mjs +6 -0
- package/validation/rules/ExecutableDefinitionsRule.d.ts +28 -0
- package/validation/rules/ExecutableDefinitionsRule.js +29 -0
- package/validation/rules/ExecutableDefinitionsRule.mjs +28 -0
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +28 -0
- package/validation/rules/FieldsOnCorrectTypeRule.js +33 -0
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +32 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +28 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.js +29 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs +28 -0
- package/validation/rules/KnownArgumentNamesRule.d.ts +29 -3
- package/validation/rules/KnownArgumentNamesRule.js +30 -3
- package/validation/rules/KnownArgumentNamesRule.mjs +29 -3
- package/validation/rules/KnownDirectivesRule.d.ts +28 -0
- package/validation/rules/KnownDirectivesRule.js +29 -0
- package/validation/rules/KnownDirectivesRule.mjs +28 -0
- package/validation/rules/KnownFragmentNamesRule.d.ts +28 -0
- package/validation/rules/KnownFragmentNamesRule.js +29 -0
- package/validation/rules/KnownFragmentNamesRule.mjs +28 -0
- package/validation/rules/KnownTypeNamesRule.d.ts +28 -0
- package/validation/rules/KnownTypeNamesRule.js +29 -0
- package/validation/rules/KnownTypeNamesRule.mjs +28 -0
- package/validation/rules/LoneAnonymousOperationRule.d.ts +28 -0
- package/validation/rules/LoneAnonymousOperationRule.js +29 -0
- package/validation/rules/LoneAnonymousOperationRule.mjs +28 -0
- package/validation/rules/LoneSchemaDefinitionRule.d.ts +21 -0
- package/validation/rules/LoneSchemaDefinitionRule.js +22 -0
- package/validation/rules/LoneSchemaDefinitionRule.mjs +21 -0
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +31 -0
- package/validation/rules/MaxIntrospectionDepthRule.js +33 -0
- package/validation/rules/MaxIntrospectionDepthRule.mjs +34 -0
- package/validation/rules/NoFragmentCyclesRule.d.ts +28 -0
- package/validation/rules/NoFragmentCyclesRule.js +29 -0
- package/validation/rules/NoFragmentCyclesRule.mjs +28 -0
- package/validation/rules/NoUndefinedVariablesRule.d.ts +28 -0
- package/validation/rules/NoUndefinedVariablesRule.js +29 -0
- package/validation/rules/NoUndefinedVariablesRule.mjs +28 -0
- package/validation/rules/NoUnusedFragmentsRule.d.ts +28 -0
- package/validation/rules/NoUnusedFragmentsRule.js +29 -0
- package/validation/rules/NoUnusedFragmentsRule.mjs +28 -0
- package/validation/rules/NoUnusedVariablesRule.d.ts +29 -0
- package/validation/rules/NoUnusedVariablesRule.js +30 -0
- package/validation/rules/NoUnusedVariablesRule.mjs +29 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +33 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +45 -6
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +45 -6
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +36 -0
- package/validation/rules/PossibleFragmentSpreadsRule.js +37 -0
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +36 -0
- package/validation/rules/PossibleTypeExtensionsRule.d.ts +21 -0
- package/validation/rules/PossibleTypeExtensionsRule.js +22 -0
- package/validation/rules/PossibleTypeExtensionsRule.mjs +21 -0
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +29 -3
- package/validation/rules/ProvidedRequiredArgumentsRule.js +30 -3
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +29 -3
- package/validation/rules/ScalarLeafsRule.d.ts +28 -0
- package/validation/rules/ScalarLeafsRule.js +29 -0
- package/validation/rules/ScalarLeafsRule.mjs +28 -0
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +33 -0
- package/validation/rules/SingleFieldSubscriptionsRule.js +34 -0
- package/validation/rules/SingleFieldSubscriptionsRule.mjs +33 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.d.ts +21 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.js +22 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +21 -0
- package/validation/rules/UniqueArgumentNamesRule.d.ts +28 -0
- package/validation/rules/UniqueArgumentNamesRule.js +29 -0
- package/validation/rules/UniqueArgumentNamesRule.mjs +28 -0
- package/validation/rules/UniqueDirectiveNamesRule.d.ts +21 -0
- package/validation/rules/UniqueDirectiveNamesRule.js +22 -0
- package/validation/rules/UniqueDirectiveNamesRule.mjs +21 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +28 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.js +29 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs +28 -0
- package/validation/rules/UniqueEnumValueNamesRule.d.ts +21 -0
- package/validation/rules/UniqueEnumValueNamesRule.js +22 -0
- package/validation/rules/UniqueEnumValueNamesRule.mjs +21 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.d.ts +21 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +22 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +21 -0
- package/validation/rules/UniqueFragmentNamesRule.d.ts +28 -0
- package/validation/rules/UniqueFragmentNamesRule.js +29 -0
- package/validation/rules/UniqueFragmentNamesRule.mjs +28 -0
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +32 -0
- package/validation/rules/UniqueInputFieldNamesRule.js +33 -0
- package/validation/rules/UniqueInputFieldNamesRule.mjs +32 -0
- package/validation/rules/UniqueOperationNamesRule.d.ts +28 -0
- package/validation/rules/UniqueOperationNamesRule.js +29 -0
- package/validation/rules/UniqueOperationNamesRule.mjs +28 -0
- package/validation/rules/UniqueOperationTypesRule.d.ts +21 -0
- package/validation/rules/UniqueOperationTypesRule.js +22 -0
- package/validation/rules/UniqueOperationTypesRule.mjs +21 -0
- package/validation/rules/UniqueTypeNamesRule.d.ts +21 -0
- package/validation/rules/UniqueTypeNamesRule.js +22 -0
- package/validation/rules/UniqueTypeNamesRule.mjs +21 -0
- package/validation/rules/UniqueVariableNamesRule.d.ts +28 -0
- package/validation/rules/UniqueVariableNamesRule.js +29 -0
- package/validation/rules/UniqueVariableNamesRule.mjs +28 -0
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +28 -0
- package/validation/rules/ValuesOfCorrectTypeRule.js +31 -0
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +30 -0
- package/validation/rules/VariablesAreInputTypesRule.d.ts +32 -0
- package/validation/rules/VariablesAreInputTypesRule.js +33 -0
- package/validation/rules/VariablesAreInputTypesRule.mjs +32 -0
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +28 -0
- package/validation/rules/VariablesInAllowedPositionRule.js +35 -1
- package/validation/rules/VariablesInAllowedPositionRule.mjs +34 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +41 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.js +42 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +41 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +28 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +29 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +28 -0
- package/validation/specifiedRules.d.ts +2 -3
- package/validation/specifiedRules.js +2 -3
- package/validation/specifiedRules.mjs +2 -3
- package/validation/validate.d.ts +70 -9
- package/validation/validate.js +63 -7
- package/validation/validate.mjs +63 -7
- package/version.d.ts +3 -6
- package/version.js +6 -8
- package/version.mjs +5 -8
package/error/GraphQLError.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/** @category Errors */
|
|
1
2
|
import type { Maybe } from '../jsutils/Maybe';
|
|
2
3
|
import type { ASTNode } from '../language/ast';
|
|
3
4
|
import type { SourceLocation } from '../language/location';
|
|
4
5
|
import type { Source } from '../language/source';
|
|
5
6
|
/**
|
|
6
7
|
* Custom extensions
|
|
7
|
-
*
|
|
8
8
|
* @remarks
|
|
9
9
|
* Use a unique identifier name for your extension, for example the name of
|
|
10
10
|
* your library or project. Do not use a shortened identifier as this increases
|
|
@@ -16,7 +16,6 @@ export interface GraphQLErrorExtensions {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Custom formatted extensions
|
|
19
|
-
*
|
|
20
19
|
* @remarks
|
|
21
20
|
* Use a unique identifier name for your extension, for example the name of
|
|
22
21
|
* your library or project. Do not use a shortened identifier as this increases
|
|
@@ -26,16 +25,24 @@ export interface GraphQLErrorExtensions {
|
|
|
26
25
|
export interface GraphQLFormattedErrorExtensions {
|
|
27
26
|
[attributeName: string]: unknown;
|
|
28
27
|
}
|
|
28
|
+
/** Options used to construct a GraphQLError. */
|
|
29
29
|
export interface GraphQLErrorOptions {
|
|
30
|
+
/** AST node or nodes associated with this error. */
|
|
30
31
|
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
|
|
32
|
+
/** Source document used to derive error locations. */
|
|
31
33
|
source?: Maybe<Source>;
|
|
34
|
+
/** Character offsets in the source document associated with this error. */
|
|
32
35
|
positions?: Maybe<ReadonlyArray<number>>;
|
|
36
|
+
/** Response path where this error occurred during execution. */
|
|
33
37
|
path?: Maybe<ReadonlyArray<string | number>>;
|
|
38
|
+
/** Original error that caused this GraphQLError, if one exists. */
|
|
34
39
|
originalError?: Maybe<
|
|
35
40
|
Error & {
|
|
41
|
+
/** Extension fields associated with this value. */
|
|
36
42
|
readonly extensions?: unknown;
|
|
37
43
|
}
|
|
38
44
|
>;
|
|
45
|
+
/** Extension fields to include in the formatted result. */
|
|
39
46
|
extensions?: Maybe<GraphQLErrorExtensions>;
|
|
40
47
|
}
|
|
41
48
|
/**
|
|
@@ -63,9 +70,7 @@ export declare class GraphQLError extends Error {
|
|
|
63
70
|
* Enumerable, and appears in the result of JSON.stringify().
|
|
64
71
|
*/
|
|
65
72
|
readonly path: ReadonlyArray<string | number> | undefined;
|
|
66
|
-
/**
|
|
67
|
-
* An array of GraphQL AST Nodes corresponding to this error.
|
|
68
|
-
*/
|
|
73
|
+
/** An array of GraphQL AST Nodes corresponding to this error. */
|
|
69
74
|
readonly nodes: ReadonlyArray<ASTNode> | undefined;
|
|
70
75
|
/**
|
|
71
76
|
* The source GraphQL document for the first location of this error.
|
|
@@ -79,16 +84,92 @@ export declare class GraphQLError extends Error {
|
|
|
79
84
|
* which correspond to this error.
|
|
80
85
|
*/
|
|
81
86
|
readonly positions: ReadonlyArray<number> | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* The original error thrown from a field resolver during execution.
|
|
84
|
-
*/
|
|
87
|
+
/** Original error that caused this GraphQLError, if one exists. */
|
|
85
88
|
readonly originalError: Error | undefined;
|
|
89
|
+
/** Extension fields to add to the formatted error. */
|
|
90
|
+
readonly extensions: GraphQLErrorExtensions;
|
|
86
91
|
/**
|
|
87
|
-
*
|
|
92
|
+
* Creates a GraphQLError instance.
|
|
93
|
+
* @param message - Human-readable error message.
|
|
94
|
+
* @param options - Error metadata such as source locations, response path, original error, and extensions.
|
|
95
|
+
* This positional-arguments constructor overload is deprecated. Use the
|
|
96
|
+
* `GraphQLError(message, options)` overload instead.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // Create an error from AST nodes and response metadata.
|
|
100
|
+
* import { parse } from 'graphql/language';
|
|
101
|
+
* import { GraphQLError } from 'graphql/error';
|
|
102
|
+
*
|
|
103
|
+
* const document = parse('{ greeting }');
|
|
104
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
105
|
+
* const error = new GraphQLError('Cannot query this field.', {
|
|
106
|
+
* nodes: fieldNode,
|
|
107
|
+
* path: ['greeting'],
|
|
108
|
+
* extensions: { code: 'FORBIDDEN' },
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* error.message; // => 'Cannot query this field.'
|
|
112
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
113
|
+
* error.path; // => ['greeting']
|
|
114
|
+
* error.extensions; // => { code: 'FORBIDDEN' }
|
|
115
|
+
* ```
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* // This variant derives locations from source positions and preserves the original error.
|
|
119
|
+
* import { Source } from 'graphql/language';
|
|
120
|
+
* import { GraphQLError } from 'graphql/error';
|
|
121
|
+
*
|
|
122
|
+
* const source = new Source('{ greeting }');
|
|
123
|
+
* const originalError = new Error('Database unavailable.');
|
|
124
|
+
* const error = new GraphQLError('Resolver failed.', {
|
|
125
|
+
* source,
|
|
126
|
+
* positions: [2],
|
|
127
|
+
* path: ['greeting'],
|
|
128
|
+
* originalError,
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
132
|
+
* error.path; // => ['greeting']
|
|
133
|
+
* error.originalError; // => originalError
|
|
134
|
+
* ```
|
|
88
135
|
*/
|
|
89
|
-
readonly extensions: GraphQLErrorExtensions;
|
|
90
136
|
constructor(message: string, options?: GraphQLErrorOptions);
|
|
91
137
|
/**
|
|
138
|
+
* Creates a GraphQLError instance using the legacy positional constructor.
|
|
139
|
+
* This deprecated overload will be removed in v17. Prefer the
|
|
140
|
+
* `GraphQLErrorOptions` object overload, which keeps optional error metadata
|
|
141
|
+
* in a single options bag.
|
|
142
|
+
* @param message - Human-readable error message.
|
|
143
|
+
* @param nodes - AST node or nodes associated with this error.
|
|
144
|
+
* @param source - Source document used to derive error locations.
|
|
145
|
+
* @param positions - Character offsets in the source document associated with
|
|
146
|
+
* this error.
|
|
147
|
+
* @param path - Response path where this error occurred during execution.
|
|
148
|
+
* @param originalError - Original error that caused this GraphQLError, if one
|
|
149
|
+
* exists.
|
|
150
|
+
* @param extensions - Extension fields to include in the formatted error.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { Source } from 'graphql/language';
|
|
154
|
+
* import { GraphQLError } from 'graphql/error';
|
|
155
|
+
*
|
|
156
|
+
* const source = new Source('{ greeting }');
|
|
157
|
+
* const originalError = new Error('Database unavailable.');
|
|
158
|
+
* const error = new GraphQLError(
|
|
159
|
+
* 'Resolver failed.',
|
|
160
|
+
* undefined,
|
|
161
|
+
* source,
|
|
162
|
+
* [2],
|
|
163
|
+
* ['greeting'],
|
|
164
|
+
* originalError,
|
|
165
|
+
* { code: 'INTERNAL' },
|
|
166
|
+
* );
|
|
167
|
+
*
|
|
168
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
169
|
+
* error.path; // => ['greeting']
|
|
170
|
+
* error.originalError; // => originalError
|
|
171
|
+
* error.extensions; // => { code: 'INTERNAL' }
|
|
172
|
+
* ```
|
|
92
173
|
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
|
|
93
174
|
*/
|
|
94
175
|
constructor(
|
|
@@ -104,13 +185,46 @@ export declare class GraphQLError extends Error {
|
|
|
104
185
|
>,
|
|
105
186
|
extensions?: Maybe<GraphQLErrorExtensions>,
|
|
106
187
|
);
|
|
188
|
+
/**
|
|
189
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
190
|
+
* @returns The built-in string tag for this object.
|
|
191
|
+
*/
|
|
107
192
|
get [Symbol.toStringTag](): string;
|
|
193
|
+
/**
|
|
194
|
+
* Returns this error as a human-readable message with source locations.
|
|
195
|
+
* @returns The formatted error string.
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { Source } from 'graphql/language';
|
|
199
|
+
* import { GraphQLError } from 'graphql/error';
|
|
200
|
+
*
|
|
201
|
+
* const error = new GraphQLError('Cannot query field "name".', {
|
|
202
|
+
* source: new Source('{ name }'),
|
|
203
|
+
* positions: [2],
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* error.toString(); // => 'Cannot query field "name".\n\nGraphQL request:1:3\n1 | { name }\n | ^'
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
108
209
|
toString(): string;
|
|
210
|
+
/**
|
|
211
|
+
* Returns the JSON representation used when this object is serialized.
|
|
212
|
+
* @returns The JSON-serializable representation.
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { GraphQLError } from 'graphql/error';
|
|
216
|
+
*
|
|
217
|
+
* const error = new GraphQLError('Resolver failed.', {
|
|
218
|
+
* path: ['viewer', 'name'],
|
|
219
|
+
* extensions: { code: 'INTERNAL' },
|
|
220
|
+
* });
|
|
221
|
+
*
|
|
222
|
+
* error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
109
225
|
toJSON(): GraphQLFormattedError;
|
|
110
226
|
}
|
|
111
|
-
/**
|
|
112
|
-
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
113
|
-
*/
|
|
227
|
+
/** See: https://spec.graphql.org/draft/#sec-Errors */
|
|
114
228
|
export interface GraphQLFormattedError {
|
|
115
229
|
/**
|
|
116
230
|
* A short, human-readable summary of the problem that **SHOULD NOT** change
|
|
@@ -138,15 +252,37 @@ export interface GraphQLFormattedError {
|
|
|
138
252
|
}
|
|
139
253
|
/**
|
|
140
254
|
* Prints a GraphQLError to a string, representing useful location information
|
|
141
|
-
* about the error's position in the source.
|
|
255
|
+
* about the error's position in the source. This deprecated helper is retained
|
|
256
|
+
* for backwards compatibility; call `error.toString()` instead because
|
|
257
|
+
* printError will be removed in v17.
|
|
258
|
+
* @param error - The error to format.
|
|
259
|
+
* @returns The printed string representation.
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* import { GraphQLError, printError } from 'graphql/error';
|
|
263
|
+
*
|
|
264
|
+
* const message = printError(new GraphQLError('Example error'));
|
|
142
265
|
*
|
|
266
|
+
* message; // => 'Example error'
|
|
267
|
+
* ```
|
|
143
268
|
* @deprecated Please use `error.toString` instead. Will be removed in v17
|
|
144
269
|
*/
|
|
145
270
|
export declare function printError(error: GraphQLError): string;
|
|
146
271
|
/**
|
|
147
272
|
* Given a GraphQLError, format it according to the rules described by the
|
|
148
|
-
* Response Format, Errors section of the GraphQL Specification.
|
|
273
|
+
* Response Format, Errors section of the GraphQL Specification. This deprecated
|
|
274
|
+
* helper is retained for backwards compatibility; call `error.toJSON()`
|
|
275
|
+
* instead because formatError will be removed in v17.
|
|
276
|
+
* @param error - The error to format.
|
|
277
|
+
* @returns The JSON-serializable formatted error.
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* import { GraphQLError, formatError } from 'graphql/error';
|
|
281
|
+
*
|
|
282
|
+
* const formatted = formatError(new GraphQLError('Example error'));
|
|
149
283
|
*
|
|
284
|
+
* formatted; // => { message: 'Example error' }
|
|
285
|
+
* ```
|
|
150
286
|
* @deprecated Please use `error.toJSON` instead. Will be removed in v17
|
|
151
287
|
*/
|
|
152
288
|
export declare function formatError(error: GraphQLError): GraphQLFormattedError;
|
package/error/GraphQLError.js
CHANGED
|
@@ -13,6 +13,7 @@ var _location = require('../language/location.js');
|
|
|
13
13
|
|
|
14
14
|
var _printLocation = require('../language/printLocation.js');
|
|
15
15
|
|
|
16
|
+
/** @category Errors */
|
|
16
17
|
function toNormalizedOptions(args) {
|
|
17
18
|
const firstArg = args[0];
|
|
18
19
|
|
|
@@ -55,9 +56,7 @@ class GraphQLError extends Error {
|
|
|
55
56
|
* Enumerable, and appears in the result of JSON.stringify().
|
|
56
57
|
*/
|
|
57
58
|
|
|
58
|
-
/**
|
|
59
|
-
* An array of GraphQL AST Nodes corresponding to this error.
|
|
60
|
-
*/
|
|
59
|
+
/** An array of GraphQL AST Nodes corresponding to this error. */
|
|
61
60
|
|
|
62
61
|
/**
|
|
63
62
|
* The source GraphQL document for the first location of this error.
|
|
@@ -71,15 +70,92 @@ class GraphQLError extends Error {
|
|
|
71
70
|
* which correspond to this error.
|
|
72
71
|
*/
|
|
73
72
|
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
/** Original error that caused this GraphQLError, if one exists. */
|
|
74
|
+
|
|
75
|
+
/** Extension fields to add to the formatted error. */
|
|
77
76
|
|
|
78
77
|
/**
|
|
79
|
-
*
|
|
78
|
+
* Creates a GraphQLError instance.
|
|
79
|
+
* @param message - Human-readable error message.
|
|
80
|
+
* @param options - Error metadata such as source locations, response path, original error, and extensions.
|
|
81
|
+
* This positional-arguments constructor overload is deprecated. Use the
|
|
82
|
+
* `GraphQLError(message, options)` overload instead.
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Create an error from AST nodes and response metadata.
|
|
86
|
+
* import { parse } from 'graphql/language';
|
|
87
|
+
* import { GraphQLError } from 'graphql/error';
|
|
88
|
+
*
|
|
89
|
+
* const document = parse('{ greeting }');
|
|
90
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
91
|
+
* const error = new GraphQLError('Cannot query this field.', {
|
|
92
|
+
* nodes: fieldNode,
|
|
93
|
+
* path: ['greeting'],
|
|
94
|
+
* extensions: { code: 'FORBIDDEN' },
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* error.message; // => 'Cannot query this field.'
|
|
98
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
99
|
+
* error.path; // => ['greeting']
|
|
100
|
+
* error.extensions; // => { code: 'FORBIDDEN' }
|
|
101
|
+
* ```
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // This variant derives locations from source positions and preserves the original error.
|
|
105
|
+
* import { Source } from 'graphql/language';
|
|
106
|
+
* import { GraphQLError } from 'graphql/error';
|
|
107
|
+
*
|
|
108
|
+
* const source = new Source('{ greeting }');
|
|
109
|
+
* const originalError = new Error('Database unavailable.');
|
|
110
|
+
* const error = new GraphQLError('Resolver failed.', {
|
|
111
|
+
* source,
|
|
112
|
+
* positions: [2],
|
|
113
|
+
* path: ['greeting'],
|
|
114
|
+
* originalError,
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
118
|
+
* error.path; // => ['greeting']
|
|
119
|
+
* error.originalError; // => originalError
|
|
120
|
+
* ```
|
|
80
121
|
*/
|
|
81
122
|
|
|
82
123
|
/**
|
|
124
|
+
* Creates a GraphQLError instance using the legacy positional constructor.
|
|
125
|
+
* This deprecated overload will be removed in v17. Prefer the
|
|
126
|
+
* `GraphQLErrorOptions` object overload, which keeps optional error metadata
|
|
127
|
+
* in a single options bag.
|
|
128
|
+
* @param message - Human-readable error message.
|
|
129
|
+
* @param nodes - AST node or nodes associated with this error.
|
|
130
|
+
* @param source - Source document used to derive error locations.
|
|
131
|
+
* @param positions - Character offsets in the source document associated with
|
|
132
|
+
* this error.
|
|
133
|
+
* @param path - Response path where this error occurred during execution.
|
|
134
|
+
* @param originalError - Original error that caused this GraphQLError, if one
|
|
135
|
+
* exists.
|
|
136
|
+
* @param extensions - Extension fields to include in the formatted error.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { Source } from 'graphql/language';
|
|
140
|
+
* import { GraphQLError } from 'graphql/error';
|
|
141
|
+
*
|
|
142
|
+
* const source = new Source('{ greeting }');
|
|
143
|
+
* const originalError = new Error('Database unavailable.');
|
|
144
|
+
* const error = new GraphQLError(
|
|
145
|
+
* 'Resolver failed.',
|
|
146
|
+
* undefined,
|
|
147
|
+
* source,
|
|
148
|
+
* [2],
|
|
149
|
+
* ['greeting'],
|
|
150
|
+
* originalError,
|
|
151
|
+
* { code: 'INTERNAL' },
|
|
152
|
+
* );
|
|
153
|
+
*
|
|
154
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
155
|
+
* error.path; // => ['greeting']
|
|
156
|
+
* error.originalError; // => originalError
|
|
157
|
+
* error.extensions; // => { code: 'INTERNAL' }
|
|
158
|
+
* ```
|
|
83
159
|
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
|
|
84
160
|
*/
|
|
85
161
|
constructor(message, ...rawArgs) {
|
|
@@ -191,10 +267,30 @@ class GraphQLError extends Error {
|
|
|
191
267
|
}
|
|
192
268
|
/* c8 ignore stop */
|
|
193
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
272
|
+
* @returns The built-in string tag for this object.
|
|
273
|
+
*/
|
|
194
274
|
|
|
195
275
|
get [Symbol.toStringTag]() {
|
|
196
276
|
return 'GraphQLError';
|
|
197
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Returns this error as a human-readable message with source locations.
|
|
280
|
+
* @returns The formatted error string.
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* import { Source } from 'graphql/language';
|
|
284
|
+
* import { GraphQLError } from 'graphql/error';
|
|
285
|
+
*
|
|
286
|
+
* const error = new GraphQLError('Cannot query field "name".', {
|
|
287
|
+
* source: new Source('{ name }'),
|
|
288
|
+
* positions: [2],
|
|
289
|
+
* });
|
|
290
|
+
*
|
|
291
|
+
* error.toString(); // => 'Cannot query field "name".\n\nGraphQL request:1:3\n1 | { name }\n | ^'
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
198
294
|
|
|
199
295
|
toString() {
|
|
200
296
|
let output = this.message;
|
|
@@ -215,6 +311,21 @@ class GraphQLError extends Error {
|
|
|
215
311
|
|
|
216
312
|
return output;
|
|
217
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Returns the JSON representation used when this object is serialized.
|
|
316
|
+
* @returns The JSON-serializable representation.
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* import { GraphQLError } from 'graphql/error';
|
|
320
|
+
*
|
|
321
|
+
* const error = new GraphQLError('Resolver failed.', {
|
|
322
|
+
* path: ['viewer', 'name'],
|
|
323
|
+
* extensions: { code: 'INTERNAL' },
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
218
329
|
|
|
219
330
|
toJSON() {
|
|
220
331
|
const formattedError = {
|
|
@@ -242,14 +353,23 @@ exports.GraphQLError = GraphQLError;
|
|
|
242
353
|
function undefinedIfEmpty(array) {
|
|
243
354
|
return array === undefined || array.length === 0 ? undefined : array;
|
|
244
355
|
}
|
|
245
|
-
/**
|
|
246
|
-
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
247
|
-
*/
|
|
356
|
+
/** See: https://spec.graphql.org/draft/#sec-Errors */
|
|
248
357
|
|
|
249
358
|
/**
|
|
250
359
|
* Prints a GraphQLError to a string, representing useful location information
|
|
251
|
-
* about the error's position in the source.
|
|
360
|
+
* about the error's position in the source. This deprecated helper is retained
|
|
361
|
+
* for backwards compatibility; call `error.toString()` instead because
|
|
362
|
+
* printError will be removed in v17.
|
|
363
|
+
* @param error - The error to format.
|
|
364
|
+
* @returns The printed string representation.
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* import { GraphQLError, printError } from 'graphql/error';
|
|
368
|
+
*
|
|
369
|
+
* const message = printError(new GraphQLError('Example error'));
|
|
252
370
|
*
|
|
371
|
+
* message; // => 'Example error'
|
|
372
|
+
* ```
|
|
253
373
|
* @deprecated Please use `error.toString` instead. Will be removed in v17
|
|
254
374
|
*/
|
|
255
375
|
function printError(error) {
|
|
@@ -257,8 +377,19 @@ function printError(error) {
|
|
|
257
377
|
}
|
|
258
378
|
/**
|
|
259
379
|
* Given a GraphQLError, format it according to the rules described by the
|
|
260
|
-
* Response Format, Errors section of the GraphQL Specification.
|
|
380
|
+
* Response Format, Errors section of the GraphQL Specification. This deprecated
|
|
381
|
+
* helper is retained for backwards compatibility; call `error.toJSON()`
|
|
382
|
+
* instead because formatError will be removed in v17.
|
|
383
|
+
* @param error - The error to format.
|
|
384
|
+
* @returns The JSON-serializable formatted error.
|
|
385
|
+
* @example
|
|
386
|
+
* ```ts
|
|
387
|
+
* import { GraphQLError, formatError } from 'graphql/error';
|
|
388
|
+
*
|
|
389
|
+
* const formatted = formatError(new GraphQLError('Example error'));
|
|
261
390
|
*
|
|
391
|
+
* formatted; // => { message: 'Example error' }
|
|
392
|
+
* ```
|
|
262
393
|
* @deprecated Please use `error.toJSON` instead. Will be removed in v17
|
|
263
394
|
*/
|
|
264
395
|
|
package/error/GraphQLError.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @category Errors */
|
|
1
2
|
import { isObjectLike } from '../jsutils/isObjectLike.mjs';
|
|
2
3
|
import { getLocation } from '../language/location.mjs';
|
|
3
4
|
import {
|
|
@@ -47,9 +48,7 @@ export class GraphQLError extends Error {
|
|
|
47
48
|
* Enumerable, and appears in the result of JSON.stringify().
|
|
48
49
|
*/
|
|
49
50
|
|
|
50
|
-
/**
|
|
51
|
-
* An array of GraphQL AST Nodes corresponding to this error.
|
|
52
|
-
*/
|
|
51
|
+
/** An array of GraphQL AST Nodes corresponding to this error. */
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* The source GraphQL document for the first location of this error.
|
|
@@ -63,15 +62,92 @@ export class GraphQLError extends Error {
|
|
|
63
62
|
* which correspond to this error.
|
|
64
63
|
*/
|
|
65
64
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
/** Original error that caused this GraphQLError, if one exists. */
|
|
66
|
+
|
|
67
|
+
/** Extension fields to add to the formatted error. */
|
|
69
68
|
|
|
70
69
|
/**
|
|
71
|
-
*
|
|
70
|
+
* Creates a GraphQLError instance.
|
|
71
|
+
* @param message - Human-readable error message.
|
|
72
|
+
* @param options - Error metadata such as source locations, response path, original error, and extensions.
|
|
73
|
+
* This positional-arguments constructor overload is deprecated. Use the
|
|
74
|
+
* `GraphQLError(message, options)` overload instead.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* // Create an error from AST nodes and response metadata.
|
|
78
|
+
* import { parse } from 'graphql/language';
|
|
79
|
+
* import { GraphQLError } from 'graphql/error';
|
|
80
|
+
*
|
|
81
|
+
* const document = parse('{ greeting }');
|
|
82
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
83
|
+
* const error = new GraphQLError('Cannot query this field.', {
|
|
84
|
+
* nodes: fieldNode,
|
|
85
|
+
* path: ['greeting'],
|
|
86
|
+
* extensions: { code: 'FORBIDDEN' },
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* error.message; // => 'Cannot query this field.'
|
|
90
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
91
|
+
* error.path; // => ['greeting']
|
|
92
|
+
* error.extensions; // => { code: 'FORBIDDEN' }
|
|
93
|
+
* ```
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* // This variant derives locations from source positions and preserves the original error.
|
|
97
|
+
* import { Source } from 'graphql/language';
|
|
98
|
+
* import { GraphQLError } from 'graphql/error';
|
|
99
|
+
*
|
|
100
|
+
* const source = new Source('{ greeting }');
|
|
101
|
+
* const originalError = new Error('Database unavailable.');
|
|
102
|
+
* const error = new GraphQLError('Resolver failed.', {
|
|
103
|
+
* source,
|
|
104
|
+
* positions: [2],
|
|
105
|
+
* path: ['greeting'],
|
|
106
|
+
* originalError,
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
110
|
+
* error.path; // => ['greeting']
|
|
111
|
+
* error.originalError; // => originalError
|
|
112
|
+
* ```
|
|
72
113
|
*/
|
|
73
114
|
|
|
74
115
|
/**
|
|
116
|
+
* Creates a GraphQLError instance using the legacy positional constructor.
|
|
117
|
+
* This deprecated overload will be removed in v17. Prefer the
|
|
118
|
+
* `GraphQLErrorOptions` object overload, which keeps optional error metadata
|
|
119
|
+
* in a single options bag.
|
|
120
|
+
* @param message - Human-readable error message.
|
|
121
|
+
* @param nodes - AST node or nodes associated with this error.
|
|
122
|
+
* @param source - Source document used to derive error locations.
|
|
123
|
+
* @param positions - Character offsets in the source document associated with
|
|
124
|
+
* this error.
|
|
125
|
+
* @param path - Response path where this error occurred during execution.
|
|
126
|
+
* @param originalError - Original error that caused this GraphQLError, if one
|
|
127
|
+
* exists.
|
|
128
|
+
* @param extensions - Extension fields to include in the formatted error.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import { Source } from 'graphql/language';
|
|
132
|
+
* import { GraphQLError } from 'graphql/error';
|
|
133
|
+
*
|
|
134
|
+
* const source = new Source('{ greeting }');
|
|
135
|
+
* const originalError = new Error('Database unavailable.');
|
|
136
|
+
* const error = new GraphQLError(
|
|
137
|
+
* 'Resolver failed.',
|
|
138
|
+
* undefined,
|
|
139
|
+
* source,
|
|
140
|
+
* [2],
|
|
141
|
+
* ['greeting'],
|
|
142
|
+
* originalError,
|
|
143
|
+
* { code: 'INTERNAL' },
|
|
144
|
+
* );
|
|
145
|
+
*
|
|
146
|
+
* error.locations; // => [{ line: 1, column: 3 }]
|
|
147
|
+
* error.path; // => ['greeting']
|
|
148
|
+
* error.originalError; // => originalError
|
|
149
|
+
* error.extensions; // => { code: 'INTERNAL' }
|
|
150
|
+
* ```
|
|
75
151
|
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
|
|
76
152
|
*/
|
|
77
153
|
constructor(message, ...rawArgs) {
|
|
@@ -181,10 +257,30 @@ export class GraphQLError extends Error {
|
|
|
181
257
|
}
|
|
182
258
|
/* c8 ignore stop */
|
|
183
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
262
|
+
* @returns The built-in string tag for this object.
|
|
263
|
+
*/
|
|
184
264
|
|
|
185
265
|
get [Symbol.toStringTag]() {
|
|
186
266
|
return 'GraphQLError';
|
|
187
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Returns this error as a human-readable message with source locations.
|
|
270
|
+
* @returns The formatted error string.
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* import { Source } from 'graphql/language';
|
|
274
|
+
* import { GraphQLError } from 'graphql/error';
|
|
275
|
+
*
|
|
276
|
+
* const error = new GraphQLError('Cannot query field "name".', {
|
|
277
|
+
* source: new Source('{ name }'),
|
|
278
|
+
* positions: [2],
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* error.toString(); // => 'Cannot query field "name".\n\nGraphQL request:1:3\n1 | { name }\n | ^'
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
188
284
|
|
|
189
285
|
toString() {
|
|
190
286
|
let output = this.message;
|
|
@@ -203,6 +299,21 @@ export class GraphQLError extends Error {
|
|
|
203
299
|
|
|
204
300
|
return output;
|
|
205
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Returns the JSON representation used when this object is serialized.
|
|
304
|
+
* @returns The JSON-serializable representation.
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { GraphQLError } from 'graphql/error';
|
|
308
|
+
*
|
|
309
|
+
* const error = new GraphQLError('Resolver failed.', {
|
|
310
|
+
* path: ['viewer', 'name'],
|
|
311
|
+
* extensions: { code: 'INTERNAL' },
|
|
312
|
+
* });
|
|
313
|
+
*
|
|
314
|
+
* error.toJSON(); // => { message: 'Resolver failed.', path: ['viewer', 'name'], extensions: { code: 'INTERNAL' } }
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
206
317
|
|
|
207
318
|
toJSON() {
|
|
208
319
|
const formattedError = {
|
|
@@ -228,14 +339,23 @@ export class GraphQLError extends Error {
|
|
|
228
339
|
function undefinedIfEmpty(array) {
|
|
229
340
|
return array === undefined || array.length === 0 ? undefined : array;
|
|
230
341
|
}
|
|
231
|
-
/**
|
|
232
|
-
* See: https://spec.graphql.org/draft/#sec-Errors
|
|
233
|
-
*/
|
|
342
|
+
/** See: https://spec.graphql.org/draft/#sec-Errors */
|
|
234
343
|
|
|
235
344
|
/**
|
|
236
345
|
* Prints a GraphQLError to a string, representing useful location information
|
|
237
|
-
* about the error's position in the source.
|
|
346
|
+
* about the error's position in the source. This deprecated helper is retained
|
|
347
|
+
* for backwards compatibility; call `error.toString()` instead because
|
|
348
|
+
* printError will be removed in v17.
|
|
349
|
+
* @param error - The error to format.
|
|
350
|
+
* @returns The printed string representation.
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* import { GraphQLError, printError } from 'graphql/error';
|
|
354
|
+
*
|
|
355
|
+
* const message = printError(new GraphQLError('Example error'));
|
|
238
356
|
*
|
|
357
|
+
* message; // => 'Example error'
|
|
358
|
+
* ```
|
|
239
359
|
* @deprecated Please use `error.toString` instead. Will be removed in v17
|
|
240
360
|
*/
|
|
241
361
|
export function printError(error) {
|
|
@@ -243,8 +363,19 @@ export function printError(error) {
|
|
|
243
363
|
}
|
|
244
364
|
/**
|
|
245
365
|
* Given a GraphQLError, format it according to the rules described by the
|
|
246
|
-
* Response Format, Errors section of the GraphQL Specification.
|
|
366
|
+
* Response Format, Errors section of the GraphQL Specification. This deprecated
|
|
367
|
+
* helper is retained for backwards compatibility; call `error.toJSON()`
|
|
368
|
+
* instead because formatError will be removed in v17.
|
|
369
|
+
* @param error - The error to format.
|
|
370
|
+
* @returns The JSON-serializable formatted error.
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* import { GraphQLError, formatError } from 'graphql/error';
|
|
374
|
+
*
|
|
375
|
+
* const formatted = formatError(new GraphQLError('Example error'));
|
|
247
376
|
*
|
|
377
|
+
* formatted; // => { message: 'Example error' }
|
|
378
|
+
* ```
|
|
248
379
|
* @deprecated Please use `error.toJSON` instead. Will be removed in v17
|
|
249
380
|
*/
|
|
250
381
|
|
package/error/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create, format, and locate GraphQL errors.
|
|
3
|
+
*
|
|
4
|
+
* These exports are also available from the root `graphql` package.
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
1
7
|
export { GraphQLError, printError, formatError } from './GraphQLError';
|
|
2
8
|
export type {
|
|
3
9
|
GraphQLErrorOptions,
|
package/error/index.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create, format, and locate GraphQL errors.
|
|
3
|
+
*
|
|
4
|
+
* These exports are also available from the root `graphql` package.
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
1
7
|
export { GraphQLError, printError, formatError } from './GraphQLError.mjs';
|
|
2
8
|
export { syntaxError } from './syntaxError.mjs';
|
|
3
9
|
export { locatedError } from './locatedError.mjs';
|