@graphql-tools/executor 3.0.0 → 4.0.0-alpha-20261019164611-538e7787be9cdbcfc800aa118defd976f702b538
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/execution/execute.js +9 -3
- package/cjs/execution/index.js +0 -1
- package/esm/execution/execute.js +9 -3
- package/esm/execution/index.js +0 -1
- package/package.json +2 -2
- package/typings/execution/execute.d.cts +2 -1
- package/typings/execution/execute.d.ts +2 -1
- package/typings/execution/index.d.cts +0 -1
- package/typings/execution/index.d.ts +0 -1
- package/cjs/execution/didYouMean.js +0 -20
- package/cjs/execution/formatList.js +0 -31
- package/cjs/execution/naturalCompare.js +0 -55
- package/cjs/execution/suggestionList.js +0 -117
- package/cjs/execution/validateInputValue.js +0 -439
- package/cjs/execution/values.js +0 -140
- package/esm/execution/didYouMean.js +0 -17
- package/esm/execution/formatList.js +0 -27
- package/esm/execution/naturalCompare.js +0 -52
- package/esm/execution/suggestionList.js +0 -114
- package/esm/execution/validateInputValue.js +0 -434
- package/esm/execution/values.js +0 -137
- package/typings/execution/didYouMean.d.cts +0 -8
- package/typings/execution/didYouMean.d.ts +0 -8
- package/typings/execution/formatList.d.cts +0 -12
- package/typings/execution/formatList.d.ts +0 -12
- package/typings/execution/naturalCompare.d.cts +0 -9
- package/typings/execution/naturalCompare.d.ts +0 -9
- package/typings/execution/suggestionList.d.cts +0 -7
- package/typings/execution/suggestionList.d.ts +0 -7
- package/typings/execution/validateInputValue.d.cts +0 -163
- package/typings/execution/validateInputValue.d.ts +0 -163
- package/typings/execution/values.d.cts +0 -24
- package/typings/execution/values.d.ts +0 -24
package/cjs/execution/execute.js
CHANGED
|
@@ -20,7 +20,6 @@ const coerceError_js_1 = require("./coerceError.js");
|
|
|
20
20
|
const flattenAsyncIterable_js_1 = require("./flattenAsyncIterable.js");
|
|
21
21
|
const invariant_js_1 = require("./invariant.js");
|
|
22
22
|
const promiseForObject_js_1 = require("./promiseForObject.js");
|
|
23
|
-
const values_js_1 = require("./values.js");
|
|
24
23
|
const EMPTY_ARGS = Object.freeze(Object.create(null));
|
|
25
24
|
const isGraphQL17 = graphql_1.versionInfo.major >= 17;
|
|
26
25
|
/**
|
|
@@ -241,7 +240,7 @@ function buildExecutionContext(args) {
|
|
|
241
240
|
// FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
242
241
|
/* c8 ignore next */
|
|
243
242
|
const variableDefinitions = operation.variableDefinitions ?? [];
|
|
244
|
-
const coercedVariableValues = (0,
|
|
243
|
+
const coercedVariableValues = (0, graphql_1.getVariableValues)(schema, variableDefinitions, rawVariableValues ?? {}, {
|
|
245
244
|
maxErrors: 50,
|
|
246
245
|
hideSuggestions: hideSuggestions ?? undefined,
|
|
247
246
|
});
|
|
@@ -249,7 +248,14 @@ function buildExecutionContext(args) {
|
|
|
249
248
|
return coercedVariableValues.errors;
|
|
250
249
|
}
|
|
251
250
|
signal?.throwIfAborted();
|
|
252
|
-
|
|
251
|
+
// GraphQL 17 returns { variableValues }; GraphQL 16 returns { coerced }.
|
|
252
|
+
// Cast through unknown: installed graphql typings match only one major.
|
|
253
|
+
const variableValues = isGraphQL17
|
|
254
|
+
? coercedVariableValues.variableValues
|
|
255
|
+
: {
|
|
256
|
+
coerced: coercedVariableValues.coerced,
|
|
257
|
+
sources: Object.create(null),
|
|
258
|
+
};
|
|
253
259
|
const resolveInfoVariableValues = (isGraphQL17 ? variableValues : variableValues.coerced);
|
|
254
260
|
let asyncHelpers;
|
|
255
261
|
const getAbortSignal = () => signal;
|
package/cjs/execution/index.js
CHANGED
|
@@ -2,5 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./execute.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./values.js"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./normalizedExecutor.js"), exports);
|
package/esm/execution/execute.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertValidSchema, getArgumentValues, GraphQLError, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, Kind, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, versionInfo, } from 'graphql';
|
|
1
|
+
import { assertValidSchema, getArgumentValues, getVariableValues, GraphQLError, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, Kind, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, versionInfo, } from 'graphql';
|
|
2
2
|
import { collectSubFields as _collectSubfields, addPath, collectFields, getDefinedRootType, getDirectiveValues, GraphQLStreamDirective, inspect, isAsyncIterable, isIterableObject, isObjectLike, locatedError, memoize2, memoize3, pathToArray, promiseReduce, } from '@graphql-tools/utils';
|
|
3
3
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
4
4
|
import { fakePromise, handleMaybePromise, isPromise, mapAsyncIterator, } from '@whatwg-node/promise-helpers';
|
|
@@ -6,7 +6,6 @@ import { coerceError } from './coerceError.js';
|
|
|
6
6
|
import { flattenAsyncIterable } from './flattenAsyncIterable.js';
|
|
7
7
|
import { invariant } from './invariant.js';
|
|
8
8
|
import { promiseForObject } from './promiseForObject.js';
|
|
9
|
-
import { getVariableValues } from './values.js';
|
|
10
9
|
const EMPTY_ARGS = Object.freeze(Object.create(null));
|
|
11
10
|
const isGraphQL17 = versionInfo.major >= 17;
|
|
12
11
|
/**
|
|
@@ -235,7 +234,14 @@ export function buildExecutionContext(args) {
|
|
|
235
234
|
return coercedVariableValues.errors;
|
|
236
235
|
}
|
|
237
236
|
signal?.throwIfAborted();
|
|
238
|
-
|
|
237
|
+
// GraphQL 17 returns { variableValues }; GraphQL 16 returns { coerced }.
|
|
238
|
+
// Cast through unknown: installed graphql typings match only one major.
|
|
239
|
+
const variableValues = isGraphQL17
|
|
240
|
+
? coercedVariableValues.variableValues
|
|
241
|
+
: {
|
|
242
|
+
coerced: coercedVariableValues.coerced,
|
|
243
|
+
sources: Object.create(null),
|
|
244
|
+
};
|
|
239
245
|
const resolveInfoVariableValues = (isGraphQL17 ? variableValues : variableValues.coerced);
|
|
240
246
|
let asyncHelpers;
|
|
241
247
|
const getAbortSignal = () => signal;
|
package/esm/execution/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/executor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha-20261019164611-538e7787be9cdbcfc800aa118defd976f702b538",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^16.0.0 || ^17.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-tools/utils": "
|
|
9
|
+
"@graphql-tools/utils": "13.0.1-alpha-20261019164611-538e7787be9cdbcfc800aa118defd976f702b538",
|
|
10
10
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
11
11
|
"@repeaterjs/repeater": "^3.1.0",
|
|
12
12
|
"@whatwg-node/disposablestack": "^0.1.0",
|
|
@@ -123,7 +123,8 @@ export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
|
123
123
|
schemaCoordinateInErrors?: boolean;
|
|
124
124
|
/**
|
|
125
125
|
* When true, omit "Did you mean ...?" suggestion text from variable coercion
|
|
126
|
-
* errors
|
|
126
|
+
* errors with GraphQL 17. GraphQL 16 ignores this option.
|
|
127
|
+
* Matches `graphql@17`'s `ExecutionArgs.hideSuggestions`.
|
|
127
128
|
*/
|
|
128
129
|
hideSuggestions?: Maybe<boolean>;
|
|
129
130
|
}
|
|
@@ -123,7 +123,8 @@ export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
|
123
123
|
schemaCoordinateInErrors?: boolean;
|
|
124
124
|
/**
|
|
125
125
|
* When true, omit "Did you mean ...?" suggestion text from variable coercion
|
|
126
|
-
* errors
|
|
126
|
+
* errors with GraphQL 17. GraphQL 16 ignores this option.
|
|
127
|
+
* Matches `graphql@17`'s `ExecutionArgs.hideSuggestions`.
|
|
127
128
|
*/
|
|
128
129
|
hideSuggestions?: Maybe<boolean>;
|
|
129
130
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.didYouMean = didYouMean;
|
|
4
|
-
const formatList_js_1 = require("./formatList.js");
|
|
5
|
-
const MAX_SUGGESTIONS = 5;
|
|
6
|
-
/** @internal */
|
|
7
|
-
function didYouMean(firstArg, secondArg) {
|
|
8
|
-
const [subMessage, suggestions] = secondArg
|
|
9
|
-
? [firstArg, secondArg]
|
|
10
|
-
: [undefined, firstArg];
|
|
11
|
-
if (suggestions.length === 0) {
|
|
12
|
-
return '';
|
|
13
|
-
}
|
|
14
|
-
let message = ' Did you mean ';
|
|
15
|
-
if (subMessage != null) {
|
|
16
|
-
message += subMessage + ' ';
|
|
17
|
-
}
|
|
18
|
-
const suggestionList = (0, formatList_js_1.orList)(suggestions.slice(0, MAX_SUGGESTIONS).map(x => `"${x}"`));
|
|
19
|
-
return message + suggestionList + '?';
|
|
20
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.orList = orList;
|
|
4
|
-
exports.andList = andList;
|
|
5
|
-
/**
|
|
6
|
-
* Given [A, B, C] return 'A, B, or C'.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
function orList(items) {
|
|
11
|
-
return formatList('or', items);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Given [A, B, C] return 'A, B, and C'.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
function andList(items) {
|
|
19
|
-
return formatList('and', items);
|
|
20
|
-
}
|
|
21
|
-
function formatList(conjunction, items) {
|
|
22
|
-
switch (items.length) {
|
|
23
|
-
case 1:
|
|
24
|
-
return items[0];
|
|
25
|
-
case 2:
|
|
26
|
-
return items[0] + ' ' + conjunction + ' ' + items[1];
|
|
27
|
-
}
|
|
28
|
-
const allButLast = items.slice(0, -1);
|
|
29
|
-
const lastItem = items.at(-1);
|
|
30
|
-
return allButLast.join(', ') + ', ' + conjunction + ' ' + lastItem;
|
|
31
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.naturalCompare = naturalCompare;
|
|
4
|
-
/**
|
|
5
|
-
* Returns a number indicating whether a reference string comes before, or after,
|
|
6
|
-
* or is the same as the given string in natural sort order.
|
|
7
|
-
*
|
|
8
|
-
* See: https://en.wikipedia.org/wiki/Natural_sort_order
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
function naturalCompare(aStr, bStr) {
|
|
13
|
-
let aIndex = 0;
|
|
14
|
-
let bIndex = 0;
|
|
15
|
-
while (aIndex < aStr.length && bIndex < bStr.length) {
|
|
16
|
-
let aChar = aStr.charCodeAt(aIndex);
|
|
17
|
-
let bChar = bStr.charCodeAt(bIndex);
|
|
18
|
-
if (isDigit(aChar) && isDigit(bChar)) {
|
|
19
|
-
let aNum = 0;
|
|
20
|
-
do {
|
|
21
|
-
++aIndex;
|
|
22
|
-
aNum = aNum * 10 + aChar - DIGIT_0;
|
|
23
|
-
aChar = aStr.charCodeAt(aIndex);
|
|
24
|
-
} while (isDigit(aChar) && aNum > 0);
|
|
25
|
-
let bNum = 0;
|
|
26
|
-
do {
|
|
27
|
-
++bIndex;
|
|
28
|
-
bNum = bNum * 10 + bChar - DIGIT_0;
|
|
29
|
-
bChar = bStr.charCodeAt(bIndex);
|
|
30
|
-
} while (isDigit(bChar) && bNum > 0);
|
|
31
|
-
if (aNum < bNum) {
|
|
32
|
-
return -1;
|
|
33
|
-
}
|
|
34
|
-
if (aNum > bNum) {
|
|
35
|
-
return 1;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
if (aChar < bChar) {
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
if (aChar > bChar) {
|
|
43
|
-
return 1;
|
|
44
|
-
}
|
|
45
|
-
++aIndex;
|
|
46
|
-
++bIndex;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return aStr.length - bStr.length;
|
|
50
|
-
}
|
|
51
|
-
const DIGIT_0 = 48;
|
|
52
|
-
const DIGIT_9 = 57;
|
|
53
|
-
function isDigit(code) {
|
|
54
|
-
return !isNaN(code) && DIGIT_0 <= code && code <= DIGIT_9;
|
|
55
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.suggestionList = suggestionList;
|
|
4
|
-
const naturalCompare_js_1 = require("./naturalCompare.js");
|
|
5
|
-
/**
|
|
6
|
-
* Given an invalid input string and a list of valid options, returns a filtered
|
|
7
|
-
* list of valid options sorted based on their similarity with the input.
|
|
8
|
-
*
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
function suggestionList(input, options) {
|
|
12
|
-
const optionsByDistance = Object.create(null);
|
|
13
|
-
const lexicalDistance = new LexicalDistance(input);
|
|
14
|
-
const threshold = Math.floor(input.length * 0.4) + 1;
|
|
15
|
-
for (const option of options) {
|
|
16
|
-
const distance = lexicalDistance.measure(option, threshold);
|
|
17
|
-
if (distance !== undefined) {
|
|
18
|
-
optionsByDistance[option] = distance;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return Object.keys(optionsByDistance).sort((a, b) => {
|
|
22
|
-
const distanceDiff = optionsByDistance[a] - optionsByDistance[b];
|
|
23
|
-
return distanceDiff !== 0 ? distanceDiff : (0, naturalCompare_js_1.naturalCompare)(a, b);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Computes the lexical distance between strings A and B.
|
|
28
|
-
*
|
|
29
|
-
* The "distance" between two strings is given by counting the minimum number
|
|
30
|
-
* of edits needed to transform string A into string B. An edit can be an
|
|
31
|
-
* insertion, deletion, or substitution of a single character, or a swap of two
|
|
32
|
-
* adjacent characters.
|
|
33
|
-
*
|
|
34
|
-
* Includes a custom alteration from Damerau-Levenshtein to treat case changes
|
|
35
|
-
* as a single edit which helps identify mis-cased values with an edit distance
|
|
36
|
-
* of 1.
|
|
37
|
-
*
|
|
38
|
-
* This distance can be useful for detecting typos in input or sorting
|
|
39
|
-
*
|
|
40
|
-
* @internal
|
|
41
|
-
*/
|
|
42
|
-
class LexicalDistance {
|
|
43
|
-
_input;
|
|
44
|
-
_inputLowerCase;
|
|
45
|
-
_inputArray;
|
|
46
|
-
_rows;
|
|
47
|
-
constructor(input) {
|
|
48
|
-
this._input = input;
|
|
49
|
-
this._inputLowerCase = input.toLowerCase();
|
|
50
|
-
this._inputArray = stringToArray(this._inputLowerCase);
|
|
51
|
-
this._rows = [
|
|
52
|
-
new Array(input.length + 1).fill(0),
|
|
53
|
-
new Array(input.length + 1).fill(0),
|
|
54
|
-
new Array(input.length + 1).fill(0),
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
measure(option, threshold) {
|
|
58
|
-
if (this._input === option) {
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
const optionLowerCase = option.toLowerCase();
|
|
62
|
-
// Any case change counts as a single edit
|
|
63
|
-
if (this._inputLowerCase === optionLowerCase) {
|
|
64
|
-
return 1;
|
|
65
|
-
}
|
|
66
|
-
let a = stringToArray(optionLowerCase);
|
|
67
|
-
let b = this._inputArray;
|
|
68
|
-
if (a.length < b.length) {
|
|
69
|
-
const tmp = a;
|
|
70
|
-
a = b;
|
|
71
|
-
b = tmp;
|
|
72
|
-
}
|
|
73
|
-
const aLength = a.length;
|
|
74
|
-
const bLength = b.length;
|
|
75
|
-
if (aLength - bLength > threshold) {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
const rows = this._rows;
|
|
79
|
-
for (let j = 0; j <= bLength; j++) {
|
|
80
|
-
rows[0][j] = j;
|
|
81
|
-
}
|
|
82
|
-
for (let i = 1; i <= aLength; i++) {
|
|
83
|
-
const upRow = rows[(i - 1) % 3];
|
|
84
|
-
const currentRow = rows[i % 3];
|
|
85
|
-
let smallestCell = (currentRow[0] = i);
|
|
86
|
-
for (let j = 1; j <= bLength; j++) {
|
|
87
|
-
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
88
|
-
let currentCell = Math.min(upRow[j] + 1, // delete
|
|
89
|
-
currentRow[j - 1] + 1, // insert
|
|
90
|
-
upRow[j - 1] + cost);
|
|
91
|
-
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
92
|
-
// transposition
|
|
93
|
-
const doubleDiagonalCell = rows[(i - 2) % 3][j - 2];
|
|
94
|
-
currentCell = Math.min(currentCell, doubleDiagonalCell + 1);
|
|
95
|
-
}
|
|
96
|
-
if (currentCell < smallestCell) {
|
|
97
|
-
smallestCell = currentCell;
|
|
98
|
-
}
|
|
99
|
-
currentRow[j] = currentCell;
|
|
100
|
-
}
|
|
101
|
-
// Early exit, since distance can't go smaller than smallest element of the previous row.
|
|
102
|
-
if (smallestCell > threshold) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const distance = rows[aLength % 3][bLength];
|
|
107
|
-
return distance <= threshold ? distance : undefined;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function stringToArray(str) {
|
|
111
|
-
const strLength = str.length;
|
|
112
|
-
const array = new Array(strLength);
|
|
113
|
-
for (let i = 0; i < strLength; ++i) {
|
|
114
|
-
array[i] = str.charCodeAt(i);
|
|
115
|
-
}
|
|
116
|
-
return array;
|
|
117
|
-
}
|