@graphql-tools/utils 8.6.11 → 8.6.12-alpha-2e27df80.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/errors.d.ts CHANGED
@@ -1,2 +1,15 @@
1
- import { GraphQLError } from 'graphql';
1
+ import { ASTNode, GraphQLError, 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?: any;
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,27 @@ 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
+ return new graphql.GraphQLError(message, options.nodes, options.source, options.positions, options.path, options.originalError, options.extensions);
81
+ }
82
+ function relocatedError(originalError, path) {
83
+ return createGraphQLError(originalError.message, {
84
+ nodes: originalError.nodes,
85
+ source: originalError.source,
86
+ positions: originalError.positions,
87
+ path: path == null ? originalError.path : path,
88
+ originalError,
89
+ extensions: originalError.extensions,
90
+ });
91
+ }
92
+
72
93
  if (typeof AggregateError === 'undefined') {
73
94
  class AggregateErrorClass extends Error {
74
95
  constructor(errors, message = '') {
@@ -217,7 +238,9 @@ function getArgumentValues(def, node, variableValues = {}) {
217
238
  coercedValues[name] = defaultValue;
218
239
  }
219
240
  else if (graphql.isNonNullType(argType)) {
220
- throw new graphql.GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', node);
241
+ throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', {
242
+ nodes: [node],
243
+ });
221
244
  }
222
245
  continue;
223
246
  }
@@ -230,22 +253,28 @@ function getArgumentValues(def, node, variableValues = {}) {
230
253
  coercedValues[name] = defaultValue;
231
254
  }
232
255
  else if (graphql.isNonNullType(argType)) {
233
- throw new graphql.GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
234
- `was provided the variable "$${variableName}" which was not provided a runtime value.`, valueNode);
256
+ throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
257
+ `was provided the variable "$${variableName}" which was not provided a runtime value.`, {
258
+ nodes: [valueNode],
259
+ });
235
260
  }
236
261
  continue;
237
262
  }
238
263
  isNull = variableValues[variableName] == null;
239
264
  }
240
265
  if (isNull && graphql.isNonNullType(argType)) {
241
- throw new graphql.GraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', valueNode);
266
+ throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', {
267
+ nodes: [valueNode],
268
+ });
242
269
  }
243
270
  const coercedValue = graphql.valueFromAST(valueNode, argType, variableValues);
244
271
  if (coercedValue === undefined) {
245
272
  // Note: ValuesOfCorrectTypeRule validation should catch this before
246
273
  // execution. This is a runtime check to ensure execution does not
247
274
  // continue with an invalid argument value.
248
- throw new graphql.GraphQLError(`Argument "${name}" has invalid value ${graphql.print(valueNode)}.`, valueNode);
275
+ throw createGraphQLError(`Argument "${name}" has invalid value ${graphql.print(valueNode)}.`, {
276
+ nodes: [valueNode],
277
+ });
249
278
  }
250
279
  coercedValues[name] = coercedValue;
251
280
  }
@@ -2091,6 +2120,30 @@ function hasCircularRef(types, config = {
2091
2120
  return size > config.depth;
2092
2121
  }
2093
2122
 
2123
+ (function (DirectiveLocation) {
2124
+ /** Request Definitions */
2125
+ DirectiveLocation["QUERY"] = "QUERY";
2126
+ DirectiveLocation["MUTATION"] = "MUTATION";
2127
+ DirectiveLocation["SUBSCRIPTION"] = "SUBSCRIPTION";
2128
+ DirectiveLocation["FIELD"] = "FIELD";
2129
+ DirectiveLocation["FRAGMENT_DEFINITION"] = "FRAGMENT_DEFINITION";
2130
+ DirectiveLocation["FRAGMENT_SPREAD"] = "FRAGMENT_SPREAD";
2131
+ DirectiveLocation["INLINE_FRAGMENT"] = "INLINE_FRAGMENT";
2132
+ DirectiveLocation["VARIABLE_DEFINITION"] = "VARIABLE_DEFINITION";
2133
+ /** Type System Definitions */
2134
+ DirectiveLocation["SCHEMA"] = "SCHEMA";
2135
+ DirectiveLocation["SCALAR"] = "SCALAR";
2136
+ DirectiveLocation["OBJECT"] = "OBJECT";
2137
+ DirectiveLocation["FIELD_DEFINITION"] = "FIELD_DEFINITION";
2138
+ DirectiveLocation["ARGUMENT_DEFINITION"] = "ARGUMENT_DEFINITION";
2139
+ DirectiveLocation["INTERFACE"] = "INTERFACE";
2140
+ DirectiveLocation["UNION"] = "UNION";
2141
+ DirectiveLocation["ENUM"] = "ENUM";
2142
+ DirectiveLocation["ENUM_VALUE"] = "ENUM_VALUE";
2143
+ DirectiveLocation["INPUT_OBJECT"] = "INPUT_OBJECT";
2144
+ DirectiveLocation["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION";
2145
+ })(exports.DirectiveLocation || (exports.DirectiveLocation = {}));
2146
+
2094
2147
  (function (MapperKind) {
2095
2148
  MapperKind["TYPE"] = "MapperKind.TYPE";
2096
2149
  MapperKind["SCALAR_TYPE"] = "MapperKind.SCALAR_TYPE";
@@ -3758,10 +3811,6 @@ function implementsAbstractType(schema, typeA, typeB) {
3758
3811
  return false;
3759
3812
  }
3760
3813
 
3761
- function relocatedError(originalError, path) {
3762
- return new graphql.GraphQLError(originalError.message, originalError.nodes, originalError.source, originalError.positions, path === null ? undefined : path === undefined ? originalError.path : path, originalError.originalError, originalError.extensions);
3763
- }
3764
-
3765
3814
  function observableToAsyncIterable(observable) {
3766
3815
  const pullQueue = [];
3767
3816
  const pushQueue = [];
@@ -4285,6 +4334,7 @@ exports.compareNodes = compareNodes;
4285
4334
  exports.compareStrings = compareStrings;
4286
4335
  exports.correctASTNodes = correctASTNodes;
4287
4336
  exports.createDefaultRules = createDefaultRules;
4337
+ exports.createGraphQLError = createGraphQLError;
4288
4338
  exports.createNamedStub = createNamedStub;
4289
4339
  exports.createStub = createStub;
4290
4340
  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, 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, TypeNameMetaFieldDef, buildASTSchema } from 'graphql';
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,27 @@ 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
+ return new GraphQLError(message, options.nodes, options.source, options.positions, options.path, options.originalError, options.extensions);
77
+ }
78
+ function relocatedError(originalError, path) {
79
+ return createGraphQLError(originalError.message, {
80
+ nodes: originalError.nodes,
81
+ source: originalError.source,
82
+ positions: originalError.positions,
83
+ path: path == null ? originalError.path : path,
84
+ originalError,
85
+ extensions: originalError.extensions,
86
+ });
87
+ }
88
+
68
89
  let AggregateErrorImpl;
69
90
  if (typeof AggregateError === 'undefined') {
70
91
  class AggregateErrorClass extends Error {
@@ -214,7 +235,9 @@ function getArgumentValues(def, node, variableValues = {}) {
214
235
  coercedValues[name] = defaultValue;
215
236
  }
216
237
  else if (isNonNullType(argType)) {
217
- throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', node);
238
+ throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', {
239
+ nodes: [node],
240
+ });
218
241
  }
219
242
  continue;
220
243
  }
@@ -227,22 +250,28 @@ function getArgumentValues(def, node, variableValues = {}) {
227
250
  coercedValues[name] = defaultValue;
228
251
  }
229
252
  else if (isNonNullType(argType)) {
230
- throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
231
- `was provided the variable "$${variableName}" which was not provided a runtime value.`, valueNode);
253
+ throw createGraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
254
+ `was provided the variable "$${variableName}" which was not provided a runtime value.`, {
255
+ nodes: [valueNode],
256
+ });
232
257
  }
233
258
  continue;
234
259
  }
235
260
  isNull = variableValues[variableName] == null;
236
261
  }
237
262
  if (isNull && isNonNullType(argType)) {
238
- throw new GraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', valueNode);
263
+ throw createGraphQLError(`Argument "${name}" of non-null type "${inspect(argType)}" ` + 'must not be null.', {
264
+ nodes: [valueNode],
265
+ });
239
266
  }
240
267
  const coercedValue = valueFromAST(valueNode, argType, variableValues);
241
268
  if (coercedValue === undefined) {
242
269
  // Note: ValuesOfCorrectTypeRule validation should catch this before
243
270
  // execution. This is a runtime check to ensure execution does not
244
271
  // continue with an invalid argument value.
245
- throw new GraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, valueNode);
272
+ throw createGraphQLError(`Argument "${name}" has invalid value ${print(valueNode)}.`, {
273
+ nodes: [valueNode],
274
+ });
246
275
  }
247
276
  coercedValues[name] = coercedValue;
248
277
  }
@@ -2088,6 +2117,31 @@ function hasCircularRef(types, config = {
2088
2117
  return size > config.depth;
2089
2118
  }
2090
2119
 
2120
+ var DirectiveLocation;
2121
+ (function (DirectiveLocation) {
2122
+ /** Request Definitions */
2123
+ DirectiveLocation["QUERY"] = "QUERY";
2124
+ DirectiveLocation["MUTATION"] = "MUTATION";
2125
+ DirectiveLocation["SUBSCRIPTION"] = "SUBSCRIPTION";
2126
+ DirectiveLocation["FIELD"] = "FIELD";
2127
+ DirectiveLocation["FRAGMENT_DEFINITION"] = "FRAGMENT_DEFINITION";
2128
+ DirectiveLocation["FRAGMENT_SPREAD"] = "FRAGMENT_SPREAD";
2129
+ DirectiveLocation["INLINE_FRAGMENT"] = "INLINE_FRAGMENT";
2130
+ DirectiveLocation["VARIABLE_DEFINITION"] = "VARIABLE_DEFINITION";
2131
+ /** Type System Definitions */
2132
+ DirectiveLocation["SCHEMA"] = "SCHEMA";
2133
+ DirectiveLocation["SCALAR"] = "SCALAR";
2134
+ DirectiveLocation["OBJECT"] = "OBJECT";
2135
+ DirectiveLocation["FIELD_DEFINITION"] = "FIELD_DEFINITION";
2136
+ DirectiveLocation["ARGUMENT_DEFINITION"] = "ARGUMENT_DEFINITION";
2137
+ DirectiveLocation["INTERFACE"] = "INTERFACE";
2138
+ DirectiveLocation["UNION"] = "UNION";
2139
+ DirectiveLocation["ENUM"] = "ENUM";
2140
+ DirectiveLocation["ENUM_VALUE"] = "ENUM_VALUE";
2141
+ DirectiveLocation["INPUT_OBJECT"] = "INPUT_OBJECT";
2142
+ DirectiveLocation["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION";
2143
+ })(DirectiveLocation || (DirectiveLocation = {}));
2144
+
2091
2145
  var MapperKind;
2092
2146
  (function (MapperKind) {
2093
2147
  MapperKind["TYPE"] = "MapperKind.TYPE";
@@ -3756,10 +3810,6 @@ function implementsAbstractType(schema, typeA, typeB) {
3756
3810
  return false;
3757
3811
  }
3758
3812
 
3759
- function relocatedError(originalError, path) {
3760
- return new GraphQLError(originalError.message, originalError.nodes, originalError.source, originalError.positions, path === null ? undefined : path === undefined ? originalError.path : path, originalError.originalError, originalError.extensions);
3761
- }
3762
-
3763
3813
  function observableToAsyncIterable(observable) {
3764
3814
  const pullQueue = [];
3765
3815
  const pushQueue = [];
@@ -4257,4 +4307,4 @@ function fixSchemaAst(schema, options) {
4257
4307
  return schema;
4258
4308
  }
4259
4309
 
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 };
4310
+ export { AggregateErrorImpl as AggregateError, DirectiveLocation, 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, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "8.6.11",
3
+ "version": "8.6.12-alpha-2e27df80.0",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
package/types.d.ts CHANGED
@@ -48,3 +48,27 @@ export interface PruneSchemaOptions {
48
48
  export declare type InputLeafValueTransformer = (type: GraphQLEnumType | GraphQLScalarType, originalValue: any) => any;
49
49
  export declare type InputObjectValueTransformer = (type: GraphQLInputObjectType, originalValue: Record<string, any>) => Record<string, any>;
50
50
  export declare type ASTVisitorKeyMap = Partial<Parameters<typeof visit>[2]>;
51
+ export declare type DirectiveLocationEnum = typeof DirectiveLocation;
52
+ export declare enum DirectiveLocation {
53
+ /** Request Definitions */
54
+ QUERY = "QUERY",
55
+ MUTATION = "MUTATION",
56
+ SUBSCRIPTION = "SUBSCRIPTION",
57
+ FIELD = "FIELD",
58
+ FRAGMENT_DEFINITION = "FRAGMENT_DEFINITION",
59
+ FRAGMENT_SPREAD = "FRAGMENT_SPREAD",
60
+ INLINE_FRAGMENT = "INLINE_FRAGMENT",
61
+ VARIABLE_DEFINITION = "VARIABLE_DEFINITION",
62
+ /** Type System Definitions */
63
+ SCHEMA = "SCHEMA",
64
+ SCALAR = "SCALAR",
65
+ OBJECT = "OBJECT",
66
+ FIELD_DEFINITION = "FIELD_DEFINITION",
67
+ ARGUMENT_DEFINITION = "ARGUMENT_DEFINITION",
68
+ INTERFACE = "INTERFACE",
69
+ UNION = "UNION",
70
+ ENUM = "ENUM",
71
+ ENUM_VALUE = "ENUM_VALUE",
72
+ INPUT_OBJECT = "INPUT_OBJECT",
73
+ INPUT_FIELD_DEFINITION = "INPUT_FIELD_DEFINITION"
74
+ }