@graphql-tools/utils 8.6.11 → 8.6.12-alpha-a2f32d26.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/createGraphQLError.d.ts +14 -0
- package/errors.d.ts +14 -1
- package/index.js +47 -6
- package/index.mjs +48 -8
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ASTNode, GraphQLError, GraphQLErrorExtensions, Source } from 'graphql';
|
|
2
|
+
import { Maybe } from './types';
|
|
3
|
+
interface GraphQLErrorOptions {
|
|
4
|
+
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
|
|
5
|
+
source?: Maybe<Source>;
|
|
6
|
+
positions?: Maybe<ReadonlyArray<number>>;
|
|
7
|
+
path?: Maybe<ReadonlyArray<string | number>>;
|
|
8
|
+
originalError?: Maybe<Error & {
|
|
9
|
+
readonly extensions?: unknown;
|
|
10
|
+
}>;
|
|
11
|
+
extensions?: Maybe<GraphQLErrorExtensions>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createGraphQLError(message: string, options: GraphQLErrorOptions): GraphQLError;
|
|
14
|
+
export {};
|
package/errors.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
import { GraphQLError } from 'graphql';
|
|
1
|
+
import { ASTNode, GraphQLError, GraphQLErrorExtensions, Source } from 'graphql';
|
|
2
|
+
import { Maybe } from './types';
|
|
3
|
+
interface GraphQLErrorOptions {
|
|
4
|
+
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
|
|
5
|
+
source?: Maybe<Source>;
|
|
6
|
+
positions?: Maybe<ReadonlyArray<number>>;
|
|
7
|
+
path?: Maybe<ReadonlyArray<string | number>>;
|
|
8
|
+
originalError?: Maybe<Error & {
|
|
9
|
+
readonly extensions?: unknown;
|
|
10
|
+
}>;
|
|
11
|
+
extensions?: Maybe<GraphQLErrorExtensions>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createGraphQLError(message: string, options: GraphQLErrorOptions): GraphQLError;
|
|
2
14
|
export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>): GraphQLError;
|
|
15
|
+
export {};
|
package/index.js
CHANGED
|
@@ -69,6 +69,19 @@ function assertSome(input, message = 'Value should be something') {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
function createGraphQLError(message, options) {
|
|
73
|
+
if (graphql.versionInfo.major > 15) {
|
|
74
|
+
const error = new graphql.GraphQLError(message, options);
|
|
75
|
+
Object.defineProperty(error, 'extensions', {
|
|
76
|
+
value: options.extensions || {},
|
|
77
|
+
});
|
|
78
|
+
return error;
|
|
79
|
+
}
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
return new graphql.GraphQLError(message, options.nodes, options.source, options.positions, options.path, options.originalError, options.extensions);
|
|
83
|
+
}
|
|
84
|
+
|
|
72
85
|
if (typeof AggregateError === 'undefined') {
|
|
73
86
|
class AggregateErrorClass extends Error {
|
|
74
87
|
constructor(errors, message = '') {
|
|
@@ -217,7 +230,9 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
217
230
|
coercedValues[name] = defaultValue;
|
|
218
231
|
}
|
|
219
232
|
else if (graphql.isNonNullType(argType)) {
|
|
220
|
-
throw
|
|
233
|
+
throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', {
|
|
234
|
+
nodes: [node],
|
|
235
|
+
});
|
|
221
236
|
}
|
|
222
237
|
continue;
|
|
223
238
|
}
|
|
@@ -230,22 +245,28 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
230
245
|
coercedValues[name] = defaultValue;
|
|
231
246
|
}
|
|
232
247
|
else if (graphql.isNonNullType(argType)) {
|
|
233
|
-
throw
|
|
234
|
-
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
|
|
248
|
+
throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
|
|
249
|
+
`was provided the variable "$${variableName}" which was not provided a runtime value.`, {
|
|
250
|
+
nodes: [valueNode],
|
|
251
|
+
});
|
|
235
252
|
}
|
|
236
253
|
continue;
|
|
237
254
|
}
|
|
238
255
|
isNull = variableValues[variableName] == null;
|
|
239
256
|
}
|
|
240
257
|
if (isNull && graphql.isNonNullType(argType)) {
|
|
241
|
-
throw
|
|
258
|
+
throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', {
|
|
259
|
+
nodes: [valueNode],
|
|
260
|
+
});
|
|
242
261
|
}
|
|
243
262
|
const coercedValue = graphql.valueFromAST(valueNode, argType, variableValues);
|
|
244
263
|
if (coercedValue === undefined) {
|
|
245
264
|
// Note: ValuesOfCorrectTypeRule validation should catch this before
|
|
246
265
|
// execution. This is a runtime check to ensure execution does not
|
|
247
266
|
// continue with an invalid argument value.
|
|
248
|
-
throw
|
|
267
|
+
throw createGraphQLError(`Argument "${name}" has invalid value ${graphql.print(valueNode)}.`, {
|
|
268
|
+
nodes: [valueNode],
|
|
269
|
+
});
|
|
249
270
|
}
|
|
250
271
|
coercedValues[name] = coercedValue;
|
|
251
272
|
}
|
|
@@ -3758,8 +3779,27 @@ function implementsAbstractType(schema, typeA, typeB) {
|
|
|
3758
3779
|
return false;
|
|
3759
3780
|
}
|
|
3760
3781
|
|
|
3782
|
+
function createGraphQLError$1(message, options) {
|
|
3783
|
+
if (graphql.versionInfo.major > 15) {
|
|
3784
|
+
const error = new graphql.GraphQLError(message, options);
|
|
3785
|
+
Object.defineProperty(error, 'extensions', {
|
|
3786
|
+
value: options.extensions || {},
|
|
3787
|
+
});
|
|
3788
|
+
return error;
|
|
3789
|
+
}
|
|
3790
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3791
|
+
// @ts-ignore
|
|
3792
|
+
return new graphql.GraphQLError(message, options.nodes, options.source, options.positions, options.path, options.originalError, options.extensions);
|
|
3793
|
+
}
|
|
3761
3794
|
function relocatedError(originalError, path) {
|
|
3762
|
-
return
|
|
3795
|
+
return createGraphQLError$1(originalError.message, {
|
|
3796
|
+
nodes: originalError.nodes,
|
|
3797
|
+
source: originalError.source,
|
|
3798
|
+
positions: originalError.positions,
|
|
3799
|
+
path: path == null ? originalError.path : path,
|
|
3800
|
+
originalError,
|
|
3801
|
+
extensions: originalError.extensions,
|
|
3802
|
+
});
|
|
3763
3803
|
}
|
|
3764
3804
|
|
|
3765
3805
|
function observableToAsyncIterable(observable) {
|
|
@@ -4285,6 +4325,7 @@ exports.compareNodes = compareNodes;
|
|
|
4285
4325
|
exports.compareStrings = compareStrings;
|
|
4286
4326
|
exports.correctASTNodes = correctASTNodes;
|
|
4287
4327
|
exports.createDefaultRules = createDefaultRules;
|
|
4328
|
+
exports.createGraphQLError = createGraphQLError$1;
|
|
4288
4329
|
exports.createNamedStub = createNamedStub;
|
|
4289
4330
|
exports.createStub = createStub;
|
|
4290
4331
|
exports.createVariableNameGenerator = createVariableNameGenerator;
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parse, GraphQLError, isNonNullType, Kind, valueFromAST, print, isObjectType, isListType, isSpecifiedDirective, astFromValue, isSpecifiedScalarType, isIntrospectionType, isInterfaceType, isUnionType, isInputObjectType, isEnumType, isScalarType, GraphQLDeprecatedDirective, specifiedRules, concatAST, validate,
|
|
1
|
+
import { parse, versionInfo, GraphQLError, isNonNullType, Kind, valueFromAST, print, isObjectType, isListType, isSpecifiedDirective, astFromValue, isSpecifiedScalarType, isIntrospectionType, isInterfaceType, isUnionType, isInputObjectType, isEnumType, isScalarType, GraphQLDeprecatedDirective, specifiedRules, concatAST, validate, buildClientSchema, visit, TokenKind, Source, isTypeSystemDefinitionNode, getNamedType, GraphQLString, GraphQLNonNull, GraphQLList, GraphQLID, GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLObjectType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLDirective, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, isNamedType, getNullableType, isLeafType, GraphQLSchema, isDirective, isCompositeType, doTypesOverlap, getOperationAST, getDirectiveValues, GraphQLSkipDirective, GraphQLIncludeDirective, typeFromAST, isAbstractType, TypeNameMetaFieldDef, buildASTSchema } from 'graphql';
|
|
2
2
|
|
|
3
3
|
const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
|
|
4
4
|
const invalidDocRegex = /\.[a-z0-9]+$/i;
|
|
@@ -65,6 +65,19 @@ function assertSome(input, message = 'Value should be something') {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
function createGraphQLError(message, options) {
|
|
69
|
+
if (versionInfo.major > 15) {
|
|
70
|
+
const error = new GraphQLError(message, options);
|
|
71
|
+
Object.defineProperty(error, 'extensions', {
|
|
72
|
+
value: options.extensions || {},
|
|
73
|
+
});
|
|
74
|
+
return error;
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
return new GraphQLError(message, options.nodes, options.source, options.positions, options.path, options.originalError, options.extensions);
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
let AggregateErrorImpl;
|
|
69
82
|
if (typeof AggregateError === 'undefined') {
|
|
70
83
|
class AggregateErrorClass extends Error {
|
|
@@ -214,7 +227,9 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
214
227
|
coercedValues[name] = defaultValue;
|
|
215
228
|
}
|
|
216
229
|
else if (isNonNullType(argType)) {
|
|
217
|
-
throw
|
|
230
|
+
throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', {
|
|
231
|
+
nodes: [node],
|
|
232
|
+
});
|
|
218
233
|
}
|
|
219
234
|
continue;
|
|
220
235
|
}
|
|
@@ -227,22 +242,28 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
227
242
|
coercedValues[name] = defaultValue;
|
|
228
243
|
}
|
|
229
244
|
else if (isNonNullType(argType)) {
|
|
230
|
-
throw
|
|
231
|
-
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
|
|
245
|
+
throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
|
|
246
|
+
`was provided the variable "$${variableName}" which was not provided a runtime value.`, {
|
|
247
|
+
nodes: [valueNode],
|
|
248
|
+
});
|
|
232
249
|
}
|
|
233
250
|
continue;
|
|
234
251
|
}
|
|
235
252
|
isNull = variableValues[variableName] == null;
|
|
236
253
|
}
|
|
237
254
|
if (isNull && isNonNullType(argType)) {
|
|
238
|
-
throw
|
|
255
|
+
throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', {
|
|
256
|
+
nodes: [valueNode],
|
|
257
|
+
});
|
|
239
258
|
}
|
|
240
259
|
const coercedValue = valueFromAST(valueNode, argType, variableValues);
|
|
241
260
|
if (coercedValue === undefined) {
|
|
242
261
|
// Note: ValuesOfCorrectTypeRule validation should catch this before
|
|
243
262
|
// execution. This is a runtime check to ensure execution does not
|
|
244
263
|
// continue with an invalid argument value.
|
|
245
|
-
throw
|
|
264
|
+
throw createGraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, {
|
|
265
|
+
nodes: [valueNode],
|
|
266
|
+
});
|
|
246
267
|
}
|
|
247
268
|
coercedValues[name] = coercedValue;
|
|
248
269
|
}
|
|
@@ -3756,8 +3777,27 @@ function implementsAbstractType(schema, typeA, typeB) {
|
|
|
3756
3777
|
return false;
|
|
3757
3778
|
}
|
|
3758
3779
|
|
|
3780
|
+
function createGraphQLError$1(message, options) {
|
|
3781
|
+
if (versionInfo.major > 15) {
|
|
3782
|
+
const error = new GraphQLError(message, options);
|
|
3783
|
+
Object.defineProperty(error, 'extensions', {
|
|
3784
|
+
value: options.extensions || {},
|
|
3785
|
+
});
|
|
3786
|
+
return error;
|
|
3787
|
+
}
|
|
3788
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3789
|
+
// @ts-ignore
|
|
3790
|
+
return new GraphQLError(message, options.nodes, options.source, options.positions, options.path, options.originalError, options.extensions);
|
|
3791
|
+
}
|
|
3759
3792
|
function relocatedError(originalError, path) {
|
|
3760
|
-
return
|
|
3793
|
+
return createGraphQLError$1(originalError.message, {
|
|
3794
|
+
nodes: originalError.nodes,
|
|
3795
|
+
source: originalError.source,
|
|
3796
|
+
positions: originalError.positions,
|
|
3797
|
+
path: path == null ? originalError.path : path,
|
|
3798
|
+
originalError,
|
|
3799
|
+
extensions: originalError.extensions,
|
|
3800
|
+
});
|
|
3761
3801
|
}
|
|
3762
3802
|
|
|
3763
3803
|
function observableToAsyncIterable(observable) {
|
|
@@ -4257,4 +4297,4 @@ function fixSchemaAst(schema, options) {
|
|
|
4257
4297
|
return schema;
|
|
4258
4298
|
}
|
|
4259
4299
|
|
|
4260
|
-
export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, collectFields, collectSubFields, compareNodes, compareStrings, correctASTNodes, createDefaultRules, createNamedStub, createStub, createVariableNameGenerator, dedentBlockStringValue, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getAsyncIterableWithCancel, getAsyncIteratorWithCancel, getBlockStringIndentation, getBuiltInForStub, getComment, getDefinedRootType, getDeprecatableDirectiveNodes, getDescription, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getOperationASTFromDocument, getOperationASTFromRequest, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, healSchema, healTypes, implementsAbstractType, inspect, isAggregateError, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isNamedStub, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, memoize1, memoize2, memoize2of4, memoize3, memoize4, memoize5, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, getAsyncIterableWithCancel as withCancel };
|
|
4300
|
+
export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, collectFields, collectSubFields, compareNodes, compareStrings, correctASTNodes, createDefaultRules, createGraphQLError$1 as createGraphQLError, createNamedStub, createStub, createVariableNameGenerator, dedentBlockStringValue, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getAsyncIterableWithCancel, getAsyncIteratorWithCancel, getBlockStringIndentation, getBuiltInForStub, getComment, getDefinedRootType, getDeprecatableDirectiveNodes, getDescription, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getOperationASTFromDocument, getOperationASTFromRequest, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, healSchema, healTypes, implementsAbstractType, inspect, isAggregateError, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isNamedStub, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, memoize1, memoize2, memoize2of4, memoize3, memoize4, memoize5, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, getAsyncIterableWithCancel as withCancel };
|