@graphql-tools/utils 10.10.1 → 10.11.0-alpha-20251110164254-8e0d1d1788c04c5a5183d93cfd465379d26a6765
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 +45 -4
- package/cjs/mergeIncrementalResult.js +4 -25
- package/esm/errors.js +40 -4
- package/esm/mergeIncrementalResult.js +4 -25
- package/package.json +2 -1
- package/typings/Interfaces.d.cts +7 -0
- package/typings/Interfaces.d.ts +7 -0
- package/typings/errors.d.cts +22 -2
- package/typings/errors.d.ts +22 -2
package/cjs/errors.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLError = void 0;
|
|
4
|
+
exports.isGraphQLErrorLike = isGraphQLErrorLike;
|
|
3
5
|
exports.createGraphQLError = createGraphQLError;
|
|
6
|
+
exports.getSchemaCoordinate = getSchemaCoordinate;
|
|
7
|
+
exports.locatedError = locatedError;
|
|
4
8
|
exports.relocatedError = relocatedError;
|
|
5
9
|
const graphql_1 = require("graphql");
|
|
6
10
|
const possibleGraphQLErrorProperties = [
|
|
@@ -14,7 +18,31 @@ const possibleGraphQLErrorProperties = [
|
|
|
14
18
|
'name',
|
|
15
19
|
'stack',
|
|
16
20
|
'extensions',
|
|
21
|
+
'coordinate',
|
|
17
22
|
];
|
|
23
|
+
function toNormalizedOptions(args) {
|
|
24
|
+
const firstArg = args[0];
|
|
25
|
+
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
|
|
26
|
+
return {
|
|
27
|
+
nodes: firstArg,
|
|
28
|
+
source: args[1],
|
|
29
|
+
positions: args[2],
|
|
30
|
+
path: args[3],
|
|
31
|
+
originalError: args[4],
|
|
32
|
+
extensions: args[5],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return firstArg;
|
|
36
|
+
}
|
|
37
|
+
class GraphQLError extends graphql_1.GraphQLError {
|
|
38
|
+
coordinate;
|
|
39
|
+
constructor(message, ...args) {
|
|
40
|
+
const options = toNormalizedOptions(args);
|
|
41
|
+
super(message, ...args);
|
|
42
|
+
this.coordinate = options.coordinate;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.GraphQLError = GraphQLError;
|
|
18
46
|
function isGraphQLErrorLike(error) {
|
|
19
47
|
return (error != null &&
|
|
20
48
|
typeof error === 'object' &&
|
|
@@ -26,12 +54,24 @@ function createGraphQLError(message, options) {
|
|
|
26
54
|
isGraphQLErrorLike(options.originalError)) {
|
|
27
55
|
options.originalError = createGraphQLError(options.originalError.message, options.originalError);
|
|
28
56
|
}
|
|
29
|
-
if (graphql_1.versionInfo.major >=
|
|
30
|
-
return new
|
|
57
|
+
if (graphql_1.versionInfo.major >= 16) {
|
|
58
|
+
return new GraphQLError(message, options);
|
|
59
|
+
}
|
|
60
|
+
return new GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
|
|
61
|
+
}
|
|
62
|
+
function getSchemaCoordinate(error) {
|
|
63
|
+
return error.coordinate;
|
|
64
|
+
}
|
|
65
|
+
function locatedError(rawError, nodes, path, info) {
|
|
66
|
+
const error = (0, graphql_1.locatedError)(rawError, nodes, path);
|
|
67
|
+
// `graphql` locatedError is only changing path and nodes if it is not already defined
|
|
68
|
+
if (!error.coordinate && info) {
|
|
69
|
+
// @ts-expect-error coordinate is readonly, but we don't want to recreate it just to add coordinate
|
|
70
|
+
error.coordinate = `${info.parentType.name}.${info.fieldName}`;
|
|
31
71
|
}
|
|
32
|
-
return
|
|
72
|
+
return error;
|
|
33
73
|
}
|
|
34
|
-
function relocatedError(originalError, path) {
|
|
74
|
+
function relocatedError(originalError, path, info) {
|
|
35
75
|
return createGraphQLError(originalError.message, {
|
|
36
76
|
nodes: originalError.nodes,
|
|
37
77
|
source: originalError.source,
|
|
@@ -39,5 +79,6 @@ function relocatedError(originalError, path) {
|
|
|
39
79
|
path: path == null ? originalError.path : path,
|
|
40
80
|
originalError,
|
|
41
81
|
extensions: originalError.extensions,
|
|
82
|
+
coordinate: info ? `${info.parentType.name}.${info.fieldName}` : undefined,
|
|
42
83
|
});
|
|
43
84
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeIncrementalResult = mergeIncrementalResult;
|
|
4
|
-
const
|
|
4
|
+
const merge_1 = require("dset/merge");
|
|
5
5
|
function mergeIncrementalResult({ incrementalResult, executionResult, }) {
|
|
6
6
|
const path = ['data', ...(incrementalResult.path ?? [])];
|
|
7
7
|
if (incrementalResult.items) {
|
|
8
8
|
for (const item of incrementalResult.items) {
|
|
9
|
-
|
|
9
|
+
(0, merge_1.dset)(executionResult, path, item);
|
|
10
10
|
// Increment the last path segment (the array index) to merge the next item at the next index
|
|
11
11
|
path[path.length - 1]++;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
if (incrementalResult.data) {
|
|
15
|
-
|
|
15
|
+
(0, merge_1.dset)(executionResult, path, incrementalResult.data);
|
|
16
16
|
}
|
|
17
17
|
if (incrementalResult.errors) {
|
|
18
18
|
executionResult.errors = executionResult.errors || [];
|
|
19
19
|
executionResult.errors.push(...incrementalResult.errors);
|
|
20
20
|
}
|
|
21
21
|
if (incrementalResult.extensions) {
|
|
22
|
-
|
|
22
|
+
(0, merge_1.dset)(executionResult, 'extensions', incrementalResult.extensions);
|
|
23
23
|
}
|
|
24
24
|
if (incrementalResult.incremental) {
|
|
25
25
|
incrementalResult.incremental.forEach(incrementalSubResult => {
|
|
@@ -30,24 +30,3 @@ function mergeIncrementalResult({ incrementalResult, executionResult, }) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function setObjectKeyPath(obj, keyPath, value) {
|
|
34
|
-
let current = obj;
|
|
35
|
-
let i;
|
|
36
|
-
for (i = 0; i < keyPath.length - 1; i++) {
|
|
37
|
-
const key = keyPath[i];
|
|
38
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (current[key] == null) {
|
|
42
|
-
// Determine if the next key is a number to create an array, otherwise create an object
|
|
43
|
-
current[key] = typeof keyPath[i + 1] === 'number' ? [] : {};
|
|
44
|
-
}
|
|
45
|
-
current = current[key];
|
|
46
|
-
}
|
|
47
|
-
const finalKey = keyPath[i];
|
|
48
|
-
if (finalKey === '__proto__' || finalKey === 'constructor' || finalKey === 'prototype') {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const existingValue = current[finalKey];
|
|
52
|
-
current[finalKey] = existingValue != null ? (0, mergeDeep_js_1.mergeDeep)([existingValue, value]) : value;
|
|
53
|
-
}
|
package/esm/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLError, versionInfo } from 'graphql';
|
|
1
|
+
import { GraphQLError as _GraphQLError, locatedError as _locatedError, versionInfo, } from 'graphql';
|
|
2
2
|
const possibleGraphQLErrorProperties = [
|
|
3
3
|
'message',
|
|
4
4
|
'locations',
|
|
@@ -10,8 +10,31 @@ const possibleGraphQLErrorProperties = [
|
|
|
10
10
|
'name',
|
|
11
11
|
'stack',
|
|
12
12
|
'extensions',
|
|
13
|
+
'coordinate',
|
|
13
14
|
];
|
|
14
|
-
function
|
|
15
|
+
function toNormalizedOptions(args) {
|
|
16
|
+
const firstArg = args[0];
|
|
17
|
+
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
|
|
18
|
+
return {
|
|
19
|
+
nodes: firstArg,
|
|
20
|
+
source: args[1],
|
|
21
|
+
positions: args[2],
|
|
22
|
+
path: args[3],
|
|
23
|
+
originalError: args[4],
|
|
24
|
+
extensions: args[5],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return firstArg;
|
|
28
|
+
}
|
|
29
|
+
export class GraphQLError extends _GraphQLError {
|
|
30
|
+
coordinate;
|
|
31
|
+
constructor(message, ...args) {
|
|
32
|
+
const options = toNormalizedOptions(args);
|
|
33
|
+
super(message, ...args);
|
|
34
|
+
this.coordinate = options.coordinate;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function isGraphQLErrorLike(error) {
|
|
15
38
|
return (error != null &&
|
|
16
39
|
typeof error === 'object' &&
|
|
17
40
|
Object.keys(error).every(key => possibleGraphQLErrorProperties.includes(key)));
|
|
@@ -22,12 +45,24 @@ export function createGraphQLError(message, options) {
|
|
|
22
45
|
isGraphQLErrorLike(options.originalError)) {
|
|
23
46
|
options.originalError = createGraphQLError(options.originalError.message, options.originalError);
|
|
24
47
|
}
|
|
25
|
-
if (versionInfo.major >=
|
|
48
|
+
if (versionInfo.major >= 16) {
|
|
26
49
|
return new GraphQLError(message, options);
|
|
27
50
|
}
|
|
28
51
|
return new GraphQLError(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
|
|
29
52
|
}
|
|
30
|
-
export function
|
|
53
|
+
export function getSchemaCoordinate(error) {
|
|
54
|
+
return error.coordinate;
|
|
55
|
+
}
|
|
56
|
+
export function locatedError(rawError, nodes, path, info) {
|
|
57
|
+
const error = _locatedError(rawError, nodes, path);
|
|
58
|
+
// `graphql` locatedError is only changing path and nodes if it is not already defined
|
|
59
|
+
if (!error.coordinate && info) {
|
|
60
|
+
// @ts-expect-error coordinate is readonly, but we don't want to recreate it just to add coordinate
|
|
61
|
+
error.coordinate = `${info.parentType.name}.${info.fieldName}`;
|
|
62
|
+
}
|
|
63
|
+
return error;
|
|
64
|
+
}
|
|
65
|
+
export function relocatedError(originalError, path, info) {
|
|
31
66
|
return createGraphQLError(originalError.message, {
|
|
32
67
|
nodes: originalError.nodes,
|
|
33
68
|
source: originalError.source,
|
|
@@ -35,5 +70,6 @@ export function relocatedError(originalError, path) {
|
|
|
35
70
|
path: path == null ? originalError.path : path,
|
|
36
71
|
originalError,
|
|
37
72
|
extensions: originalError.extensions,
|
|
73
|
+
coordinate: info ? `${info.parentType.name}.${info.fieldName}` : undefined,
|
|
38
74
|
});
|
|
39
75
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dset } from 'dset/merge';
|
|
2
2
|
export function mergeIncrementalResult({ incrementalResult, executionResult, }) {
|
|
3
3
|
const path = ['data', ...(incrementalResult.path ?? [])];
|
|
4
4
|
if (incrementalResult.items) {
|
|
5
5
|
for (const item of incrementalResult.items) {
|
|
6
|
-
|
|
6
|
+
dset(executionResult, path, item);
|
|
7
7
|
// Increment the last path segment (the array index) to merge the next item at the next index
|
|
8
8
|
path[path.length - 1]++;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
if (incrementalResult.data) {
|
|
12
|
-
|
|
12
|
+
dset(executionResult, path, incrementalResult.data);
|
|
13
13
|
}
|
|
14
14
|
if (incrementalResult.errors) {
|
|
15
15
|
executionResult.errors = executionResult.errors || [];
|
|
16
16
|
executionResult.errors.push(...incrementalResult.errors);
|
|
17
17
|
}
|
|
18
18
|
if (incrementalResult.extensions) {
|
|
19
|
-
|
|
19
|
+
dset(executionResult, 'extensions', incrementalResult.extensions);
|
|
20
20
|
}
|
|
21
21
|
if (incrementalResult.incremental) {
|
|
22
22
|
incrementalResult.incremental.forEach(incrementalSubResult => {
|
|
@@ -27,24 +27,3 @@ export function mergeIncrementalResult({ incrementalResult, executionResult, })
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
function setObjectKeyPath(obj, keyPath, value) {
|
|
31
|
-
let current = obj;
|
|
32
|
-
let i;
|
|
33
|
-
for (i = 0; i < keyPath.length - 1; i++) {
|
|
34
|
-
const key = keyPath[i];
|
|
35
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (current[key] == null) {
|
|
39
|
-
// Determine if the next key is a number to create an array, otherwise create an object
|
|
40
|
-
current[key] = typeof keyPath[i + 1] === 'number' ? [] : {};
|
|
41
|
-
}
|
|
42
|
-
current = current[key];
|
|
43
|
-
}
|
|
44
|
-
const finalKey = keyPath[i];
|
|
45
|
-
if (finalKey === '__proto__' || finalKey === 'constructor' || finalKey === 'prototype') {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const existingValue = current[finalKey];
|
|
49
|
-
current[finalKey] = existingValue != null ? mergeDeep([existingValue, value]) : value;
|
|
50
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/utils",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.11.0-alpha-20251110164254-8e0d1d1788c04c5a5183d93cfd465379d26a6765",
|
|
4
4
|
"description": "Common package containing utils and types for GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"@graphql-typed-document-node/core": "^3.1.1",
|
|
11
11
|
"@whatwg-node/promise-helpers": "^1.0.0",
|
|
12
12
|
"cross-inspect": "1.0.1",
|
|
13
|
+
"dset": "^3.1.4",
|
|
13
14
|
"tslib": "^2.4.0"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
package/typings/Interfaces.d.cts
CHANGED
|
@@ -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;
|
package/typings/Interfaces.d.ts
CHANGED
|
@@ -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;
|
package/typings/errors.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTNode,
|
|
1
|
+
import { GraphQLError as _GraphQLError, ASTNode, GraphQLErrorExtensions, Source } from 'graphql';
|
|
2
2
|
import { Maybe } from './types.cjs';
|
|
3
3
|
interface GraphQLErrorOptions {
|
|
4
4
|
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
|
|
@@ -9,7 +9,27 @@ interface GraphQLErrorOptions {
|
|
|
9
9
|
readonly extensions?: unknown;
|
|
10
10
|
}>;
|
|
11
11
|
extensions?: any;
|
|
12
|
+
coordinate?: string;
|
|
12
13
|
}
|
|
14
|
+
export declare class GraphQLError extends _GraphQLError {
|
|
15
|
+
readonly coordinate?: string;
|
|
16
|
+
constructor(message: string, options?: Maybe<GraphQLErrorOptions>);
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
|
|
19
|
+
*/
|
|
20
|
+
constructor(message: string, nodes?: ReadonlyArray<ASTNode> | ASTNode | null, source?: Maybe<Source>, positions?: Maybe<ReadonlyArray<number>>, path?: Maybe<ReadonlyArray<string | number>>, originalError?: Maybe<Error & {
|
|
21
|
+
readonly extensions?: unknown;
|
|
22
|
+
}>, extensions?: Maybe<GraphQLErrorExtensions>);
|
|
23
|
+
}
|
|
24
|
+
export declare function isGraphQLErrorLike(error: any): boolean;
|
|
13
25
|
export declare function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError;
|
|
14
|
-
|
|
26
|
+
type SchemaCoordinateInfo = {
|
|
27
|
+
fieldName: string;
|
|
28
|
+
parentType: {
|
|
29
|
+
name: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare function getSchemaCoordinate(error: GraphQLError): string | undefined;
|
|
33
|
+
export declare function locatedError(rawError: unknown, nodes: ASTNode | ReadonlyArray<ASTNode> | undefined, path: Maybe<ReadonlyArray<string | number>>, info: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
|
|
34
|
+
export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>, info?: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
|
|
15
35
|
export {};
|
package/typings/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTNode,
|
|
1
|
+
import { GraphQLError as _GraphQLError, ASTNode, GraphQLErrorExtensions, Source } from 'graphql';
|
|
2
2
|
import { Maybe } from './types.js';
|
|
3
3
|
interface GraphQLErrorOptions {
|
|
4
4
|
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
|
|
@@ -9,7 +9,27 @@ interface GraphQLErrorOptions {
|
|
|
9
9
|
readonly extensions?: unknown;
|
|
10
10
|
}>;
|
|
11
11
|
extensions?: any;
|
|
12
|
+
coordinate?: string;
|
|
12
13
|
}
|
|
14
|
+
export declare class GraphQLError extends _GraphQLError {
|
|
15
|
+
readonly coordinate?: string;
|
|
16
|
+
constructor(message: string, options?: Maybe<GraphQLErrorOptions>);
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
|
|
19
|
+
*/
|
|
20
|
+
constructor(message: string, nodes?: ReadonlyArray<ASTNode> | ASTNode | null, source?: Maybe<Source>, positions?: Maybe<ReadonlyArray<number>>, path?: Maybe<ReadonlyArray<string | number>>, originalError?: Maybe<Error & {
|
|
21
|
+
readonly extensions?: unknown;
|
|
22
|
+
}>, extensions?: Maybe<GraphQLErrorExtensions>);
|
|
23
|
+
}
|
|
24
|
+
export declare function isGraphQLErrorLike(error: any): boolean;
|
|
13
25
|
export declare function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError;
|
|
14
|
-
|
|
26
|
+
type SchemaCoordinateInfo = {
|
|
27
|
+
fieldName: string;
|
|
28
|
+
parentType: {
|
|
29
|
+
name: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare function getSchemaCoordinate(error: GraphQLError): string | undefined;
|
|
33
|
+
export declare function locatedError(rawError: unknown, nodes: ASTNode | ReadonlyArray<ASTNode> | undefined, path: Maybe<ReadonlyArray<string | number>>, info: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
|
|
34
|
+
export declare function relocatedError(originalError: GraphQLError, path?: ReadonlyArray<string | number>, info?: SchemaCoordinateInfo | false | null | undefined): GraphQLError;
|
|
15
35
|
export {};
|