@graphql-tools/utils 10.0.6 → 10.0.7

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/cjs/errors.js CHANGED
@@ -2,7 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.relocatedError = exports.createGraphQLError = void 0;
4
4
  const graphql_1 = require("graphql");
5
+ const possibleGraphQLErrorProperties = [
6
+ 'message',
7
+ 'locations',
8
+ 'path',
9
+ 'nodes',
10
+ 'source',
11
+ 'positions',
12
+ 'originalError',
13
+ 'name',
14
+ 'stack',
15
+ 'extensions',
16
+ ];
17
+ function isGraphQLErrorLike(error) {
18
+ return (error != null &&
19
+ typeof error === 'object' &&
20
+ Object.keys(error).every(key => possibleGraphQLErrorProperties.includes(key)));
21
+ }
5
22
  function createGraphQLError(message, options) {
23
+ if (options?.originalError &&
24
+ !(options.originalError instanceof Error) &&
25
+ isGraphQLErrorLike(options.originalError)) {
26
+ options.originalError = createGraphQLError(options.originalError.message, options.originalError);
27
+ }
6
28
  if (graphql_1.versionInfo.major >= 17) {
7
29
  return new graphql_1.GraphQLError(message, options);
8
30
  }
package/esm/errors.js CHANGED
@@ -1,5 +1,27 @@
1
1
  import { GraphQLError, versionInfo } from 'graphql';
2
+ const possibleGraphQLErrorProperties = [
3
+ 'message',
4
+ 'locations',
5
+ 'path',
6
+ 'nodes',
7
+ 'source',
8
+ 'positions',
9
+ 'originalError',
10
+ 'name',
11
+ 'stack',
12
+ 'extensions',
13
+ ];
14
+ function isGraphQLErrorLike(error) {
15
+ return (error != null &&
16
+ typeof error === 'object' &&
17
+ Object.keys(error).every(key => possibleGraphQLErrorProperties.includes(key)));
18
+ }
2
19
  export function createGraphQLError(message, options) {
20
+ if (options?.originalError &&
21
+ !(options.originalError instanceof Error) &&
22
+ isGraphQLErrorLike(options.originalError)) {
23
+ options.originalError = createGraphQLError(options.originalError.message, options.originalError);
24
+ }
3
25
  if (versionInfo.major >= 17) {
4
26
  return new GraphQLError(message, options);
5
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.0.6",
3
+ "version": "10.0.7",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {