@graphql-tools/utils 10.7.2 → 12.0.1
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/astFromValue.js +21 -14
- package/cjs/build-operation-for-field.js +13 -3
- package/cjs/collectFields.js +4 -3
- package/cjs/comments.js +1 -1
- package/cjs/defaultValueAstFromType.js +32 -0
- package/cjs/descriptionFromObject.js +7 -5
- package/cjs/errors.js +30 -4
- package/cjs/getArgumentValues.js +23 -15
- package/cjs/getDirectiveValues.js +15 -0
- package/cjs/heal.js +4 -1
- package/cjs/helpers.js +40 -4
- package/cjs/index.js +8 -5
- package/cjs/jsutils.js +4 -6
- package/cjs/mapSchema.js +2 -1
- package/cjs/mergeDeep.js +35 -9
- package/cjs/mergeIncrementalResult.js +25 -4
- package/cjs/observableToAsyncIterable.js +29 -17
- package/cjs/print-schema-with-directives.js +23 -17
- package/cjs/registerAbortSignalListener.js +5 -1
- package/cjs/stub.js +1 -0
- package/cjs/updateArgument.js +2 -1
- package/cjs/visitResult.js +7 -1
- package/esm/astFromValue.js +21 -14
- package/esm/build-operation-for-field.js +13 -3
- package/esm/collectFields.js +2 -1
- package/esm/comments.js +1 -1
- package/esm/defaultValueAstFromType.js +28 -0
- package/esm/descriptionFromObject.js +7 -5
- package/esm/errors.js +29 -6
- package/esm/getArgumentValues.js +24 -16
- package/esm/getDirectiveValues.js +12 -0
- package/esm/heal.js +4 -1
- package/esm/helpers.js +39 -4
- package/esm/index.js +3 -4
- package/esm/jsutils.js +3 -5
- package/esm/mapSchema.js +2 -1
- package/esm/mergeDeep.js +35 -9
- package/esm/mergeIncrementalResult.js +25 -4
- package/esm/observableToAsyncIterable.js +28 -16
- package/esm/print-schema-with-directives.js +24 -18
- package/esm/registerAbortSignalListener.js +5 -1
- package/esm/stub.js +1 -0
- package/esm/updateArgument.js +2 -1
- package/esm/visitResult.js +7 -1
- package/package.json +3 -3
- package/typings/Interfaces.d.cts +39 -0
- package/typings/Interfaces.d.ts +39 -0
- package/typings/collectFields.d.cts +5 -6
- package/typings/collectFields.d.ts +5 -6
- package/typings/defaultValueAstFromType.d.cts +9 -0
- package/typings/defaultValueAstFromType.d.ts +9 -0
- package/typings/errors.d.cts +19 -1
- package/typings/errors.d.ts +19 -1
- package/typings/executor.d.cts +4 -7
- package/typings/executor.d.ts +4 -7
- package/typings/getDirectiveExtensions.d.cts +1 -3
- package/typings/getDirectiveExtensions.d.ts +1 -3
- package/typings/getDirectiveValues.d.cts +10 -0
- package/typings/getDirectiveValues.d.ts +10 -0
- package/typings/helpers.d.cts +28 -2
- package/typings/helpers.d.ts +28 -2
- package/typings/index.d.cts +3 -4
- package/typings/index.d.ts +3 -4
- package/typings/jsutils.d.cts +2 -2
- package/typings/jsutils.d.ts +2 -2
- package/typings/mergeDeep.d.cts +1 -1
- package/typings/mergeDeep.d.ts +1 -1
- package/typings/print-schema-with-directives.d.cts +1 -0
- package/typings/print-schema-with-directives.d.ts +1 -0
- package/typings/registerAbortSignalListener.d.cts +1 -1
- package/typings/registerAbortSignalListener.d.ts +1 -1
- package/typings/types.d.cts +25 -1
- package/typings/types.d.ts +25 -1
- package/cjs/createDeferred.js +0 -15
- package/cjs/fakePromise.js +0 -63
- package/cjs/map-maybe-promise.js +0 -26
- package/cjs/mapAsyncIterator.js +0 -75
- package/esm/createDeferred.js +0 -12
- package/esm/fakePromise.js +0 -59
- package/esm/map-maybe-promise.js +0 -23
- package/esm/mapAsyncIterator.js +0 -72
- package/typings/createDeferred.d.cts +0 -6
- package/typings/createDeferred.d.ts +0 -6
- package/typings/fakePromise.d.cts +0 -4
- package/typings/fakePromise.d.ts +0 -4
- package/typings/map-maybe-promise.d.cts +0 -2
- package/typings/map-maybe-promise.d.ts +0 -2
- package/typings/mapAsyncIterator.d.cts +0 -6
- package/typings/mapAsyncIterator.d.ts +0 -6
package/cjs/astFromValue.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.astFromValue = astFromValue;
|
|
4
|
-
const cross_inspect_1 = require("cross-inspect");
|
|
5
4
|
const graphql_1 = require("graphql");
|
|
6
5
|
const astFromValueUntyped_js_1 = require("./astFromValueUntyped.js");
|
|
7
6
|
const jsutils_js_1 = require("./jsutils.js");
|
|
@@ -81,24 +80,32 @@ function astFromValue(value, type) {
|
|
|
81
80
|
if ((0, graphql_1.isLeafType)(type)) {
|
|
82
81
|
// Since value is an internally represented value, it must be serialized
|
|
83
82
|
// to an externally represented value before converting into an AST.
|
|
84
|
-
const serialized = type.serialize(value);
|
|
85
|
-
if (serialized == null) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
83
|
if ((0, graphql_1.isEnumType)(type)) {
|
|
89
|
-
|
|
84
|
+
const values = type.getValues();
|
|
85
|
+
for (const enumValue of values) {
|
|
86
|
+
if (enumValue.value === value) {
|
|
87
|
+
value = enumValue.name;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (enumValue.name === value) {
|
|
91
|
+
value = enumValue.name;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { kind: graphql_1.Kind.ENUM, value: value };
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
value = type.serialize(value);
|
|
99
|
+
}
|
|
100
|
+
if (value == null) {
|
|
101
|
+
return null;
|
|
90
102
|
}
|
|
91
103
|
// ID types can use Int literals.
|
|
92
|
-
if (type.name === 'ID' &&
|
|
93
|
-
|
|
94
|
-
integerStringRegExp.test(serialized)) {
|
|
95
|
-
return { kind: graphql_1.Kind.INT, value: serialized };
|
|
104
|
+
if (type.name === 'ID' && typeof value === 'string' && integerStringRegExp.test(value)) {
|
|
105
|
+
return { kind: graphql_1.Kind.INT, value };
|
|
96
106
|
}
|
|
97
|
-
return (0, astFromValueUntyped_js_1.astFromValueUntyped)(serialized);
|
|
98
107
|
}
|
|
99
|
-
|
|
100
|
-
// Not reachable, all possible types have been considered.
|
|
101
|
-
console.assert(false, 'Unexpected input type: ' + (0, cross_inspect_1.inspect)(type));
|
|
108
|
+
return (0, astFromValueUntyped_js_1.astFromValueUntyped)(value);
|
|
102
109
|
}
|
|
103
110
|
/**
|
|
104
111
|
* IntValue:
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildOperationNodeForField = buildOperationNodeForField;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
+
const astFromValueUntyped_js_1 = require("./astFromValueUntyped.js");
|
|
6
|
+
const defaultValueAstFromType_js_1 = require("./defaultValueAstFromType.js");
|
|
5
7
|
const rootTypes_js_1 = require("./rootTypes.js");
|
|
6
8
|
let operationVariables = [];
|
|
7
9
|
let fieldTypeMap = new Map();
|
|
@@ -241,6 +243,13 @@ function resolveVariable(arg, name) {
|
|
|
241
243
|
},
|
|
242
244
|
};
|
|
243
245
|
}
|
|
246
|
+
let defaultValue;
|
|
247
|
+
try {
|
|
248
|
+
defaultValue = (0, defaultValueAstFromType_js_1.defaultValueAstFromType)(arg);
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
defaultValue = (0, astFromValueUntyped_js_1.astFromValueUntyped)(arg.defaultValue) ?? undefined;
|
|
252
|
+
}
|
|
244
253
|
return {
|
|
245
254
|
kind: graphql_1.Kind.VARIABLE_DEFINITION,
|
|
246
255
|
variable: {
|
|
@@ -251,6 +260,7 @@ function resolveVariable(arg, name) {
|
|
|
251
260
|
},
|
|
252
261
|
},
|
|
253
262
|
type: resolveVariableType(arg.type),
|
|
263
|
+
defaultValue,
|
|
254
264
|
};
|
|
255
265
|
}
|
|
256
266
|
function getArgumentName(name, path) {
|
|
@@ -299,9 +309,9 @@ function resolveField({ type, field, models, firstCall, path, ancestors, ignore,
|
|
|
299
309
|
if (fieldTypeMap.has(fieldPathStr) && fieldTypeMap.get(fieldPathStr) !== field.type.toString()) {
|
|
300
310
|
fieldName += field.type
|
|
301
311
|
.toString()
|
|
302
|
-
.replace(
|
|
303
|
-
.replace(
|
|
304
|
-
.replace(
|
|
312
|
+
.replace(/!/g, 'NonNull')
|
|
313
|
+
.replace(/\[/g, 'List')
|
|
314
|
+
.replace(/\]/g, '');
|
|
305
315
|
}
|
|
306
316
|
fieldTypeMap.set(fieldPathStr, field.type.toString());
|
|
307
317
|
if (!(0, graphql_1.isScalarType)(namedType) && !(0, graphql_1.isEnumType)(namedType)) {
|
package/cjs/collectFields.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.getDeferValues = getDeferValues;
|
|
|
9
9
|
const graphql_1 = require("graphql");
|
|
10
10
|
const AccumulatorMap_js_1 = require("./AccumulatorMap.js");
|
|
11
11
|
const directives_js_1 = require("./directives.js");
|
|
12
|
+
const getDirectiveValues_js_1 = require("./getDirectiveValues.js");
|
|
12
13
|
const memoize_js_1 = require("./memoize.js");
|
|
13
14
|
function collectFieldsImpl(schema, fragments, variableValues, runtimeType, selectionSet, fields, patches, visitedFragmentNames) {
|
|
14
15
|
for (const selection of selectionSet.selections) {
|
|
@@ -90,11 +91,11 @@ function collectFields(schema, fragments, variableValues, runtimeType, selection
|
|
|
90
91
|
* directives, where `@skip` has higher precedence than `@include`.
|
|
91
92
|
*/
|
|
92
93
|
function shouldIncludeNode(variableValues, node) {
|
|
93
|
-
const skip = (0,
|
|
94
|
+
const skip = (0, getDirectiveValues_js_1.getDirectiveValues)(graphql_1.GraphQLSkipDirective, node, variableValues);
|
|
94
95
|
if (skip?.['if'] === true) {
|
|
95
96
|
return false;
|
|
96
97
|
}
|
|
97
|
-
const include = (0,
|
|
98
|
+
const include = (0, getDirectiveValues_js_1.getDirectiveValues)(graphql_1.GraphQLIncludeDirective, node, variableValues);
|
|
98
99
|
if (include?.['if'] === false) {
|
|
99
100
|
return false;
|
|
100
101
|
}
|
|
@@ -130,7 +131,7 @@ function getFieldEntryKey(node) {
|
|
|
130
131
|
* not disabled by the "if" argument.
|
|
131
132
|
*/
|
|
132
133
|
function getDeferValues(variableValues, node) {
|
|
133
|
-
const defer = (0,
|
|
134
|
+
const defer = (0, getDirectiveValues_js_1.getDirectiveValues)(directives_js_1.GraphQLDeferDirective, node, variableValues);
|
|
134
135
|
if (!defer) {
|
|
135
136
|
return;
|
|
136
137
|
}
|
package/cjs/comments.js
CHANGED
|
@@ -127,7 +127,7 @@ function wrap(start, maybeString, end) {
|
|
|
127
127
|
* a single-line, adding a leading blank line would strip that whitespace.
|
|
128
128
|
*/
|
|
129
129
|
function printBlockString(value, isDescription = false) {
|
|
130
|
-
const escaped = value.replace(/"""/g, '\\"""');
|
|
130
|
+
const escaped = value.replace(/\\/g, '\\\\').replace(/"""/g, '\\"""');
|
|
131
131
|
return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1
|
|
132
132
|
? `"""${escaped.replace(/"$/, '"\n')}"""`
|
|
133
133
|
: `"""\n${isDescription ? escaped : indent(escaped)}\n"""`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultValueAstFromType = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const astFromValue_js_1 = require("./astFromValue.js");
|
|
6
|
+
const astFromValueUntyped_js_1 = require("./astFromValueUntyped.js");
|
|
7
|
+
/**
|
|
8
|
+
* `defaultValueAstFromType` extracts default value from `GraphQLArgument` or `GraphQLInputField`, if available
|
|
9
|
+
* This is compatible with all `graphql` versions
|
|
10
|
+
*
|
|
11
|
+
* The return type is `ConstValueNode` in graphql@16+,
|
|
12
|
+
* but it is not available in graphql@15 so `ValueNode` is used as return type here and `as any` is often required at callsites for backwards compatibility,
|
|
13
|
+
*/
|
|
14
|
+
const defaultValueAstFromType = (arg) => {
|
|
15
|
+
// graphql >= v17 has `default` instead of `defaultValue`
|
|
16
|
+
// So for backward compatibility with v16, we are using `arg.default as any`, otherwise, TypeScript report type error
|
|
17
|
+
if ('default' in arg) {
|
|
18
|
+
if (!arg.default) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if ('value' in arg.default) {
|
|
22
|
+
return (0, astFromValueUntyped_js_1.astFromValueUntyped)(arg.default.value) ?? undefined;
|
|
23
|
+
}
|
|
24
|
+
const value = (0, graphql_1.valueFromASTUntyped)(arg.default.literal);
|
|
25
|
+
return (0, astFromValue_js_1.astFromValue)(value, arg.type) ?? undefined;
|
|
26
|
+
}
|
|
27
|
+
// graphql < v17 has `defaultValue` instead of `default`
|
|
28
|
+
return arg.defaultValue !== undefined
|
|
29
|
+
? ((0, astFromValue_js_1.astFromValue)(arg.defaultValue, arg.type) ?? undefined)
|
|
30
|
+
: undefined;
|
|
31
|
+
};
|
|
32
|
+
exports.defaultValueAstFromType = defaultValueAstFromType;
|
|
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDescriptionNode = getDescriptionNode;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
function getDescriptionNode(obj) {
|
|
6
|
-
|
|
6
|
+
// Prefer the runtime `description` over a stale `astNode` description.
|
|
7
|
+
// Schema transforms (e.g. mapSchema) update config descriptions without rewriting astNode (#5508).
|
|
8
|
+
if (typeof obj.description === 'string') {
|
|
7
9
|
return {
|
|
8
|
-
|
|
10
|
+
kind: graphql_1.Kind.STRING,
|
|
11
|
+
value: obj.description,
|
|
9
12
|
block: true,
|
|
10
13
|
};
|
|
11
14
|
}
|
|
12
|
-
if (obj.description) {
|
|
15
|
+
if (obj.astNode?.description) {
|
|
13
16
|
return {
|
|
14
|
-
|
|
15
|
-
value: obj.description,
|
|
17
|
+
...obj.astNode.description,
|
|
16
18
|
block: true,
|
|
17
19
|
};
|
|
18
20
|
}
|
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 = [
|
|
@@ -14,6 +17,7 @@ const possibleGraphQLErrorProperties = [
|
|
|
14
17
|
'name',
|
|
15
18
|
'stack',
|
|
16
19
|
'extensions',
|
|
20
|
+
'coordinate',
|
|
17
21
|
];
|
|
18
22
|
function isGraphQLErrorLike(error) {
|
|
19
23
|
return (error != null &&
|
|
@@ -26,12 +30,33 @@ function createGraphQLError(message, options) {
|
|
|
26
30
|
isGraphQLErrorLike(options.originalError)) {
|
|
27
31
|
options.originalError = createGraphQLError(options.originalError.message, options.originalError);
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
// To avoid type error on graphql <16, we have to use an any type here
|
|
34
|
+
const Constructor = graphql_1.GraphQLError;
|
|
35
|
+
const error = graphql_1.versionInfo.major >= 16
|
|
36
|
+
? new Constructor(message, options)
|
|
37
|
+
: new Constructor(message, options?.nodes, options?.source, options?.positions, options?.path, options?.originalError, options?.extensions);
|
|
38
|
+
if (options?.coordinate && error.coordinate == null) {
|
|
39
|
+
Object.defineProperties(error, {
|
|
40
|
+
coordinate: { value: options.coordinate, enumerable: true, configurable: true },
|
|
41
|
+
});
|
|
31
42
|
}
|
|
32
|
-
return
|
|
43
|
+
return error;
|
|
33
44
|
}
|
|
34
|
-
function
|
|
45
|
+
function getSchemaCoordinate(error) {
|
|
46
|
+
return error.coordinate;
|
|
47
|
+
}
|
|
48
|
+
function locatedError(rawError, nodes, path, info) {
|
|
49
|
+
const error = (0, graphql_1.locatedError)(rawError, nodes, path);
|
|
50
|
+
// `graphql` locatedError is only changing path and nodes if it is not already defined
|
|
51
|
+
if (!error.coordinate && info && error.coordinate == null) {
|
|
52
|
+
const coordinate = `${info.parentType.name}.${info.fieldName}`;
|
|
53
|
+
Object.defineProperties(error, {
|
|
54
|
+
coordinate: { value: coordinate, enumerable: true, configurable: true },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return error;
|
|
58
|
+
}
|
|
59
|
+
function relocatedError(originalError, path, info) {
|
|
35
60
|
return createGraphQLError(originalError.message, {
|
|
36
61
|
nodes: originalError.nodes,
|
|
37
62
|
source: originalError.source,
|
|
@@ -39,5 +64,6 @@ function relocatedError(originalError, path) {
|
|
|
39
64
|
path: path == null ? originalError.path : path,
|
|
40
65
|
originalError,
|
|
41
66
|
extensions: originalError.extensions,
|
|
67
|
+
coordinate: info ? `${info.parentType.name}.${info.fieldName}` : undefined,
|
|
42
68
|
});
|
|
43
69
|
}
|
package/cjs/getArgumentValues.js
CHANGED
|
@@ -20,14 +20,22 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
20
20
|
...prev,
|
|
21
21
|
[arg.name.value]: arg,
|
|
22
22
|
}), {});
|
|
23
|
-
for (const
|
|
24
|
-
const argumentNode = argNodeMap[name];
|
|
23
|
+
for (const arg of def.args) {
|
|
24
|
+
const argumentNode = argNodeMap[arg.name];
|
|
25
25
|
if (!argumentNode) {
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
if ('default' in arg && arg.default) {
|
|
27
|
+
// graphql v17
|
|
28
|
+
coercedValues[arg.name] =
|
|
29
|
+
'value' in arg.default
|
|
30
|
+
? arg.default.value
|
|
31
|
+
: (0, graphql_1.valueFromASTUntyped)(arg.default.literal);
|
|
28
32
|
}
|
|
29
|
-
else if (
|
|
30
|
-
|
|
33
|
+
else if (arg.defaultValue !== undefined) {
|
|
34
|
+
// graphql < v17
|
|
35
|
+
coercedValues[arg.name] = arg.defaultValue;
|
|
36
|
+
}
|
|
37
|
+
else if ((0, graphql_1.isNonNullType)(arg.type)) {
|
|
38
|
+
throw (0, errors_js_1.createGraphQLError)(`Argument "${arg.name}" of required type "${(0, cross_inspect_1.inspect)(arg.type)}" ` + 'was not provided.', {
|
|
31
39
|
nodes: [node],
|
|
32
40
|
});
|
|
33
41
|
}
|
|
@@ -38,11 +46,11 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
38
46
|
if (valueNode.kind === graphql_1.Kind.VARIABLE) {
|
|
39
47
|
const variableName = valueNode.name.value;
|
|
40
48
|
if (variableValues == null || !(0, jsutils_js_1.hasOwnProperty)(variableValues, variableName)) {
|
|
41
|
-
if (defaultValue !== undefined) {
|
|
42
|
-
coercedValues[name] = defaultValue;
|
|
49
|
+
if (arg.defaultValue !== undefined) {
|
|
50
|
+
coercedValues[arg.name] = arg.defaultValue;
|
|
43
51
|
}
|
|
44
|
-
else if ((0, graphql_1.isNonNullType)(
|
|
45
|
-
throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of required type "${(0, cross_inspect_1.inspect)(
|
|
52
|
+
else if ((0, graphql_1.isNonNullType)(arg.type)) {
|
|
53
|
+
throw (0, errors_js_1.createGraphQLError)(`Argument "${arg.name}" of required type "${(0, cross_inspect_1.inspect)(arg.type)}" ` +
|
|
46
54
|
`was provided the variable "$${variableName}" which was not provided a runtime value.`, {
|
|
47
55
|
nodes: [valueNode],
|
|
48
56
|
});
|
|
@@ -51,21 +59,21 @@ function getArgumentValues(def, node, variableValues = {}) {
|
|
|
51
59
|
}
|
|
52
60
|
isNull = variableValues[variableName] == null;
|
|
53
61
|
}
|
|
54
|
-
if (isNull && (0, graphql_1.isNonNullType)(
|
|
55
|
-
throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" of non-null type "${(0, cross_inspect_1.inspect)(
|
|
62
|
+
if (isNull && (0, graphql_1.isNonNullType)(arg.type)) {
|
|
63
|
+
throw (0, errors_js_1.createGraphQLError)(`Argument "${arg.name}" of non-null type "${(0, cross_inspect_1.inspect)(arg.type)}" ` + 'must not be null.', {
|
|
56
64
|
nodes: [valueNode],
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
|
-
const coercedValue = (0, graphql_1.valueFromAST)(valueNode,
|
|
67
|
+
const coercedValue = (0, graphql_1.valueFromAST)(valueNode, arg.type, variableValues);
|
|
60
68
|
if (coercedValue === undefined) {
|
|
61
69
|
// Note: ValuesOfCorrectTypeRule validation should catch this before
|
|
62
70
|
// execution. This is a runtime check to ensure execution does not
|
|
63
71
|
// continue with an invalid argument value.
|
|
64
|
-
throw (0, errors_js_1.createGraphQLError)(`Argument "${name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, {
|
|
72
|
+
throw (0, errors_js_1.createGraphQLError)(`Argument "${arg.name}" has invalid value ${(0, graphql_1.print)(valueNode)}.`, {
|
|
65
73
|
nodes: [valueNode],
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
|
-
coercedValues[name] = coercedValue;
|
|
76
|
+
coercedValues[arg.name] = coercedValue;
|
|
69
77
|
}
|
|
70
78
|
return coercedValues;
|
|
71
79
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDirectiveValues = getDirectiveValues;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
/**
|
|
6
|
+
* GraphQL v17's getDirectiveValues function accepts `VariableValues`
|
|
7
|
+
* while older versions accept `Record<string, any>`. This function wraps the original
|
|
8
|
+
* getDirectiveValues function to provide compatibility across versions.
|
|
9
|
+
*/
|
|
10
|
+
function getDirectiveValues(directiveDef, node, variableValues) {
|
|
11
|
+
if (graphql_1.versionInfo.major >= 17) {
|
|
12
|
+
return (0, graphql_1.getDirectiveValues)(directiveDef, node, variableValues);
|
|
13
|
+
}
|
|
14
|
+
return (0, graphql_1.getDirectiveValues)(directiveDef, node, variableValues?.coerced);
|
|
15
|
+
}
|
package/cjs/heal.js
CHANGED
|
@@ -158,7 +158,10 @@ function healTypes(originalTypeMap, directives) {
|
|
|
158
158
|
}
|
|
159
159
|
else if ((0, graphql_1.isNonNullType)(type)) {
|
|
160
160
|
const healedType = healType(type.ofType);
|
|
161
|
-
return healedType != null
|
|
161
|
+
return healedType != null
|
|
162
|
+
? // FIXME: `healedType` needs `as any` as graphql@17 changes the type for `GraphQLType`
|
|
163
|
+
new graphql_1.GraphQLNonNull(healedType)
|
|
164
|
+
: null;
|
|
162
165
|
}
|
|
163
166
|
else if ((0, graphql_1.isNamedType)(type)) {
|
|
164
167
|
// If a type annotation on a field or an argument or a union member is
|
package/cjs/helpers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.asArray = void 0;
|
|
4
|
+
exports.isUrl = isUrl;
|
|
4
5
|
exports.isDocumentString = isDocumentString;
|
|
5
6
|
exports.isValidPath = isValidPath;
|
|
6
7
|
exports.compareStrings = compareStrings;
|
|
@@ -9,7 +10,27 @@ exports.compareNodes = compareNodes;
|
|
|
9
10
|
exports.isSome = isSome;
|
|
10
11
|
exports.assertSome = assertSome;
|
|
11
12
|
const graphql_1 = require("graphql");
|
|
12
|
-
|
|
13
|
+
const URL_REGEXP = /^(https?|wss?|file):\/\//;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the given string is a valid URL.
|
|
16
|
+
*
|
|
17
|
+
* @param str - The string to validate as a URL
|
|
18
|
+
* @returns A boolean indicating whether the string is a valid URL
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This function first attempts to use the `URL.canParse` method if available.
|
|
22
|
+
* If not, it falls back to creating a new `URL` object to validate the string.
|
|
23
|
+
*/
|
|
24
|
+
function isUrl(str) {
|
|
25
|
+
if (typeof str !== 'string') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (!URL_REGEXP.test(str)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (URL.canParse) {
|
|
32
|
+
return URL.canParse(str);
|
|
33
|
+
}
|
|
13
34
|
try {
|
|
14
35
|
const url = new URL(str);
|
|
15
36
|
return !!url;
|
|
@@ -21,6 +42,21 @@ function isURL(str) {
|
|
|
21
42
|
const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
|
|
22
43
|
exports.asArray = asArray;
|
|
23
44
|
const invalidDocRegex = /\.[a-z0-9]+$/i;
|
|
45
|
+
/**
|
|
46
|
+
* Determines if a given input is a valid GraphQL document string.
|
|
47
|
+
*
|
|
48
|
+
* @param str - The input to validate as a GraphQL document
|
|
49
|
+
* @returns A boolean indicating whether the input is a valid GraphQL document string
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* This function performs several validation checks:
|
|
53
|
+
* - Ensures the input is a string
|
|
54
|
+
* - Filters out strings with invalid document extensions
|
|
55
|
+
* - Excludes URLs
|
|
56
|
+
* - Attempts to parse the string as a GraphQL document
|
|
57
|
+
*
|
|
58
|
+
* @throws {Error} If the document fails to parse and is empty except GraphQL comments
|
|
59
|
+
*/
|
|
24
60
|
function isDocumentString(str) {
|
|
25
61
|
if (typeof str !== 'string') {
|
|
26
62
|
return false;
|
|
@@ -30,7 +66,7 @@ function isDocumentString(str) {
|
|
|
30
66
|
// this why checking the extension is fast enough
|
|
31
67
|
// and prevent from parsing the string in order to find out
|
|
32
68
|
// if the string is a SDL
|
|
33
|
-
if (invalidDocRegex.test(str) ||
|
|
69
|
+
if (invalidDocRegex.test(str) || isUrl(str)) {
|
|
34
70
|
return false;
|
|
35
71
|
}
|
|
36
72
|
try {
|
|
@@ -46,9 +82,9 @@ function isDocumentString(str) {
|
|
|
46
82
|
}
|
|
47
83
|
return false;
|
|
48
84
|
}
|
|
49
|
-
const invalidPathRegex = /[
|
|
85
|
+
const invalidPathRegex = /[‘“!^<>`\n]/;
|
|
50
86
|
/**
|
|
51
|
-
*
|
|
87
|
+
* Checks whether the `str` contains any path illegal characters.
|
|
52
88
|
*
|
|
53
89
|
* A string may sometimes look like a path but is not (like an SDL of a simple
|
|
54
90
|
* GraphQL schema). To make sure we don't yield false-positives in such cases,
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inspect = void 0;
|
|
3
|
+
exports.createDeferred = exports.fakePromise = exports.mapMaybePromise = exports.mapAsyncIterator = exports.inspect = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./loaders.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./helpers.js"), exports);
|
|
@@ -32,8 +32,8 @@ tslib_1.__exportStar(require("./getResponseKeyFromInfo.js"), exports);
|
|
|
32
32
|
tslib_1.__exportStar(require("./fields.js"), exports);
|
|
33
33
|
tslib_1.__exportStar(require("./renameType.js"), exports);
|
|
34
34
|
tslib_1.__exportStar(require("./transformInputValue.js"), exports);
|
|
35
|
-
tslib_1.__exportStar(require("./mapAsyncIterator.js"), exports);
|
|
36
35
|
tslib_1.__exportStar(require("./updateArgument.js"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./astFromType.js"), exports);
|
|
37
37
|
tslib_1.__exportStar(require("./implementsAbstractType.js"), exports);
|
|
38
38
|
tslib_1.__exportStar(require("./errors.js"), exports);
|
|
39
39
|
tslib_1.__exportStar(require("./observableToAsyncIterable.js"), exports);
|
|
@@ -60,7 +60,10 @@ tslib_1.__exportStar(require("./directives.js"), exports);
|
|
|
60
60
|
tslib_1.__exportStar(require("./mergeIncrementalResult.js"), exports);
|
|
61
61
|
tslib_1.__exportStar(require("./debugTimer.js"), exports);
|
|
62
62
|
tslib_1.__exportStar(require("./getDirectiveExtensions.js"), exports);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
var promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
64
|
+
Object.defineProperty(exports, "mapAsyncIterator", { enumerable: true, get: function () { return promise_helpers_1.mapAsyncIterator; } });
|
|
65
|
+
Object.defineProperty(exports, "mapMaybePromise", { enumerable: true, get: function () { return promise_helpers_1.mapMaybePromise; } });
|
|
66
|
+
Object.defineProperty(exports, "fakePromise", { enumerable: true, get: function () { return promise_helpers_1.fakePromise; } });
|
|
67
|
+
Object.defineProperty(exports, "createDeferred", { enumerable: true, get: function () { return promise_helpers_1.createDeferredPromise; } });
|
|
66
68
|
tslib_1.__exportStar(require("./registerAbortSignalListener.js"), exports);
|
|
69
|
+
tslib_1.__exportStar(require("./getDirectiveValues.js"), exports);
|
package/cjs/jsutils.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPromise = void 0;
|
|
3
4
|
exports.isIterableObject = isIterableObject;
|
|
4
5
|
exports.isObjectLike = isObjectLike;
|
|
5
|
-
exports.isPromise = isPromise;
|
|
6
6
|
exports.promiseReduce = promiseReduce;
|
|
7
7
|
exports.hasOwnProperty = hasOwnProperty;
|
|
8
|
-
const
|
|
8
|
+
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
|
9
|
+
Object.defineProperty(exports, "isPromise", { enumerable: true, get: function () { return promise_helpers_1.isPromise; } });
|
|
9
10
|
function isIterableObject(value) {
|
|
10
11
|
return value != null && typeof value === 'object' && Symbol.iterator in value;
|
|
11
12
|
}
|
|
12
13
|
function isObjectLike(value) {
|
|
13
14
|
return typeof value === 'object' && value !== null;
|
|
14
15
|
}
|
|
15
|
-
function isPromise(value) {
|
|
16
|
-
return value?.then != null;
|
|
17
|
-
}
|
|
18
16
|
function promiseReduce(values, callbackFn, initialValue) {
|
|
19
17
|
let accumulator = initialValue;
|
|
20
18
|
for (const value of values) {
|
|
21
|
-
accumulator = (0,
|
|
19
|
+
accumulator = (0, promise_helpers_1.handleMaybePromise)(() => accumulator, resolved => callbackFn(resolved, value));
|
|
22
20
|
}
|
|
23
21
|
return accumulator;
|
|
24
22
|
}
|
package/cjs/mapSchema.js
CHANGED
|
@@ -21,10 +21,11 @@ function mapSchema(schema, schemaMapper = {}) {
|
|
|
21
21
|
directives,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
const builtinTypes = ['String', 'ID', 'Int', 'Float', 'Boolean'];
|
|
24
25
|
function mapTypes(originalTypeMap, schema, schemaMapper, testFn = () => true) {
|
|
25
26
|
const newTypeMap = {};
|
|
26
27
|
for (const typeName in originalTypeMap) {
|
|
27
|
-
if (!typeName.startsWith('__')) {
|
|
28
|
+
if (!typeName.startsWith('__') && !builtinTypes.includes(typeName)) {
|
|
28
29
|
const originalType = originalTypeMap[typeName];
|
|
29
30
|
if (originalType == null || !testFn(originalType)) {
|
|
30
31
|
newTypeMap[typeName] = originalType;
|
package/cjs/mergeDeep.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeDeep = mergeDeep;
|
|
4
4
|
const helpers_js_1 = require("./helpers.js");
|
|
5
|
-
function mergeDeep(sources, respectPrototype = false, respectArrays = false, respectArrayLength = false) {
|
|
5
|
+
function mergeDeep(sources, respectPrototype = false, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
|
|
6
|
+
if (sources.length === 0) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (sources.length === 1) {
|
|
10
|
+
return sources[0];
|
|
11
|
+
}
|
|
6
12
|
let expectedLength;
|
|
7
13
|
let allArrays = true;
|
|
8
14
|
const areArraysInTheSameLength = sources.every(source => {
|
|
@@ -21,7 +27,7 @@ function mergeDeep(sources, respectPrototype = false, respectArrays = false, res
|
|
|
21
27
|
return false;
|
|
22
28
|
});
|
|
23
29
|
if (respectArrayLength && areArraysInTheSameLength) {
|
|
24
|
-
return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength));
|
|
30
|
+
return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength, respectNonEnumerableSymbols));
|
|
25
31
|
}
|
|
26
32
|
if (allArrays) {
|
|
27
33
|
return sources.flat(1);
|
|
@@ -30,15 +36,21 @@ function mergeDeep(sources, respectPrototype = false, respectArrays = false, res
|
|
|
30
36
|
let firstObjectSource;
|
|
31
37
|
if (respectPrototype) {
|
|
32
38
|
firstObjectSource = sources.find(source => isObject(source));
|
|
33
|
-
if (output == null) {
|
|
34
|
-
output = {};
|
|
35
|
-
}
|
|
36
39
|
if (firstObjectSource) {
|
|
40
|
+
if (output == null) {
|
|
41
|
+
output = {};
|
|
42
|
+
}
|
|
37
43
|
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(firstObjectSource)));
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
for (const source of sources) {
|
|
47
|
+
if (source === undefined) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
41
50
|
if (isObject(source)) {
|
|
51
|
+
if (output == null) {
|
|
52
|
+
output = {};
|
|
53
|
+
}
|
|
42
54
|
if (firstObjectSource) {
|
|
43
55
|
const outputPrototype = Object.getPrototypeOf(output);
|
|
44
56
|
const sourcePrototype = Object.getPrototypeOf(source);
|
|
@@ -52,16 +64,30 @@ function mergeDeep(sources, respectPrototype = false, respectArrays = false, res
|
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
for (const key in source) {
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
// never let a source key reach the prototype chain
|
|
68
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
69
|
+
continue;
|
|
57
70
|
}
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
// An own key present with value `undefined` is an explicit override and must win,
|
|
72
|
+
// distinct from the key being altogether absent from `source`. Assigning directly
|
|
73
|
+
// (rather than recursing through mergeDeep) avoids the top-level `source === undefined`
|
|
74
|
+
// skip above, which would otherwise silently discard this override and keep the prior
|
|
75
|
+
// value.
|
|
76
|
+
if (Object.prototype.hasOwnProperty.call(output, key) && source[key] !== undefined) {
|
|
77
|
+
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength, respectNonEnumerableSymbols);
|
|
60
78
|
}
|
|
61
79
|
else {
|
|
62
80
|
output[key] = source[key];
|
|
63
81
|
}
|
|
64
82
|
}
|
|
83
|
+
if (respectNonEnumerableSymbols && output != null) {
|
|
84
|
+
for (const sym of Object.getOwnPropertySymbols(source)) {
|
|
85
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, sym);
|
|
86
|
+
if (!descriptor.enumerable) {
|
|
87
|
+
Object.defineProperty(output, sym, descriptor);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
65
91
|
}
|
|
66
92
|
else if (Array.isArray(source)) {
|
|
67
93
|
if (!Array.isArray(output)) {
|
|
@@ -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 mergeDeep_js_1 = require("./mergeDeep.js");
|
|
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
|
+
setObjectKeyPath(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
|
+
setObjectKeyPath(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
|
+
setObjectKeyPath(executionResult, ['extensions'], incrementalResult.extensions);
|
|
23
23
|
}
|
|
24
24
|
if (incrementalResult.incremental) {
|
|
25
25
|
incrementalResult.incremental.forEach(incrementalSubResult => {
|
|
@@ -30,3 +30,24 @@ 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
|
+
}
|