@graphql-tools/utils 8.5.2 → 8.5.3
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/AggregateError.d.ts +1 -0
- package/executor.d.ts +3 -3
- package/index.js +35 -17
- package/index.mjs +36 -19
- package/isAsyncIterable.d.ts +1 -1
- package/package.json +1 -1
package/AggregateError.d.ts
CHANGED
package/executor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutionResult, ExecutionRequest } from './Interfaces';
|
|
2
2
|
declare type MaybePromise<T> = Promise<T> | T;
|
|
3
|
-
declare type
|
|
4
|
-
export declare type AsyncExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions>) => Promise<
|
|
3
|
+
declare type MaybeAsyncIterable<T> = AsyncIterable<T> | T;
|
|
4
|
+
export declare type AsyncExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions>) => Promise<MaybeAsyncIterable<ExecutionResult<TReturn>>>;
|
|
5
5
|
export declare type SyncExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions>) => ExecutionResult<TReturn>;
|
|
6
|
-
export declare type Executor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions>) => MaybePromise<
|
|
6
|
+
export declare type Executor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions>) => MaybePromise<MaybeAsyncIterable<ExecutionResult<TReturn>>>;
|
|
7
7
|
export {};
|
package/index.js
CHANGED
|
@@ -69,8 +69,25 @@ function assertSome(input, message = 'Value should be something') {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
exports.AggregateError = globalThis.AggregateError;
|
|
73
|
+
if (typeof exports.AggregateError === 'undefined') {
|
|
74
|
+
class AggregateErrorClass extends Error {
|
|
75
|
+
constructor(errors, message = '') {
|
|
76
|
+
super(message);
|
|
77
|
+
this.errors = errors;
|
|
78
|
+
this.name = 'AggregateError';
|
|
79
|
+
Error.captureStackTrace(this, AggregateErrorClass);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.AggregateError = function (errors, message) {
|
|
83
|
+
return new AggregateErrorClass(errors, message);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function isAggregateError(error) {
|
|
87
|
+
return 'errors' in error && Array.isArray(error['errors']);
|
|
88
|
+
}
|
|
89
|
+
|
|
72
90
|
// Taken from graphql-js
|
|
73
|
-
// https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
|
|
74
91
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
75
92
|
const MAX_ARRAY_LENGTH = 10;
|
|
76
93
|
const MAX_RECURSIVE_DEPTH = 2;
|
|
@@ -92,10 +109,22 @@ function formatValue(value, seenValues) {
|
|
|
92
109
|
return String(value);
|
|
93
110
|
}
|
|
94
111
|
}
|
|
112
|
+
function formatError(value) {
|
|
113
|
+
if (value instanceof graphql.GraphQLError) {
|
|
114
|
+
return value.toString();
|
|
115
|
+
}
|
|
116
|
+
return `${value.name}: ${value.message};\n ${value.stack}`;
|
|
117
|
+
}
|
|
95
118
|
function formatObjectValue(value, previouslySeenValues) {
|
|
96
119
|
if (value === null) {
|
|
97
120
|
return 'null';
|
|
98
121
|
}
|
|
122
|
+
if (value instanceof Error) {
|
|
123
|
+
if (isAggregateError(value)) {
|
|
124
|
+
return formatError(value) + '\n' + formatArray(value.errors, previouslySeenValues);
|
|
125
|
+
}
|
|
126
|
+
return formatError(value);
|
|
127
|
+
}
|
|
99
128
|
if (previouslySeenValues.includes(value)) {
|
|
100
129
|
return '[Circular]';
|
|
101
130
|
}
|
|
@@ -1164,21 +1193,6 @@ function makeDirectiveNodes(schema, directiveValues) {
|
|
|
1164
1193
|
return directiveNodes;
|
|
1165
1194
|
}
|
|
1166
1195
|
|
|
1167
|
-
exports.AggregateError = globalThis.AggregateError;
|
|
1168
|
-
if (typeof exports.AggregateError === 'undefined') {
|
|
1169
|
-
class AggregateErrorClass extends Error {
|
|
1170
|
-
constructor(errors, message = '') {
|
|
1171
|
-
super(message);
|
|
1172
|
-
this.errors = errors;
|
|
1173
|
-
this.name = 'AggregateError';
|
|
1174
|
-
Error.captureStackTrace(this, AggregateErrorClass);
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
exports.AggregateError = function (errors, message) {
|
|
1178
|
-
return new AggregateErrorClass(errors, message);
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
1196
|
async function validateGraphQlDocuments(schema, documentFiles, effectiveRules = createDefaultRules()) {
|
|
1183
1197
|
const allFragmentMap = new Map();
|
|
1184
1198
|
const documentFileObjectsToValidate = [];
|
|
@@ -4152,7 +4166,10 @@ function valueMatchesCriteria(value, criteria) {
|
|
|
4152
4166
|
}
|
|
4153
4167
|
|
|
4154
4168
|
function isAsyncIterable(value) {
|
|
4155
|
-
return typeof value === 'object' &&
|
|
4169
|
+
return (typeof value === 'object' &&
|
|
4170
|
+
value != null &&
|
|
4171
|
+
Symbol.asyncIterator in value &&
|
|
4172
|
+
typeof value[Symbol.asyncIterator] === 'function');
|
|
4156
4173
|
}
|
|
4157
4174
|
|
|
4158
4175
|
function isDocumentNode(object) {
|
|
@@ -4254,6 +4271,7 @@ exports.healSchema = healSchema;
|
|
|
4254
4271
|
exports.healTypes = healTypes;
|
|
4255
4272
|
exports.implementsAbstractType = implementsAbstractType;
|
|
4256
4273
|
exports.inspect = inspect;
|
|
4274
|
+
exports.isAggregateError = isAggregateError;
|
|
4257
4275
|
exports.isAsyncIterable = isAsyncIterable;
|
|
4258
4276
|
exports.isDescribable = isDescribable;
|
|
4259
4277
|
exports.isDocumentNode = isDocumentNode;
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parse,
|
|
1
|
+
import { parse, GraphQLError, isNonNullType, Kind, valueFromAST, print, isObjectType, isListType, isSpecifiedDirective, astFromValue, isSpecifiedScalarType, isIntrospectionType, isInterfaceType, isUnionType, isInputObjectType, isEnumType, isScalarType, GraphQLDeprecatedDirective, specifiedRules, concatAST, validate, versionInfo, 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, getOperationRootType, 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,8 +65,25 @@ function assertSome(input, message = 'Value should be something') {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
let AggregateErrorImpl = globalThis.AggregateError;
|
|
69
|
+
if (typeof AggregateErrorImpl === 'undefined') {
|
|
70
|
+
class AggregateErrorClass extends Error {
|
|
71
|
+
constructor(errors, message = '') {
|
|
72
|
+
super(message);
|
|
73
|
+
this.errors = errors;
|
|
74
|
+
this.name = 'AggregateError';
|
|
75
|
+
Error.captureStackTrace(this, AggregateErrorClass);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
AggregateErrorImpl = function (errors, message) {
|
|
79
|
+
return new AggregateErrorClass(errors, message);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function isAggregateError(error) {
|
|
83
|
+
return 'errors' in error && Array.isArray(error['errors']);
|
|
84
|
+
}
|
|
85
|
+
|
|
68
86
|
// Taken from graphql-js
|
|
69
|
-
// https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
|
|
70
87
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
71
88
|
const MAX_ARRAY_LENGTH = 10;
|
|
72
89
|
const MAX_RECURSIVE_DEPTH = 2;
|
|
@@ -88,10 +105,22 @@ function formatValue(value, seenValues) {
|
|
|
88
105
|
return String(value);
|
|
89
106
|
}
|
|
90
107
|
}
|
|
108
|
+
function formatError(value) {
|
|
109
|
+
if (value instanceof GraphQLError) {
|
|
110
|
+
return value.toString();
|
|
111
|
+
}
|
|
112
|
+
return `${value.name}: ${value.message};\n ${value.stack}`;
|
|
113
|
+
}
|
|
91
114
|
function formatObjectValue(value, previouslySeenValues) {
|
|
92
115
|
if (value === null) {
|
|
93
116
|
return 'null';
|
|
94
117
|
}
|
|
118
|
+
if (value instanceof Error) {
|
|
119
|
+
if (isAggregateError(value)) {
|
|
120
|
+
return formatError(value) + '\n' + formatArray(value.errors, previouslySeenValues);
|
|
121
|
+
}
|
|
122
|
+
return formatError(value);
|
|
123
|
+
}
|
|
95
124
|
if (previouslySeenValues.includes(value)) {
|
|
96
125
|
return '[Circular]';
|
|
97
126
|
}
|
|
@@ -1160,21 +1189,6 @@ function makeDirectiveNodes(schema, directiveValues) {
|
|
|
1160
1189
|
return directiveNodes;
|
|
1161
1190
|
}
|
|
1162
1191
|
|
|
1163
|
-
let AggregateErrorImpl = globalThis.AggregateError;
|
|
1164
|
-
if (typeof AggregateErrorImpl === 'undefined') {
|
|
1165
|
-
class AggregateErrorClass extends Error {
|
|
1166
|
-
constructor(errors, message = '') {
|
|
1167
|
-
super(message);
|
|
1168
|
-
this.errors = errors;
|
|
1169
|
-
this.name = 'AggregateError';
|
|
1170
|
-
Error.captureStackTrace(this, AggregateErrorClass);
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
AggregateErrorImpl = function (errors, message) {
|
|
1174
|
-
return new AggregateErrorClass(errors, message);
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
1192
|
async function validateGraphQlDocuments(schema, documentFiles, effectiveRules = createDefaultRules()) {
|
|
1179
1193
|
const allFragmentMap = new Map();
|
|
1180
1194
|
const documentFileObjectsToValidate = [];
|
|
@@ -4149,7 +4163,10 @@ function valueMatchesCriteria(value, criteria) {
|
|
|
4149
4163
|
}
|
|
4150
4164
|
|
|
4151
4165
|
function isAsyncIterable(value) {
|
|
4152
|
-
return typeof value === 'object' &&
|
|
4166
|
+
return (typeof value === 'object' &&
|
|
4167
|
+
value != null &&
|
|
4168
|
+
Symbol.asyncIterator in value &&
|
|
4169
|
+
typeof value[Symbol.asyncIterator] === 'function');
|
|
4153
4170
|
}
|
|
4154
4171
|
|
|
4155
4172
|
function isDocumentNode(object) {
|
|
@@ -4190,4 +4207,4 @@ function fixSchemaAst(schema, options) {
|
|
|
4190
4207
|
return schema;
|
|
4191
4208
|
}
|
|
4192
4209
|
|
|
4193
|
-
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, 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, 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, withCancel };
|
|
4210
|
+
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, 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, withCancel };
|
package/isAsyncIterable.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isAsyncIterable<T>(value: any): value is
|
|
1
|
+
export declare function isAsyncIterable<T>(value: any): value is AsyncIterable<T>;
|