@graphql-tools/utils 10.10.0-alpha-20251027010606-226b580f6448e27f51c6c50b3035c631e1902460 → 10.10.0-alpha-20251027100557-9a80d88e5b0ded866058fced28dcd30be6728693

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,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR_EXTENSION_SCHEMA_COORDINATE = void 0;
3
4
  exports.createGraphQLError = createGraphQLError;
5
+ exports.locatedError = locatedError;
4
6
  exports.relocatedError = relocatedError;
5
7
  const graphql_1 = require("graphql");
6
8
  const possibleGraphQLErrorProperties = [
@@ -31,13 +33,34 @@ function createGraphQLError(message, options) {
31
33
  }
32
34
  return new graphql_1.GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
33
35
  }
34
- function relocatedError(originalError, path) {
35
- return createGraphQLError(originalError.message, {
36
+ exports.ERROR_EXTENSION_SCHEMA_COORDINATE = Symbol.for('graphql.error.schemaCoordinate');
37
+ function addSchemaCoordinateToError(error, info) {
38
+ // @ts-expect-error extensions can't be Symbol in official GraphQL Error type
39
+ error.extensions[exports.ERROR_EXTENSION_SCHEMA_COORDINATE] = `${info.parentType.name}.${info.fieldName}`;
40
+ }
41
+ function locatedError(rawError, nodes, path, info) {
42
+ const error = (0, graphql_1.locatedError)(rawError, nodes, path);
43
+ if (info) {
44
+ addSchemaCoordinateToError(error, info);
45
+ }
46
+ return error;
47
+ }
48
+ function relocatedError(originalError, path, info) {
49
+ const error = createGraphQLError(originalError.message, {
36
50
  nodes: originalError.nodes,
37
51
  source: originalError.source,
38
52
  positions: originalError.positions,
39
53
  path: path == null ? originalError.path : path,
40
54
  originalError,
41
- extensions: originalError.extensions,
55
+ extensions: info
56
+ ? {
57
+ ...originalError.extensions,
58
+ schemaCoordinates: `${info.parentType.name}.${info.fieldName}`,
59
+ }
60
+ : originalError.extensions,
42
61
  });
62
+ if (info) {
63
+ addSchemaCoordinateToError(error, info);
64
+ }
65
+ return error;
43
66
  }
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',
@@ -27,13 +27,34 @@ export function createGraphQLError(message, options) {
27
27
  }
28
28
  return new GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
29
29
  }
30
- export function relocatedError(originalError, path) {
31
- return createGraphQLError(originalError.message, {
30
+ export const ERROR_EXTENSION_SCHEMA_COORDINATE = Symbol.for('graphql.error.schemaCoordinate');
31
+ function addSchemaCoordinateToError(error, info) {
32
+ // @ts-expect-error extensions can't be Symbol in official GraphQL Error type
33
+ error.extensions[ERROR_EXTENSION_SCHEMA_COORDINATE] = `${info.parentType.name}.${info.fieldName}`;
34
+ }
35
+ export function locatedError(rawError, nodes, path, info) {
36
+ const error = _locatedError(rawError, nodes, path);
37
+ if (info) {
38
+ addSchemaCoordinateToError(error, info);
39
+ }
40
+ return error;
41
+ }
42
+ export function relocatedError(originalError, path, info) {
43
+ const error = createGraphQLError(originalError.message, {
32
44
  nodes: originalError.nodes,
33
45
  source: originalError.source,
34
46
  positions: originalError.positions,
35
47
  path: path == null ? originalError.path : path,
36
48
  originalError,
37
- extensions: originalError.extensions,
49
+ extensions: info
50
+ ? {
51
+ ...originalError.extensions,
52
+ schemaCoordinates: `${info.parentType.name}.${info.fieldName}`,
53
+ }
54
+ : originalError.extensions,
38
55
  });
56
+ if (info) {
57
+ addSchemaCoordinateToError(error, info);
58
+ }
59
+ return error;
39
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.10.0-alpha-20251027010606-226b580f6448e27f51c6c50b3035c631e1902460",
3
+ "version": "10.10.0-alpha-20251027100557-9a80d88e5b0ded866058fced28dcd30be6728693",
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;
@@ -11,5 +11,13 @@ interface GraphQLErrorOptions {
11
11
  extensions?: any;
12
12
  }
13
13
  export declare function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError;
14
- export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>): GraphQLError;
14
+ type SchemaCoordinateInfo = {
15
+ fieldName: string;
16
+ parentType: {
17
+ name: string;
18
+ };
19
+ };
20
+ export declare const ERROR_EXTENSION_SCHEMA_COORDINATE: unique symbol;
21
+ export declare function locatedError(rawError: unknown, nodes: ASTNode | ReadonlyArray<ASTNode> | null | undefined, path: Maybe<ReadonlyArray<string | number>>, info: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
22
+ export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>, info?: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
15
23
  export {};
@@ -11,5 +11,13 @@ interface GraphQLErrorOptions {
11
11
  extensions?: any;
12
12
  }
13
13
  export declare function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError;
14
- export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>): GraphQLError;
14
+ type SchemaCoordinateInfo = {
15
+ fieldName: string;
16
+ parentType: {
17
+ name: string;
18
+ };
19
+ };
20
+ export declare const ERROR_EXTENSION_SCHEMA_COORDINATE: unique symbol;
21
+ export declare function locatedError(rawError: unknown, nodes: ASTNode | ReadonlyArray<ASTNode> | null | undefined, path: Maybe<ReadonlyArray<string | number>>, info: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
22
+ export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>, info?: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
15
23
  export {};