@graphql-tools/utils 10.0.7 → 10.0.8-alpha-20231108155036-4f89aba8

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.
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.astFromType = void 0;
4
+ const cross_inspect_1 = require("cross-inspect");
4
5
  const graphql_1 = require("graphql");
5
- const inspect_js_1 = require("./inspect.js");
6
6
  function astFromType(type) {
7
7
  if ((0, graphql_1.isNonNullType)(type)) {
8
8
  const innerType = astFromType(type.ofType);
9
9
  if (innerType.kind === graphql_1.Kind.NON_NULL_TYPE) {
10
- throw new Error(`Invalid type node ${(0, inspect_js_1.inspect)(type)}. Inner type of non-null type cannot be a non-null type.`);
10
+ throw new Error(`Invalid type node ${(0, cross_inspect_1.inspect)(type)}. Inner type of non-null type cannot be a non-null type.`);
11
11
  }
12
12
  return {
13
13
  kind: graphql_1.Kind.NON_NULL_TYPE,
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.astFromValue = void 0;
4
+ const cross_inspect_1 = require("cross-inspect");
4
5
  const graphql_1 = require("graphql");
5
6
  const astFromValueUntyped_js_1 = require("./astFromValueUntyped.js");
6
- const inspect_js_1 = require("./inspect.js");
7
7
  const jsutils_js_1 = require("./jsutils.js");
8
8
  /**
9
9
  * Produces a GraphQL Value AST given a JavaScript object.
@@ -98,7 +98,7 @@ function astFromValue(value, type) {
98
98
  }
99
99
  /* c8 ignore next 3 */
100
100
  // Not reachable, all possible types have been considered.
101
- console.assert(false, 'Unexpected input type: ' + (0, inspect_js_1.inspect)(type));
101
+ console.assert(false, 'Unexpected input type: ' + (0, cross_inspect_1.inspect)(type));
102
102
  }
103
103
  exports.astFromValue = astFromValue;
104
104
  /**
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getArgumentValues = void 0;
4
+ const cross_inspect_1 = require("cross-inspect");
4
5
  const graphql_1 = require("graphql");
5
6
  const errors_js_1 = require("./errors.js");
6
- const inspect_js_1 = require("./inspect.js");
7
7
  const jsutils_js_1 = require("./jsutils.js");
8
8
  /**
9
9
  * Prepares an object map of argument values given a list of argument
@@ -27,7 +27,7 @@ function getArgumentValues(def, node, variableValues = {}) {
27
27
  coercedValues[name] = defaultValue;
28
28
  }
29
29
  else if ((0, graphql_1.isNonNullType)(argType)) {
30
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` + 'was not provided.', {
30
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, cross_inspect_1.inspect)(argType)}" ` + 'was not provided.', {
31
31
  nodes: [node],
32
32
  });
33
33
  }
@@ -42,7 +42,7 @@ function getArgumentValues(def, node, variableValues = {}) {
42
42
  coercedValues[name] = defaultValue;
43
43
  }
44
44
  else if ((0, graphql_1.isNonNullType)(argType)) {
45
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, inspect_js_1.inspect)(argType)}" ` +
45
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, cross_inspect_1.inspect)(argType)}" ` +
46
46
  `was provided the variable "$${variableName}" which was not provided a runtime value.`, {
47
47
  nodes: [valueNode],
48
48
  });
@@ -52,7 +52,7 @@ function getArgumentValues(def, node, variableValues = {}) {
52
52
  isNull = variableValues[variableName] == null;
53
53
  }
54
54
  if (isNull && (0, graphql_1.isNonNullType)(argType)) {
55
- throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of non-null type "${(0, inspect_js_1.inspect)(argType)}" ` + 'must not be null.', {
55
+ throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of non-null type "${(0, cross_inspect_1.inspect)(argType)}" ` + 'must not be null.', {
56
56
  nodes: [valueNode],
57
57
  });
58
58
  }
package/cjs/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inspect = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./loaders.js"), exports);
5
6
  tslib_1.__exportStar(require("./helpers.js"), exports);
@@ -47,7 +48,8 @@ tslib_1.__exportStar(require("./withCancel.js"), exports);
47
48
  tslib_1.__exportStar(require("./rootTypes.js"), exports);
48
49
  tslib_1.__exportStar(require("./comments.js"), exports);
49
50
  tslib_1.__exportStar(require("./collectFields.js"), exports);
50
- tslib_1.__exportStar(require("./inspect.js"), exports);
51
+ var cross_inspect_1 = require("cross-inspect");
52
+ Object.defineProperty(exports, "inspect", { enumerable: true, get: function () { return cross_inspect_1.inspect; } });
51
53
  tslib_1.__exportStar(require("./memoize.js"), exports);
52
54
  tslib_1.__exportStar(require("./fixSchemaAst.js"), exports);
53
55
  tslib_1.__exportStar(require("./getOperationASTFromRequest.js"), exports);
@@ -1,5 +1,5 @@
1
+ import { inspect } from 'cross-inspect';
1
2
  import { isListType, isNonNullType, Kind } from 'graphql';
2
- import { inspect } from './inspect.js';
3
3
  export function astFromType(type) {
4
4
  if (isNonNullType(type)) {
5
5
  const innerType = astFromType(type.ofType);
@@ -1,6 +1,6 @@
1
+ import { inspect } from 'cross-inspect';
1
2
  import { isEnumType, isInputObjectType, isLeafType, isListType, isNonNullType, Kind, } from 'graphql';
2
3
  import { astFromValueUntyped } from './astFromValueUntyped.js';
3
- import { inspect } from './inspect.js';
4
4
  import { isIterableObject, isObjectLike } from './jsutils.js';
5
5
  /**
6
6
  * Produces a GraphQL Value AST given a JavaScript object.
@@ -1,6 +1,6 @@
1
+ import { inspect } from 'cross-inspect';
1
2
  import { isNonNullType, Kind, print, valueFromAST, } from 'graphql';
2
3
  import { createGraphQLError } from './errors.js';
3
- import { inspect } from './inspect.js';
4
4
  import { hasOwnProperty } from './jsutils.js';
5
5
  /**
6
6
  * Prepares an object map of argument values given a list of argument
package/esm/index.js CHANGED
@@ -44,7 +44,7 @@ export * from './withCancel.js';
44
44
  export * from './rootTypes.js';
45
45
  export * from './comments.js';
46
46
  export * from './collectFields.js';
47
- export * from './inspect.js';
47
+ export { inspect } from 'cross-inspect';
48
48
  export * from './memoize.js';
49
49
  export * from './fixSchemaAst.js';
50
50
  export * from './getOperationASTFromRequest.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.0.7",
3
+ "version": "10.0.8-alpha-20231108155036-4f89aba8",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@graphql-typed-document-node/core": "^3.1.1",
11
+ "cross-inspect": "1.0.0-alpha-20231108155036-4f89aba8",
11
12
  "dset": "^3.1.2",
12
13
  "tslib": "^2.4.0"
13
14
  },
@@ -44,7 +44,7 @@ export * from './withCancel.cjs';
44
44
  export * from './rootTypes.cjs';
45
45
  export * from './comments.cjs';
46
46
  export * from './collectFields.cjs';
47
- export * from './inspect.cjs';
47
+ export { inspect } from 'cross-inspect';
48
48
  export * from './memoize.cjs';
49
49
  export * from './fixSchemaAst.cjs';
50
50
  export * from './getOperationASTFromRequest.cjs';
@@ -44,7 +44,7 @@ export * from './withCancel.js';
44
44
  export * from './rootTypes.js';
45
45
  export * from './comments.js';
46
46
  export * from './collectFields.js';
47
- export * from './inspect.js';
47
+ export { inspect } from 'cross-inspect';
48
48
  export * from './memoize.js';
49
49
  export * from './fixSchemaAst.js';
50
50
  export * from './getOperationASTFromRequest.js';
package/cjs/inspect.js DELETED
@@ -1,101 +0,0 @@
1
- "use strict";
2
- // Taken from graphql-js
3
- // https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.inspect = void 0;
6
- const graphql_1 = require("graphql");
7
- const MAX_RECURSIVE_DEPTH = 3;
8
- /**
9
- * Used to print values in error messages.
10
- */
11
- function inspect(value) {
12
- return formatValue(value, []);
13
- }
14
- exports.inspect = inspect;
15
- function formatValue(value, seenValues) {
16
- switch (typeof value) {
17
- case 'string':
18
- return JSON.stringify(value);
19
- case 'function':
20
- return value.name ? `[function ${value.name}]` : '[function]';
21
- case 'object':
22
- return formatObjectValue(value, seenValues);
23
- default:
24
- return String(value);
25
- }
26
- }
27
- function formatError(value) {
28
- if (value instanceof graphql_1.GraphQLError) {
29
- return value.toString();
30
- }
31
- return `${value.name}: ${value.message};\n ${value.stack}`;
32
- }
33
- function formatObjectValue(value, previouslySeenValues) {
34
- if (value === null) {
35
- return 'null';
36
- }
37
- if (value instanceof Error) {
38
- if (value.name === 'AggregateError') {
39
- return (formatError(value) +
40
- '\n' +
41
- formatArray(value.errors, previouslySeenValues));
42
- }
43
- return formatError(value);
44
- }
45
- if (previouslySeenValues.includes(value)) {
46
- return '[Circular]';
47
- }
48
- const seenValues = [...previouslySeenValues, value];
49
- if (isJSONable(value)) {
50
- const jsonValue = value.toJSON();
51
- // check for infinite recursion
52
- if (jsonValue !== value) {
53
- return typeof jsonValue === 'string' ? jsonValue : formatValue(jsonValue, seenValues);
54
- }
55
- }
56
- else if (Array.isArray(value)) {
57
- return formatArray(value, seenValues);
58
- }
59
- return formatObject(value, seenValues);
60
- }
61
- function isJSONable(value) {
62
- return typeof value.toJSON === 'function';
63
- }
64
- function formatObject(object, seenValues) {
65
- const entries = Object.entries(object);
66
- if (entries.length === 0) {
67
- return '{}';
68
- }
69
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
70
- return '[' + getObjectTag(object) + ']';
71
- }
72
- const properties = entries.map(([key, value]) => key + ': ' + formatValue(value, seenValues));
73
- return '{ ' + properties.join(', ') + ' }';
74
- }
75
- function formatArray(array, seenValues) {
76
- if (array.length === 0) {
77
- return '[]';
78
- }
79
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
80
- return '[Array]';
81
- }
82
- const len = array.length;
83
- const items = [];
84
- for (let i = 0; i < len; ++i) {
85
- items.push(formatValue(array[i], seenValues));
86
- }
87
- return '[' + items.join(', ') + ']';
88
- }
89
- function getObjectTag(object) {
90
- const tag = Object.prototype.toString
91
- .call(object)
92
- .replace(/^\[object /, '')
93
- .replace(/]$/, '');
94
- if (tag === 'Object' && typeof object.constructor === 'function') {
95
- const name = object.constructor.name;
96
- if (typeof name === 'string' && name !== '') {
97
- return name;
98
- }
99
- }
100
- return tag;
101
- }
package/esm/inspect.js DELETED
@@ -1,97 +0,0 @@
1
- // Taken from graphql-js
2
- // https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
3
- import { GraphQLError } from 'graphql';
4
- const MAX_RECURSIVE_DEPTH = 3;
5
- /**
6
- * Used to print values in error messages.
7
- */
8
- export function inspect(value) {
9
- return formatValue(value, []);
10
- }
11
- function formatValue(value, seenValues) {
12
- switch (typeof value) {
13
- case 'string':
14
- return JSON.stringify(value);
15
- case 'function':
16
- return value.name ? `[function ${value.name}]` : '[function]';
17
- case 'object':
18
- return formatObjectValue(value, seenValues);
19
- default:
20
- return String(value);
21
- }
22
- }
23
- function formatError(value) {
24
- if (value instanceof GraphQLError) {
25
- return value.toString();
26
- }
27
- return `${value.name}: ${value.message};\n ${value.stack}`;
28
- }
29
- function formatObjectValue(value, previouslySeenValues) {
30
- if (value === null) {
31
- return 'null';
32
- }
33
- if (value instanceof Error) {
34
- if (value.name === 'AggregateError') {
35
- return (formatError(value) +
36
- '\n' +
37
- formatArray(value.errors, previouslySeenValues));
38
- }
39
- return formatError(value);
40
- }
41
- if (previouslySeenValues.includes(value)) {
42
- return '[Circular]';
43
- }
44
- const seenValues = [...previouslySeenValues, value];
45
- if (isJSONable(value)) {
46
- const jsonValue = value.toJSON();
47
- // check for infinite recursion
48
- if (jsonValue !== value) {
49
- return typeof jsonValue === 'string' ? jsonValue : formatValue(jsonValue, seenValues);
50
- }
51
- }
52
- else if (Array.isArray(value)) {
53
- return formatArray(value, seenValues);
54
- }
55
- return formatObject(value, seenValues);
56
- }
57
- function isJSONable(value) {
58
- return typeof value.toJSON === 'function';
59
- }
60
- function formatObject(object, seenValues) {
61
- const entries = Object.entries(object);
62
- if (entries.length === 0) {
63
- return '{}';
64
- }
65
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
66
- return '[' + getObjectTag(object) + ']';
67
- }
68
- const properties = entries.map(([key, value]) => key + ': ' + formatValue(value, seenValues));
69
- return '{ ' + properties.join(', ') + ' }';
70
- }
71
- function formatArray(array, seenValues) {
72
- if (array.length === 0) {
73
- return '[]';
74
- }
75
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
76
- return '[Array]';
77
- }
78
- const len = array.length;
79
- const items = [];
80
- for (let i = 0; i < len; ++i) {
81
- items.push(formatValue(array[i], seenValues));
82
- }
83
- return '[' + items.join(', ') + ']';
84
- }
85
- function getObjectTag(object) {
86
- const tag = Object.prototype.toString
87
- .call(object)
88
- .replace(/^\[object /, '')
89
- .replace(/]$/, '');
90
- if (tag === 'Object' && typeof object.constructor === 'function') {
91
- const name = object.constructor.name;
92
- if (typeof name === 'string' && name !== '') {
93
- return name;
94
- }
95
- }
96
- return tag;
97
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Used to print values in error messages.
3
- */
4
- export declare function inspect(value: unknown): string;
@@ -1,4 +0,0 @@
1
- /**
2
- * Used to print values in error messages.
3
- */
4
- export declare function inspect(value: unknown): string;