@graphql-tools/utils 10.10.1 → 10.11.0-alpha-20251110221147-3e773b194d7b3e752eb121d0bec4e49919d9f1f9

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
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGraphQLErrorLike = isGraphQLErrorLike;
3
4
  exports.createGraphQLError = createGraphQLError;
5
+ exports.getSchemaCoordinate = getSchemaCoordinate;
6
+ exports.locatedError = locatedError;
4
7
  exports.relocatedError = relocatedError;
5
8
  const graphql_1 = require("graphql");
6
9
  const possibleGraphQLErrorProperties = [
@@ -26,12 +29,35 @@ function createGraphQLError(message, options) {
26
29
  isGraphQLErrorLike(options.originalError)) {
27
30
  options.originalError = createGraphQLError(options.originalError.message, options.originalError);
28
31
  }
29
- if (graphql_1.versionInfo.major >= 17) {
30
- return new graphql_1.GraphQLError(message, options);
32
+ let error;
33
+ if (graphql_1.versionInfo.major >= 16) {
34
+ error = new graphql_1.GraphQLError(message, options);
31
35
  }
32
- return new graphql_1.GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
36
+ else {
37
+ error = new graphql_1.GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
38
+ }
39
+ if (options?.coordinate != null && !error.coordinate) {
40
+ Object.defineProperty(error, 'coordinate', {
41
+ value: options.coordinate,
42
+ enumerable: true,
43
+ configurable: true,
44
+ });
45
+ }
46
+ return error;
47
+ }
48
+ function getSchemaCoordinate(error) {
49
+ return error.coordinate;
50
+ }
51
+ function locatedError(rawError, nodes, path, info) {
52
+ const error = (0, graphql_1.locatedError)(rawError, nodes, path);
53
+ // `graphql` locatedError is only changing path and nodes if it is not already defined
54
+ if (!error.coordinate && info) {
55
+ // @ts-expect-error coordinate is readonly, but we don't want to recreate it just to add coordinate
56
+ error.coordinate = `${info.parentType.name}.${info.fieldName}`;
57
+ }
58
+ return error;
33
59
  }
34
- function relocatedError(originalError, path) {
60
+ function relocatedError(originalError, path, info) {
35
61
  return createGraphQLError(originalError.message, {
36
62
  nodes: originalError.nodes,
37
63
  source: originalError.source,
@@ -39,5 +65,6 @@ function relocatedError(originalError, path) {
39
65
  path: path == null ? originalError.path : path,
40
66
  originalError,
41
67
  extensions: originalError.extensions,
68
+ coordinate: info ? `${info.parentType.name}.${info.fieldName}` : undefined,
42
69
  });
43
70
  }
package/esm/errors.js CHANGED
@@ -1,4 +1,4 @@
1
- import { GraphQLError, versionInfo } from 'graphql';
1
+ import { locatedError as _locatedError, GraphQLError, versionInfo, } from 'graphql';
2
2
  const possibleGraphQLErrorProperties = [
3
3
  'message',
4
4
  'locations',
@@ -11,7 +11,7 @@ const possibleGraphQLErrorProperties = [
11
11
  'stack',
12
12
  'extensions',
13
13
  ];
14
- function isGraphQLErrorLike(error) {
14
+ export function isGraphQLErrorLike(error) {
15
15
  return (error != null &&
16
16
  typeof error === 'object' &&
17
17
  Object.keys(error).every(key => possibleGraphQLErrorProperties.includes(key)));
@@ -22,12 +22,35 @@ export function createGraphQLError(message, options) {
22
22
  isGraphQLErrorLike(options.originalError)) {
23
23
  options.originalError = createGraphQLError(options.originalError.message, options.originalError);
24
24
  }
25
- if (versionInfo.major >= 17) {
26
- return new GraphQLError(message, options);
25
+ let error;
26
+ if (versionInfo.major >= 16) {
27
+ error = new GraphQLError(message, options);
27
28
  }
28
- return new GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
29
+ else {
30
+ error = new GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
31
+ }
32
+ if (options?.coordinate != null && !error.coordinate) {
33
+ Object.defineProperty(error, 'coordinate', {
34
+ value: options.coordinate,
35
+ enumerable: true,
36
+ configurable: true,
37
+ });
38
+ }
39
+ return error;
40
+ }
41
+ export function getSchemaCoordinate(error) {
42
+ return error.coordinate;
43
+ }
44
+ export function locatedError(rawError, nodes, path, info) {
45
+ const error = _locatedError(rawError, nodes, path);
46
+ // `graphql` locatedError is only changing path and nodes if it is not already defined
47
+ if (!error.coordinate && info) {
48
+ // @ts-expect-error coordinate is readonly, but we don't want to recreate it just to add coordinate
49
+ error.coordinate = `${info.parentType.name}.${info.fieldName}`;
50
+ }
51
+ return error;
29
52
  }
30
- export function relocatedError(originalError, path) {
53
+ export function relocatedError(originalError, path, info) {
31
54
  return createGraphQLError(originalError.message, {
32
55
  nodes: originalError.nodes,
33
56
  source: originalError.source,
@@ -35,5 +58,6 @@ export function relocatedError(originalError, path) {
35
58
  path: path == null ? originalError.path : path,
36
59
  originalError,
37
60
  extensions: originalError.extensions,
61
+ coordinate: info ? `${info.parentType.name}.${info.fieldName}` : undefined,
38
62
  });
39
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.10.1",
3
+ "version": "10.11.0-alpha-20251110221147-3e773b194d7b3e752eb121d0bec4e49919d9f1f9",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -32,6 +32,13 @@ export interface ExecutionRequest<TVariables extends Record<string, any> = any,
32
32
  subgraphName?: string;
33
33
  info?: GraphQLResolveInfo;
34
34
  signal?: AbortSignal;
35
+ /**
36
+ * Enable/Disable the addition of field schema coordinate in GraphQL Errors extension
37
+ *
38
+ * Note: Schema Coordinate are exposed using Symbol.for('schemaCoordinate') so that it's not
39
+ * serialized. Exposing schema coordinate can ease the discovery of private schemas.
40
+ */
41
+ schemaCoordinateInErrors?: boolean;
35
42
  }
36
43
  export interface GraphQLParseOptions {
37
44
  noLocation?: boolean;
@@ -32,6 +32,13 @@ export interface ExecutionRequest<TVariables extends Record<string, any> = any,
32
32
  subgraphName?: string;
33
33
  info?: GraphQLResolveInfo;
34
34
  signal?: AbortSignal;
35
+ /**
36
+ * Enable/Disable the addition of field schema coordinate in GraphQL Errors extension
37
+ *
38
+ * Note: Schema Coordinate are exposed using Symbol.for('schemaCoordinate') so that it's not
39
+ * serialized. Exposing schema coordinate can ease the discovery of private schemas.
40
+ */
41
+ schemaCoordinateInErrors?: boolean;
35
42
  }
36
43
  export interface GraphQLParseOptions {
37
44
  noLocation?: boolean;
@@ -9,7 +9,25 @@ interface GraphQLErrorOptions {
9
9
  readonly extensions?: unknown;
10
10
  }>;
11
11
  extensions?: any;
12
+ coordinate?: string;
13
+ }
14
+ export declare function isGraphQLErrorLike(error: any): boolean;
15
+ declare module 'graphql' {
16
+ interface GraphQLError {
17
+ /**
18
+ * An optional schema coordinate (e.g. "MyType.myField") associated with this error.
19
+ */
20
+ readonly coordinate?: string;
21
+ }
12
22
  }
13
23
  export declare function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError;
14
- export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>): GraphQLError;
24
+ type SchemaCoordinateInfo = {
25
+ fieldName: string;
26
+ parentType: {
27
+ name: string;
28
+ };
29
+ };
30
+ export declare function getSchemaCoordinate(error: GraphQLError): string | undefined;
31
+ export declare function locatedError(rawError: unknown, nodes: ASTNode | ReadonlyArray<ASTNode> | undefined, path: Maybe<ReadonlyArray<string | number>>, info: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
32
+ export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>, info?: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
15
33
  export {};
@@ -9,7 +9,25 @@ interface GraphQLErrorOptions {
9
9
  readonly extensions?: unknown;
10
10
  }>;
11
11
  extensions?: any;
12
+ coordinate?: string;
13
+ }
14
+ export declare function isGraphQLErrorLike(error: any): boolean;
15
+ declare module 'graphql' {
16
+ interface GraphQLError {
17
+ /**
18
+ * An optional schema coordinate (e.g. "MyType.myField") associated with this error.
19
+ */
20
+ readonly coordinate?: string;
21
+ }
12
22
  }
13
23
  export declare function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError;
14
- export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>): GraphQLError;
24
+ type SchemaCoordinateInfo = {
25
+ fieldName: string;
26
+ parentType: {
27
+ name: string;
28
+ };
29
+ };
30
+ export declare function getSchemaCoordinate(error: GraphQLError): string | undefined;
31
+ export declare function locatedError(rawError: unknown, nodes: ASTNode | ReadonlyArray<ASTNode> | undefined, path: Maybe<ReadonlyArray<string | number>>, info: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
32
+ export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>, info?: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
15
33
  export {};