@graphql-tools/utils 8.7.0 → 8.8.0-alpha-b76ec274.0
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/AggregateError.js +25 -0
- package/cjs/Interfaces.js +31 -0
- package/cjs/addTypes.js +62 -0
- package/cjs/astFromType.js +31 -0
- package/cjs/astFromValueUntyped.js +78 -0
- package/cjs/build-operation-for-field.js +351 -0
- package/cjs/collectFields.js +98 -0
- package/cjs/comments.js +380 -0
- package/cjs/errors.js +22 -0
- package/cjs/executor.js +2 -0
- package/cjs/fields.js +115 -0
- package/cjs/filterSchema.js +66 -0
- package/cjs/fixSchemaAst.js +26 -0
- package/cjs/forEachDefaultValue.js +29 -0
- package/cjs/forEachField.js +19 -0
- package/cjs/get-directives.js +103 -0
- package/cjs/get-fields-with-directives.js +52 -0
- package/cjs/get-implementing-types.js +19 -0
- package/cjs/getArgumentValues.js +76 -0
- package/cjs/getObjectTypeFromTypeMap.js +13 -0
- package/cjs/getOperationASTFromRequest.js +16 -0
- package/cjs/getResolversFromSchema.js +73 -0
- package/cjs/getResponseKeyFromInfo.js +12 -0
- package/cjs/heal.js +177 -0
- package/cjs/helpers.js +76 -0
- package/cjs/implementsAbstractType.js +17 -0
- package/cjs/index.js +53 -0
- package/cjs/inspect.js +107 -0
- package/cjs/isAsyncIterable.js +10 -0
- package/cjs/isDocumentNode.js +8 -0
- package/cjs/loaders.js +2 -0
- package/cjs/mapAsyncIterator.js +53 -0
- package/cjs/mapSchema.js +470 -0
- package/cjs/memoize.js +189 -0
- package/cjs/mergeDeep.js +45 -0
- package/cjs/observableToAsyncIterable.js +85 -0
- package/cjs/package.json +1 -0
- package/cjs/parse-graphql-json.js +44 -0
- package/cjs/parse-graphql-sdl.js +84 -0
- package/cjs/print-schema-with-directives.js +494 -0
- package/cjs/prune.js +133 -0
- package/cjs/renameType.js +152 -0
- package/cjs/rewire.js +159 -0
- package/cjs/rootTypes.js +37 -0
- package/cjs/selectionSets.js +9 -0
- package/cjs/stub.js +68 -0
- package/cjs/transformInputValue.js +55 -0
- package/cjs/types.js +27 -0
- package/cjs/updateArgument.js +54 -0
- package/cjs/validate-documents.js +76 -0
- package/cjs/valueMatchesCriteria.js +21 -0
- package/cjs/visitResult.js +219 -0
- package/cjs/withCancel.js +56 -0
- package/esm/AggregateError.js +21 -0
- package/esm/Interfaces.js +28 -0
- package/esm/addTypes.js +58 -0
- package/esm/astFromType.js +27 -0
- package/esm/astFromValueUntyped.js +74 -0
- package/esm/build-operation-for-field.js +347 -0
- package/esm/collectFields.js +94 -0
- package/esm/comments.js +367 -0
- package/esm/errors.js +17 -0
- package/esm/executor.js +1 -0
- package/esm/fields.js +108 -0
- package/esm/filterSchema.js +62 -0
- package/esm/fixSchemaAst.js +22 -0
- package/esm/forEachDefaultValue.js +25 -0
- package/esm/forEachField.js +15 -0
- package/esm/get-directives.js +96 -0
- package/esm/get-fields-with-directives.js +48 -0
- package/esm/get-implementing-types.js +15 -0
- package/esm/getArgumentValues.js +72 -0
- package/esm/getObjectTypeFromTypeMap.js +9 -0
- package/esm/getOperationASTFromRequest.js +12 -0
- package/esm/getResolversFromSchema.js +69 -0
- package/esm/getResponseKeyFromInfo.js +8 -0
- package/esm/heal.js +172 -0
- package/esm/helpers.js +65 -0
- package/esm/implementsAbstractType.js +13 -0
- package/esm/index.js +50 -0
- package/esm/inspect.js +103 -0
- package/esm/isAsyncIterable.js +6 -0
- package/esm/isDocumentNode.js +4 -0
- package/esm/loaders.js +1 -0
- package/esm/mapAsyncIterator.js +49 -0
- package/esm/mapSchema.js +465 -0
- package/esm/memoize.js +180 -0
- package/esm/mergeDeep.js +41 -0
- package/esm/observableToAsyncIterable.js +81 -0
- package/esm/parse-graphql-json.js +40 -0
- package/esm/parse-graphql-sdl.js +78 -0
- package/esm/print-schema-with-directives.js +472 -0
- package/esm/prune.js +129 -0
- package/esm/renameType.js +148 -0
- package/esm/rewire.js +155 -0
- package/esm/rootTypes.js +33 -0
- package/esm/selectionSets.js +5 -0
- package/esm/stub.js +61 -0
- package/esm/transformInputValue.js +48 -0
- package/esm/types.js +24 -0
- package/esm/updateArgument.js +49 -0
- package/esm/validate-documents.js +70 -0
- package/esm/valueMatchesCriteria.js +17 -0
- package/esm/visitResult.js +213 -0
- package/esm/withCancel.js +51 -0
- package/package.json +31 -10
- package/{AggregateError.d.ts → typings/AggregateError.d.ts} +0 -0
- package/{Interfaces.d.ts → typings/Interfaces.d.ts} +0 -0
- package/{addTypes.d.ts → typings/addTypes.d.ts} +0 -0
- package/{astFromType.d.ts → typings/astFromType.d.ts} +0 -0
- package/{astFromValueUntyped.d.ts → typings/astFromValueUntyped.d.ts} +0 -0
- package/{build-operation-for-field.d.ts → typings/build-operation-for-field.d.ts} +0 -0
- package/{collectFields.d.ts → typings/collectFields.d.ts} +0 -0
- package/{comments.d.ts → typings/comments.d.ts} +0 -0
- package/{errors.d.ts → typings/errors.d.ts} +1 -1
- package/{executor.d.ts → typings/executor.d.ts} +1 -1
- package/{fields.d.ts → typings/fields.d.ts} +0 -0
- package/{filterSchema.d.ts → typings/filterSchema.d.ts} +1 -1
- package/{fixSchemaAst.d.ts → typings/fixSchemaAst.d.ts} +1 -1
- package/{forEachDefaultValue.d.ts → typings/forEachDefaultValue.d.ts} +1 -1
- package/{forEachField.d.ts → typings/forEachField.d.ts} +1 -1
- package/{get-directives.d.ts → typings/get-directives.d.ts} +0 -0
- package/{get-fields-with-directives.d.ts → typings/get-fields-with-directives.d.ts} +0 -0
- package/{get-implementing-types.d.ts → typings/get-implementing-types.d.ts} +0 -0
- package/{getArgumentValues.d.ts → typings/getArgumentValues.d.ts} +0 -0
- package/{getObjectTypeFromTypeMap.d.ts → typings/getObjectTypeFromTypeMap.d.ts} +1 -1
- package/{getOperationASTFromRequest.d.ts → typings/getOperationASTFromRequest.d.ts} +1 -1
- package/{getResolversFromSchema.d.ts → typings/getResolversFromSchema.d.ts} +1 -1
- package/{getResponseKeyFromInfo.d.ts → typings/getResponseKeyFromInfo.d.ts} +0 -0
- package/{heal.d.ts → typings/heal.d.ts} +0 -0
- package/{helpers.d.ts → typings/helpers.d.ts} +0 -0
- package/{implementsAbstractType.d.ts → typings/implementsAbstractType.d.ts} +1 -1
- package/typings/index.d.ts +50 -0
- package/{inspect.d.ts → typings/inspect.d.ts} +0 -0
- package/{isAsyncIterable.d.ts → typings/isAsyncIterable.d.ts} +0 -0
- package/{isDocumentNode.d.ts → typings/isDocumentNode.d.ts} +0 -0
- package/{loaders.d.ts → typings/loaders.d.ts} +1 -1
- package/{mapAsyncIterator.d.ts → typings/mapAsyncIterator.d.ts} +0 -0
- package/{mapSchema.d.ts → typings/mapSchema.d.ts} +1 -1
- package/{memoize.d.ts → typings/memoize.d.ts} +0 -0
- package/{mergeDeep.d.ts → typings/mergeDeep.d.ts} +0 -0
- package/{observableToAsyncIterable.d.ts → typings/observableToAsyncIterable.d.ts} +0 -0
- package/{parse-graphql-json.d.ts → typings/parse-graphql-json.d.ts} +2 -2
- package/{parse-graphql-sdl.d.ts → typings/parse-graphql-sdl.d.ts} +1 -1
- package/{print-schema-with-directives.d.ts → typings/print-schema-with-directives.d.ts} +1 -1
- package/{prune.d.ts → typings/prune.d.ts} +1 -1
- package/{renameType.d.ts → typings/renameType.d.ts} +0 -0
- package/{rewire.d.ts → typings/rewire.d.ts} +0 -0
- package/{rootTypes.d.ts → typings/rootTypes.d.ts} +0 -0
- package/{selectionSets.d.ts → typings/selectionSets.d.ts} +1 -1
- package/{stub.d.ts → typings/stub.d.ts} +0 -0
- package/{transformInputValue.d.ts → typings/transformInputValue.d.ts} +1 -1
- package/{types.d.ts → typings/types.d.ts} +0 -0
- package/{updateArgument.d.ts → typings/updateArgument.d.ts} +0 -0
- package/{validate-documents.d.ts → typings/validate-documents.d.ts} +1 -1
- package/{valueMatchesCriteria.d.ts → typings/valueMatchesCriteria.d.ts} +0 -0
- package/{visitResult.d.ts → typings/visitResult.d.ts} +1 -1
- package/{withCancel.d.ts → typings/withCancel.d.ts} +0 -0
- package/index.d.ts +0 -50
- package/index.js +0 -4428
- package/index.mjs +0 -4315
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { getOperationASTFromRequest } from './getOperationASTFromRequest.js';
|
|
2
|
+
import { Kind, isListType, getNullableType, isAbstractType, isObjectType, TypeNameMetaFieldDef, } from 'graphql';
|
|
3
|
+
import { collectFields, collectSubFields } from './collectFields.js';
|
|
4
|
+
export function visitData(data, enter, leave) {
|
|
5
|
+
if (Array.isArray(data)) {
|
|
6
|
+
return data.map(value => visitData(value, enter, leave));
|
|
7
|
+
}
|
|
8
|
+
else if (typeof data === 'object') {
|
|
9
|
+
const newData = enter != null ? enter(data) : data;
|
|
10
|
+
if (newData != null) {
|
|
11
|
+
for (const key in newData) {
|
|
12
|
+
const value = newData[key];
|
|
13
|
+
Object.defineProperty(newData, key, {
|
|
14
|
+
value: visitData(value, enter, leave),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return leave != null ? leave(newData) : newData;
|
|
19
|
+
}
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
export function visitErrors(errors, visitor) {
|
|
23
|
+
return errors.map(error => visitor(error));
|
|
24
|
+
}
|
|
25
|
+
export function visitResult(result, request, schema, resultVisitorMap, errorVisitorMap) {
|
|
26
|
+
const fragments = request.document.definitions.reduce((acc, def) => {
|
|
27
|
+
if (def.kind === Kind.FRAGMENT_DEFINITION) {
|
|
28
|
+
acc[def.name.value] = def;
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
const variableValues = request.variables || {};
|
|
33
|
+
const errorInfo = {
|
|
34
|
+
segmentInfoMap: new Map(),
|
|
35
|
+
unpathedErrors: new Set(),
|
|
36
|
+
};
|
|
37
|
+
const data = result.data;
|
|
38
|
+
const errors = result.errors;
|
|
39
|
+
const visitingErrors = errors != null && errorVisitorMap != null;
|
|
40
|
+
const operationDocumentNode = getOperationASTFromRequest(request);
|
|
41
|
+
if (data != null && operationDocumentNode != null) {
|
|
42
|
+
result.data = visitRoot(data, operationDocumentNode, schema, fragments, variableValues, resultVisitorMap, visitingErrors ? errors : undefined, errorInfo);
|
|
43
|
+
}
|
|
44
|
+
if (errors != null && errorVisitorMap) {
|
|
45
|
+
result.errors = visitErrorsByType(errors, errorVisitorMap, errorInfo);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function visitErrorsByType(errors, errorVisitorMap, errorInfo) {
|
|
50
|
+
const segmentInfoMap = errorInfo.segmentInfoMap;
|
|
51
|
+
const unpathedErrors = errorInfo.unpathedErrors;
|
|
52
|
+
const unpathedErrorVisitor = errorVisitorMap['__unpathed'];
|
|
53
|
+
return errors.map(originalError => {
|
|
54
|
+
const pathSegmentsInfo = segmentInfoMap.get(originalError);
|
|
55
|
+
const newError = pathSegmentsInfo == null
|
|
56
|
+
? originalError
|
|
57
|
+
: pathSegmentsInfo.reduceRight((acc, segmentInfo) => {
|
|
58
|
+
const typeName = segmentInfo.type.name;
|
|
59
|
+
const typeVisitorMap = errorVisitorMap[typeName];
|
|
60
|
+
if (typeVisitorMap == null) {
|
|
61
|
+
return acc;
|
|
62
|
+
}
|
|
63
|
+
const errorVisitor = typeVisitorMap[segmentInfo.fieldName];
|
|
64
|
+
return errorVisitor == null ? acc : errorVisitor(acc, segmentInfo.pathIndex);
|
|
65
|
+
}, originalError);
|
|
66
|
+
if (unpathedErrorVisitor && unpathedErrors.has(originalError)) {
|
|
67
|
+
return unpathedErrorVisitor(newError);
|
|
68
|
+
}
|
|
69
|
+
return newError;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function getOperationRootType(schema, operationDef) {
|
|
73
|
+
switch (operationDef.operation) {
|
|
74
|
+
case 'query':
|
|
75
|
+
return schema.getQueryType();
|
|
76
|
+
case 'mutation':
|
|
77
|
+
return schema.getMutationType();
|
|
78
|
+
case 'subscription':
|
|
79
|
+
return schema.getSubscriptionType();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function visitRoot(root, operation, schema, fragments, variableValues, resultVisitorMap, errors, errorInfo) {
|
|
83
|
+
const operationRootType = getOperationRootType(schema, operation);
|
|
84
|
+
const collectedFields = collectFields(schema, fragments, variableValues, operationRootType, operation.selectionSet, new Map(), new Set());
|
|
85
|
+
return visitObjectValue(root, operationRootType, collectedFields, schema, fragments, variableValues, resultVisitorMap, 0, errors, errorInfo);
|
|
86
|
+
}
|
|
87
|
+
function visitObjectValue(object, type, fieldNodeMap, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo) {
|
|
88
|
+
var _a;
|
|
89
|
+
const fieldMap = type.getFields();
|
|
90
|
+
const typeVisitorMap = resultVisitorMap === null || resultVisitorMap === void 0 ? void 0 : resultVisitorMap[type.name];
|
|
91
|
+
const enterObject = typeVisitorMap === null || typeVisitorMap === void 0 ? void 0 : typeVisitorMap.__enter;
|
|
92
|
+
const newObject = enterObject != null ? enterObject(object) : object;
|
|
93
|
+
let sortedErrors;
|
|
94
|
+
let errorMap = null;
|
|
95
|
+
if (errors != null) {
|
|
96
|
+
sortedErrors = sortErrorsByPathSegment(errors, pathIndex);
|
|
97
|
+
errorMap = sortedErrors.errorMap;
|
|
98
|
+
for (const error of sortedErrors.unpathedErrors) {
|
|
99
|
+
errorInfo.unpathedErrors.add(error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const [responseKey, subFieldNodes] of fieldNodeMap) {
|
|
103
|
+
const fieldName = subFieldNodes[0].name.value;
|
|
104
|
+
const fieldType = fieldName === '__typename' ? TypeNameMetaFieldDef.type : (_a = fieldMap[fieldName]) === null || _a === void 0 ? void 0 : _a.type;
|
|
105
|
+
const newPathIndex = pathIndex + 1;
|
|
106
|
+
let fieldErrors;
|
|
107
|
+
if (errorMap) {
|
|
108
|
+
fieldErrors = errorMap[responseKey];
|
|
109
|
+
if (fieldErrors != null) {
|
|
110
|
+
delete errorMap[responseKey];
|
|
111
|
+
}
|
|
112
|
+
addPathSegmentInfo(type, fieldName, newPathIndex, fieldErrors, errorInfo);
|
|
113
|
+
}
|
|
114
|
+
const newValue = visitFieldValue(object[responseKey], fieldType, subFieldNodes, schema, fragments, variableValues, resultVisitorMap, newPathIndex, fieldErrors, errorInfo);
|
|
115
|
+
updateObject(newObject, responseKey, newValue, typeVisitorMap, fieldName);
|
|
116
|
+
}
|
|
117
|
+
const oldTypename = newObject.__typename;
|
|
118
|
+
if (oldTypename != null) {
|
|
119
|
+
updateObject(newObject, '__typename', oldTypename, typeVisitorMap, '__typename');
|
|
120
|
+
}
|
|
121
|
+
if (errorMap) {
|
|
122
|
+
for (const errorsKey in errorMap) {
|
|
123
|
+
const errors = errorMap[errorsKey];
|
|
124
|
+
for (const error of errors) {
|
|
125
|
+
errorInfo.unpathedErrors.add(error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const leaveObject = typeVisitorMap === null || typeVisitorMap === void 0 ? void 0 : typeVisitorMap.__leave;
|
|
130
|
+
return leaveObject != null ? leaveObject(newObject) : newObject;
|
|
131
|
+
}
|
|
132
|
+
function updateObject(object, responseKey, newValue, typeVisitorMap, fieldName) {
|
|
133
|
+
if (typeVisitorMap == null) {
|
|
134
|
+
object[responseKey] = newValue;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const fieldVisitor = typeVisitorMap[fieldName];
|
|
138
|
+
if (fieldVisitor == null) {
|
|
139
|
+
object[responseKey] = newValue;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const visitedValue = fieldVisitor(newValue);
|
|
143
|
+
if (visitedValue === undefined) {
|
|
144
|
+
delete object[responseKey];
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
object[responseKey] = visitedValue;
|
|
148
|
+
}
|
|
149
|
+
function visitListValue(list, returnType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo) {
|
|
150
|
+
return list.map(listMember => visitFieldValue(listMember, returnType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex + 1, errors, errorInfo));
|
|
151
|
+
}
|
|
152
|
+
function visitFieldValue(value, returnType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors = [], errorInfo) {
|
|
153
|
+
if (value == null) {
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
const nullableType = getNullableType(returnType);
|
|
157
|
+
if (isListType(nullableType)) {
|
|
158
|
+
return visitListValue(value, nullableType.ofType, fieldNodes, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo);
|
|
159
|
+
}
|
|
160
|
+
else if (isAbstractType(nullableType)) {
|
|
161
|
+
const finalType = schema.getType(value.__typename);
|
|
162
|
+
const collectedFields = collectSubFields(schema, fragments, variableValues, finalType, fieldNodes);
|
|
163
|
+
return visitObjectValue(value, finalType, collectedFields, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo);
|
|
164
|
+
}
|
|
165
|
+
else if (isObjectType(nullableType)) {
|
|
166
|
+
const collectedFields = collectSubFields(schema, fragments, variableValues, nullableType, fieldNodes);
|
|
167
|
+
return visitObjectValue(value, nullableType, collectedFields, schema, fragments, variableValues, resultVisitorMap, pathIndex, errors, errorInfo);
|
|
168
|
+
}
|
|
169
|
+
const typeVisitorMap = resultVisitorMap === null || resultVisitorMap === void 0 ? void 0 : resultVisitorMap[nullableType.name];
|
|
170
|
+
if (typeVisitorMap == null) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
const visitedValue = typeVisitorMap(value);
|
|
174
|
+
return visitedValue === undefined ? value : visitedValue;
|
|
175
|
+
}
|
|
176
|
+
function sortErrorsByPathSegment(errors, pathIndex) {
|
|
177
|
+
var _a;
|
|
178
|
+
const errorMap = Object.create(null);
|
|
179
|
+
const unpathedErrors = new Set();
|
|
180
|
+
for (const error of errors) {
|
|
181
|
+
const pathSegment = (_a = error.path) === null || _a === void 0 ? void 0 : _a[pathIndex];
|
|
182
|
+
if (pathSegment == null) {
|
|
183
|
+
unpathedErrors.add(error);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (pathSegment in errorMap) {
|
|
187
|
+
errorMap[pathSegment].push(error);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
errorMap[pathSegment] = [error];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
errorMap,
|
|
195
|
+
unpathedErrors,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function addPathSegmentInfo(type, fieldName, pathIndex, errors = [], errorInfo) {
|
|
199
|
+
for (const error of errors) {
|
|
200
|
+
const segmentInfo = {
|
|
201
|
+
type,
|
|
202
|
+
fieldName,
|
|
203
|
+
pathIndex,
|
|
204
|
+
};
|
|
205
|
+
const pathSegmentsInfo = errorInfo.segmentInfoMap.get(error);
|
|
206
|
+
if (pathSegmentsInfo == null) {
|
|
207
|
+
errorInfo.segmentInfoMap.set(error, [segmentInfo]);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
pathSegmentsInfo.push(segmentInfo);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { memoize2 } from './memoize.js';
|
|
2
|
+
async function defaultAsyncIteratorReturn(value) {
|
|
3
|
+
return { value, done: true };
|
|
4
|
+
}
|
|
5
|
+
const proxyMethodFactory = memoize2(function proxyMethodFactory(target, targetMethod) {
|
|
6
|
+
return function proxyMethod(...args) {
|
|
7
|
+
return Reflect.apply(targetMethod, target, args);
|
|
8
|
+
};
|
|
9
|
+
});
|
|
10
|
+
export function getAsyncIteratorWithCancel(asyncIterator, onCancel) {
|
|
11
|
+
return new Proxy(asyncIterator, {
|
|
12
|
+
has(asyncIterator, prop) {
|
|
13
|
+
if (prop === 'return') {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return Reflect.has(asyncIterator, prop);
|
|
17
|
+
},
|
|
18
|
+
get(asyncIterator, prop, receiver) {
|
|
19
|
+
const existingPropValue = Reflect.get(asyncIterator, prop, receiver);
|
|
20
|
+
if (prop === 'return') {
|
|
21
|
+
const existingReturn = existingPropValue || defaultAsyncIteratorReturn;
|
|
22
|
+
return async function returnWithCancel(value) {
|
|
23
|
+
const returnValue = await onCancel(value);
|
|
24
|
+
return Reflect.apply(existingReturn, asyncIterator, [returnValue]);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else if (typeof existingPropValue === 'function') {
|
|
28
|
+
return proxyMethodFactory(asyncIterator, existingPropValue);
|
|
29
|
+
}
|
|
30
|
+
return existingPropValue;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function getAsyncIterableWithCancel(asyncIterable, onCancel) {
|
|
35
|
+
return new Proxy(asyncIterable, {
|
|
36
|
+
get(asyncIterable, prop, receiver) {
|
|
37
|
+
const existingPropValue = Reflect.get(asyncIterable, prop, receiver);
|
|
38
|
+
if (Symbol.asyncIterator === prop) {
|
|
39
|
+
return function asyncIteratorFactory() {
|
|
40
|
+
const asyncIterator = Reflect.apply(existingPropValue, asyncIterable, []);
|
|
41
|
+
return getAsyncIteratorWithCancel(asyncIterator, onCancel);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else if (typeof existingPropValue === 'function') {
|
|
45
|
+
return proxyMethodFactory(asyncIterable, existingPropValue);
|
|
46
|
+
}
|
|
47
|
+
return existingPropValue;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export { getAsyncIterableWithCancel as withCancel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.0-alpha-b76ec274.0",
|
|
4
4
|
"description": "Common package containing utils and types for GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -16,21 +16,42 @@
|
|
|
16
16
|
},
|
|
17
17
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"module": "index.
|
|
21
|
-
"typings": "index.d.ts",
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"typings": "typings/index.d.ts",
|
|
22
22
|
"typescript": {
|
|
23
|
-
"definition": "index.d.ts"
|
|
23
|
+
"definition": "typings/index.d.ts"
|
|
24
24
|
},
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
|
-
"require":
|
|
28
|
-
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./typings/index.d.ts",
|
|
30
|
+
"default": "./cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
}
|
|
29
40
|
},
|
|
30
41
|
"./*": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./typings/*.d.ts",
|
|
44
|
+
"default": "./cjs/*.js"
|
|
45
|
+
},
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./typings/*.d.ts",
|
|
48
|
+
"default": "./esm/*.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"types": "./typings/*.d.ts",
|
|
52
|
+
"default": "./esm/*.js"
|
|
53
|
+
}
|
|
33
54
|
},
|
|
34
55
|
"./package.json": "./package.json"
|
|
35
56
|
}
|
|
36
|
-
}
|
|
57
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExecutionResult, ExecutionRequest } from './Interfaces';
|
|
1
|
+
import { ExecutionResult, ExecutionRequest } from './Interfaces.js';
|
|
2
2
|
declare type MaybePromise<T> = Promise<T> | T;
|
|
3
3
|
declare type MaybeAsyncIterable<T> = AsyncIterable<T> | T;
|
|
4
4
|
export declare type AsyncExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs extends Record<string, any> = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions>) => Promise<MaybeAsyncIterable<ExecutionResult<TReturn>>>;
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { FieldFilter, RootFieldFilter, TypeFilter, ArgumentFilter } from './Interfaces';
|
|
2
|
+
import { FieldFilter, RootFieldFilter, TypeFilter, ArgumentFilter } from './Interfaces.js';
|
|
3
3
|
export declare function filterSchema({ schema, typeFilter, fieldFilter, rootFieldFilter, objectFieldFilter, interfaceFieldFilter, inputObjectFieldFilter, argumentFilter, }: {
|
|
4
4
|
schema: GraphQLSchema;
|
|
5
5
|
rootFieldFilter?: RootFieldFilter;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLSchema, BuildSchemaOptions } from 'graphql';
|
|
2
|
-
import { SchemaPrintOptions } from './types';
|
|
2
|
+
import { SchemaPrintOptions } from './types.js';
|
|
3
3
|
export declare function fixSchemaAst(schema: GraphQLSchema, options: BuildSchemaOptions & SchemaPrintOptions): GraphQLSchema;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLNamedType, GraphQLObjectType } from 'graphql';
|
|
2
|
-
import { Maybe } from './types';
|
|
2
|
+
import { Maybe } from './types.js';
|
|
3
3
|
export declare function getObjectTypeFromTypeMap(typeMap: Record<string, GraphQLNamedType>, type: Maybe<GraphQLObjectType>): GraphQLObjectType | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DocumentNode, OperationDefinitionNode } from 'graphql';
|
|
2
|
-
import { ExecutionRequest } from './Interfaces';
|
|
2
|
+
import { ExecutionRequest } from './Interfaces.js';
|
|
3
3
|
export declare function getOperationASTFromDocument(documentNode: DocumentNode, operationName?: string): OperationDefinitionNode;
|
|
4
4
|
export declare const getOperationASTFromRequest: (request: ExecutionRequest) => OperationDefinitionNode;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export * from './loaders.js';
|
|
2
|
+
export * from './helpers.js';
|
|
3
|
+
export * from './get-directives.js';
|
|
4
|
+
export * from './get-fields-with-directives.js';
|
|
5
|
+
export * from './get-implementing-types.js';
|
|
6
|
+
export * from './print-schema-with-directives.js';
|
|
7
|
+
export * from './get-fields-with-directives.js';
|
|
8
|
+
export * from './validate-documents.js';
|
|
9
|
+
export * from './parse-graphql-json.js';
|
|
10
|
+
export * from './parse-graphql-sdl.js';
|
|
11
|
+
export * from './build-operation-for-field.js';
|
|
12
|
+
export * from './types.js';
|
|
13
|
+
export * from './filterSchema.js';
|
|
14
|
+
export * from './heal.js';
|
|
15
|
+
export * from './getResolversFromSchema.js';
|
|
16
|
+
export * from './forEachField.js';
|
|
17
|
+
export * from './forEachDefaultValue.js';
|
|
18
|
+
export * from './mapSchema.js';
|
|
19
|
+
export * from './addTypes.js';
|
|
20
|
+
export * from './rewire.js';
|
|
21
|
+
export * from './prune.js';
|
|
22
|
+
export * from './mergeDeep.js';
|
|
23
|
+
export * from './Interfaces.js';
|
|
24
|
+
export * from './stub.js';
|
|
25
|
+
export * from './selectionSets.js';
|
|
26
|
+
export * from './getResponseKeyFromInfo.js';
|
|
27
|
+
export * from './fields.js';
|
|
28
|
+
export * from './renameType.js';
|
|
29
|
+
export * from './transformInputValue.js';
|
|
30
|
+
export * from './mapAsyncIterator.js';
|
|
31
|
+
export * from './updateArgument.js';
|
|
32
|
+
export * from './implementsAbstractType.js';
|
|
33
|
+
export * from './errors.js';
|
|
34
|
+
export * from './observableToAsyncIterable.js';
|
|
35
|
+
export * from './visitResult.js';
|
|
36
|
+
export * from './getArgumentValues.js';
|
|
37
|
+
export * from './valueMatchesCriteria.js';
|
|
38
|
+
export * from './isAsyncIterable.js';
|
|
39
|
+
export * from './isDocumentNode.js';
|
|
40
|
+
export * from './astFromValueUntyped.js';
|
|
41
|
+
export * from './executor.js';
|
|
42
|
+
export * from './withCancel.js';
|
|
43
|
+
export * from './AggregateError.js';
|
|
44
|
+
export * from './rootTypes.js';
|
|
45
|
+
export * from './comments.js';
|
|
46
|
+
export * from './collectFields.js';
|
|
47
|
+
export * from './inspect.js';
|
|
48
|
+
export * from './memoize.js';
|
|
49
|
+
export * from './fixSchemaAst.js';
|
|
50
|
+
export * from './getOperationASTFromRequest.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLObjectType, GraphQLSchema, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLEnumType } from 'graphql';
|
|
2
|
-
import { SchemaMapper } from './Interfaces';
|
|
2
|
+
import { SchemaMapper } from './Interfaces.js';
|
|
3
3
|
export declare function mapSchema(schema: GraphQLSchema, schemaMapper?: SchemaMapper): GraphQLSchema;
|
|
4
4
|
export declare function correctASTNodes(type: GraphQLObjectType): GraphQLObjectType;
|
|
5
5
|
export declare function correctASTNodes(type: GraphQLInterfaceType): GraphQLInterfaceType;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ParseOptions } from 'graphql';
|
|
2
|
-
import { Source } from './loaders';
|
|
3
|
-
import { SchemaPrintOptions } from './types';
|
|
2
|
+
import { Source } from './loaders.js';
|
|
3
|
+
import { SchemaPrintOptions } from './types.js';
|
|
4
4
|
export declare function parseGraphQLJSON(location: string, jsonContent: string, options: SchemaPrintOptions & ParseOptions): Source;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocumentNode, ASTNode, StringValueNode } from 'graphql';
|
|
2
|
-
import { GraphQLParseOptions } from './Interfaces';
|
|
2
|
+
import { GraphQLParseOptions } from './Interfaces.js';
|
|
3
3
|
export declare function parseGraphQLSDL(location: string | undefined, rawSDL: string, options?: GraphQLParseOptions): {
|
|
4
4
|
location: string | undefined;
|
|
5
5
|
document: DocumentNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema, GraphQLNamedType, DirectiveNode, FieldDefinitionNode, InputValueDefinitionNode, GraphQLArgument, EnumValueDefinitionNode, GraphQLDirective, DirectiveDefinitionNode, SchemaDefinitionNode, SchemaExtensionNode, GraphQLObjectType, ObjectTypeDefinitionNode, GraphQLField, GraphQLInterfaceType, InterfaceTypeDefinitionNode, UnionTypeDefinitionNode, GraphQLUnionType, GraphQLInputObjectType, InputObjectTypeDefinitionNode, GraphQLInputField, GraphQLEnumType, GraphQLEnumValue, EnumTypeDefinitionNode, GraphQLScalarType, ScalarTypeDefinitionNode, DocumentNode } from 'graphql';
|
|
2
|
-
import { GetDocumentNodeFromSchemaOptions, PrintSchemaWithDirectivesOptions, Maybe } from './types';
|
|
2
|
+
import { GetDocumentNodeFromSchemaOptions, PrintSchemaWithDirectivesOptions, Maybe } from './types.js';
|
|
3
3
|
export declare function getDocumentNodeFromSchema(schema: GraphQLSchema, options?: GetDocumentNodeFromSchemaOptions): DocumentNode;
|
|
4
4
|
export declare function printSchemaWithDirectives(schema: GraphQLSchema, options?: PrintSchemaWithDirectivesOptions): string;
|
|
5
5
|
export declare function astFromSchema(schema: GraphQLSchema, pathToDirectivesInExtensions?: Array<string>): SchemaDefinitionNode | SchemaExtensionNode | null;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLInputType } from 'graphql';
|
|
2
|
-
import { InputLeafValueTransformer, InputObjectValueTransformer, Maybe } from './types';
|
|
2
|
+
import { InputLeafValueTransformer, InputObjectValueTransformer, Maybe } from './types.js';
|
|
3
3
|
export declare function transformInputValue(type: GraphQLInputType, value: any, inputLeafValueTransformer?: Maybe<InputLeafValueTransformer>, inputObjectValueTransformer?: Maybe<InputObjectValueTransformer>): any;
|
|
4
4
|
export declare function serializeInputValue(type: GraphQLInputType, value: any): any;
|
|
5
5
|
export declare function parseInputValue(type: GraphQLInputType, value: any): any;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema, GraphQLError, ValidationContext, ASTVisitor } from 'graphql';
|
|
2
|
-
import { Source } from './loaders';
|
|
2
|
+
import { Source } from './loaders.js';
|
|
3
3
|
export declare type ValidationRule = (context: ValidationContext) => ASTVisitor;
|
|
4
4
|
export interface LoadDocumentError {
|
|
5
5
|
readonly filePath?: string;
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema, GraphQLError } from 'graphql';
|
|
2
|
-
import { ExecutionRequest, ExecutionResult } from './Interfaces';
|
|
2
|
+
import { ExecutionRequest, ExecutionResult } from './Interfaces.js';
|
|
3
3
|
export declare type ValueVisitor = (value: any) => any;
|
|
4
4
|
export declare type ObjectValueVisitor = {
|
|
5
5
|
__enter?: ValueVisitor;
|
|
File without changes
|