1 | import { parse, isNonNullType, GraphQLError, Kind, valueFromAST, print, isObjectType, isScalarType, isSpecifiedScalarType, isIntrospectionType, printType, specifiedRules, validate, buildSchema, Source, TokenKind, visit, isTypeSystemDefinitionNode, buildClientSchema, isListType, getNamedType, isEnumType, isUnionType, isInterfaceType, GraphQLString, GraphQLNonNull, GraphQLList, isInputObjectType, GraphQLID, GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLObjectType, GraphQLInterfaceType, GraphQLInputObjectType, isSpecifiedDirective, GraphQLDirective, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, isNamedType, getNullableType, isLeafType, GraphQLSchema, isSchema, isInputType, valueFromASTUntyped, isDirective, getDirectiveValues as getDirectiveValues$1, GraphQLSkipDirective, GraphQLIncludeDirective, typeFromAST, isAbstractType, isCompositeType, doTypesOverlap, getOperationAST, getOperationRootType } from 'graphql';
|
2 | import { __spread, __read, __assign, __values, __awaiter, __generator, __extends } from 'tslib';
|
3 | import AggregateError from '@ardatan/aggregate-error';
|
4 | import { camelCase } from 'camel-case';
|
5 |
|
6 | var asArray = function (fns) { return (Array.isArray(fns) ? fns : fns ? [fns] : []); };
|
7 | function isEqual(a, b) {
|
8 | if (Array.isArray(a) && Array.isArray(b)) {
|
9 | if (a.length !== b.length) {
|
10 | return false;
|
11 | }
|
12 | for (var index = 0; index < a.length; index++) {
|
13 | if (a[index] !== b[index]) {
|
14 | return false;
|
15 | }
|
16 | }
|
17 | return true;
|
18 | }
|
19 | return a === b || (!a && !b);
|
20 | }
|
21 | function isNotEqual(a, b) {
|
22 | return !isEqual(a, b);
|
23 | }
|
24 | function isDocumentString(str) {
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | if (/\.[a-z0-9]+$/i.test(str)) {
|
31 | return false;
|
32 | }
|
33 | try {
|
34 | parse(str);
|
35 | return true;
|
36 | }
|
37 | catch (e) { }
|
38 | return false;
|
39 | }
|
40 | var invalidPathRegex = /[‘“!$%&^<=>`]/;
|
41 | function isValidPath(str) {
|
42 | return typeof str === 'string' && !invalidPathRegex.test(str);
|
43 | }
|
44 | function compareStrings(a, b) {
|
45 | if (a.toString() < b.toString()) {
|
46 | return -1;
|
47 | }
|
48 | if (a.toString() > b.toString()) {
|
49 | return 1;
|
50 | }
|
51 | return 0;
|
52 | }
|
53 | function nodeToString(a) {
|
54 | if ('alias' in a) {
|
55 | return a.alias.value;
|
56 | }
|
57 | if ('name' in a) {
|
58 | return a.name.value;
|
59 | }
|
60 | return a.kind;
|
61 | }
|
62 | function compareNodes(a, b, customFn) {
|
63 | var aStr = nodeToString(a);
|
64 | var bStr = nodeToString(b);
|
65 | if (typeof customFn === 'function') {
|
66 | return customFn(aStr, bStr);
|
67 | }
|
68 | return compareStrings(aStr, bStr);
|
69 | }
|
70 |
|
71 | function debugLog() {
|
72 | var args = [];
|
73 | for (var _i = 0; _i < arguments.length; _i++) {
|
74 | args[_i] = arguments[_i];
|
75 | }
|
76 | if (process && process.env && process.env.DEBUG && !process.env.GQL_tools_NODEBUG) {
|
77 |
|
78 | console.log.apply(console, __spread(args));
|
79 | }
|
80 | }
|
81 |
|
82 | var fixWindowsPath = function (path) { return path.replace(/\\/g, '/'); };
|
83 |
|
84 | var flattenArray = function (arr) {
|
85 | return arr.reduce(function (acc, next) { return acc.concat(Array.isArray(next) ? flattenArray(next) : next); }, []);
|
86 | };
|
87 |
|
88 | var MAX_ARRAY_LENGTH = 10;
|
89 | var MAX_RECURSIVE_DEPTH = 2;
|
90 |
|
91 |
|
92 |
|
93 | function inspect(value) {
|
94 | return formatValue(value, []);
|
95 | }
|
96 | function formatValue(value, seenValues) {
|
97 | switch (typeof value) {
|
98 | case 'string':
|
99 | return JSON.stringify(value);
|
100 | case 'function':
|
101 | return value.name ? "[function " + value.name + "]" : '[function]';
|
102 | case 'object':
|
103 | if (value === null) {
|
104 | return 'null';
|
105 | }
|
106 | return formatObjectValue(value, seenValues);
|
107 | default:
|
108 | return String(value);
|
109 | }
|
110 | }
|
111 | function formatObjectValue(value, previouslySeenValues) {
|
112 | if (previouslySeenValues.indexOf(value) !== -1) {
|
113 | return '[Circular]';
|
114 | }
|
115 | var seenValues = __spread(previouslySeenValues, [value]);
|
116 | var customInspectFn = getCustomFn(value);
|
117 | if (customInspectFn !== undefined) {
|
118 | var customValue = customInspectFn.call(value);
|
119 |
|
120 | if (customValue !== value) {
|
121 | return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
|
122 | }
|
123 | }
|
124 | else if (Array.isArray(value)) {
|
125 | return formatArray(value, seenValues);
|
126 | }
|
127 | return formatObject(value, seenValues);
|
128 | }
|
129 | function formatObject(object, seenValues) {
|
130 | var keys = Object.keys(object);
|
131 | if (keys.length === 0) {
|
132 | return '{}';
|
133 | }
|
134 | if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
135 | return '[' + getObjectTag(object) + ']';
|
136 | }
|
137 | var properties = keys.map(function (key) {
|
138 | var value = formatValue(object[key], seenValues);
|
139 | return key + ': ' + value;
|
140 | });
|
141 | return '{ ' + properties.join(', ') + ' }';
|
142 | }
|
143 | function formatArray(array, seenValues) {
|
144 | if (array.length === 0) {
|
145 | return '[]';
|
146 | }
|
147 | if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
148 | return '[Array]';
|
149 | }
|
150 | var len = Math.min(MAX_ARRAY_LENGTH, array.length);
|
151 | var remaining = array.length - len;
|
152 | var items = [];
|
153 | for (var i = 0; i < len; ++i) {
|
154 | items.push(formatValue(array[i], seenValues));
|
155 | }
|
156 | if (remaining === 1) {
|
157 | items.push('... 1 more item');
|
158 | }
|
159 | else if (remaining > 1) {
|
160 | items.push("... " + remaining.toString(10) + " more items");
|
161 | }
|
162 | return '[' + items.join(', ') + ']';
|
163 | }
|
164 | function getCustomFn(obj) {
|
165 | if (typeof obj.inspect === 'function') {
|
166 | return obj.inspect;
|
167 | }
|
168 | }
|
169 | function getObjectTag(obj) {
|
170 | var tag = Object.prototype.toString
|
171 | .call(obj)
|
172 | .replace(/^\[object /, '')
|
173 | .replace(/]$/, '');
|
174 | if (tag === 'Object' && typeof obj.constructor === 'function') {
|
175 | var name_1 = obj.constructor.name;
|
176 | if (typeof name_1 === 'string' && name_1 !== '') {
|
177 | return name_1;
|
178 | }
|
179 | }
|
180 | return tag;
|
181 | }
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | function getArgumentValues(def, node, variableValues) {
|
192 | var e_1, _a;
|
193 | var _b;
|
194 | if (variableValues === void 0) { variableValues = {}; }
|
195 | var variableMap = Object.entries(variableValues).reduce(function (prev, _a) {
|
196 | var _b;
|
197 | var _c = __read(_a, 2), key = _c[0], value = _c[1];
|
198 | return (__assign(__assign({}, prev), (_b = {}, _b[key] = value, _b)));
|
199 | }, {});
|
200 | var coercedValues = {};
|
201 |
|
202 | var argumentNodes = (_b = node.arguments) !== null && _b !== void 0 ? _b : [];
|
203 | var argNodeMap = argumentNodes.reduce(function (prev, arg) {
|
204 | var _a;
|
205 | return (__assign(__assign({}, prev), (_a = {}, _a[arg.name.value] = arg, _a)));
|
206 | }, {});
|
207 | try {
|
208 | for (var _c = __values(def.args), _d = _c.next(); !_d.done; _d = _c.next()) {
|
209 | var argDef = _d.value;
|
210 | var name_1 = argDef.name;
|
211 | var argType = argDef.type;
|
212 | var argumentNode = argNodeMap[name_1];
|
213 | if (!argumentNode) {
|
214 | if (argDef.defaultValue !== undefined) {
|
215 | coercedValues[name_1] = argDef.defaultValue;
|
216 | }
|
217 | else if (isNonNullType(argType)) {
|
218 | throw new GraphQLError("Argument \"" + name_1 + "\" of required type \"" + inspect(argType) + "\" " + 'was not provided.', node);
|
219 | }
|
220 | continue;
|
221 | }
|
222 | var valueNode = argumentNode.value;
|
223 | var isNull = valueNode.kind === Kind.NULL;
|
224 | if (valueNode.kind === Kind.VARIABLE) {
|
225 | var variableName = valueNode.name.value;
|
226 | if (variableValues == null || !(variableName in variableMap)) {
|
227 | if (argDef.defaultValue !== undefined) {
|
228 | coercedValues[name_1] = argDef.defaultValue;
|
229 | }
|
230 | else if (isNonNullType(argType)) {
|
231 | throw new GraphQLError("Argument \"" + name_1 + "\" of required type \"" + inspect(argType) + "\" " +
|
232 | ("was provided the variable \"$" + variableName + "\" which was not provided a runtime value."), valueNode);
|
233 | }
|
234 | continue;
|
235 | }
|
236 | isNull = variableValues[variableName] == null;
|
237 | }
|
238 | if (isNull && isNonNullType(argType)) {
|
239 | throw new GraphQLError("Argument \"" + name_1 + "\" of non-null type \"" + inspect(argType) + "\" " + 'must not be null.', valueNode);
|
240 | }
|
241 | var coercedValue = valueFromAST(valueNode, argType, variableValues);
|
242 | if (coercedValue === undefined) {
|
243 |
|
244 |
|
245 |
|
246 | throw new GraphQLError("Argument \"" + name_1 + "\" has invalid value " + print(valueNode) + ".", valueNode);
|
247 | }
|
248 | coercedValues[name_1] = coercedValue;
|
249 | }
|
250 | }
|
251 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
252 | finally {
|
253 | try {
|
254 | if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
255 | }
|
256 | finally { if (e_1) throw e_1.error; }
|
257 | }
|
258 | return coercedValues;
|
259 | }
|
260 |
|
261 | function getDirectives(schema, node) {
|
262 | var schemaDirectives = schema && schema.getDirectives ? schema.getDirectives() : [];
|
263 | var schemaDirectiveMap = schemaDirectives.reduce(function (schemaDirectiveMap, schemaDirective) {
|
264 | schemaDirectiveMap[schemaDirective.name] = schemaDirective;
|
265 | return schemaDirectiveMap;
|
266 | }, {});
|
267 | var astNodes = [];
|
268 | if (node.astNode) {
|
269 | astNodes.push(node.astNode);
|
270 | }
|
271 | if ('extensionASTNodes' in node && node.extensionASTNodes) {
|
272 | astNodes = __spread(astNodes, node.extensionASTNodes);
|
273 | }
|
274 | var result = {};
|
275 | astNodes.forEach(function (astNode) {
|
276 | if (astNode.directives) {
|
277 | astNode.directives.forEach(function (directive) {
|
278 | var schemaDirective = schemaDirectiveMap[directive.name.value];
|
279 | if (schemaDirective) {
|
280 | var directiveValue = getDirectiveValues(schemaDirective, astNode);
|
281 | if (schemaDirective.isRepeatable) {
|
282 | if (result[schemaDirective.name]) {
|
283 | result[schemaDirective.name] = result[schemaDirective.name].concat([directiveValue]);
|
284 | }
|
285 | else {
|
286 | result[schemaDirective.name] = [directiveValue];
|
287 | }
|
288 | }
|
289 | else {
|
290 | result[schemaDirective.name] = directiveValue;
|
291 | }
|
292 | }
|
293 | });
|
294 | }
|
295 | });
|
296 | return result;
|
297 | }
|
298 |
|
299 | function getDirectiveValues(directiveDef, node) {
|
300 | if (node.directives) {
|
301 | if (directiveDef.isRepeatable) {
|
302 | var directiveNodes = node.directives.filter(function (directive) { return directive.name.value === directiveDef.name; });
|
303 | return directiveNodes.map(function (directiveNode) { return getArgumentValues(directiveDef, directiveNode); });
|
304 | }
|
305 | var directiveNode = node.directives.find(function (directive) { return directive.name.value === directiveDef.name; });
|
306 | return getArgumentValues(directiveDef, directiveNode);
|
307 | }
|
308 | }
|
309 |
|
310 | function parseDirectiveValue(value) {
|
311 | switch (value.kind) {
|
312 | case Kind.INT:
|
313 | return parseInt(value.value);
|
314 | case Kind.FLOAT:
|
315 | return parseFloat(value.value);
|
316 | case Kind.BOOLEAN:
|
317 | return Boolean(value.value);
|
318 | case Kind.STRING:
|
319 | case Kind.ENUM:
|
320 | return value.value;
|
321 | case Kind.LIST:
|
322 | return value.values.map(function (v) { return parseDirectiveValue(v); });
|
323 | case Kind.OBJECT:
|
324 | return value.fields.reduce(function (prev, v) {
|
325 | var _a;
|
326 | return (__assign(__assign({}, prev), (_a = {}, _a[v.name.value] = parseDirectiveValue(v.value), _a)));
|
327 | }, {});
|
328 | case Kind.NULL:
|
329 | return null;
|
330 | default:
|
331 | return null;
|
332 | }
|
333 | }
|
334 | function getFieldsWithDirectives(documentNode, options) {
|
335 | var e_1, _a, e_2, _b;
|
336 | if (options === void 0) { options = {}; }
|
337 | var result = {};
|
338 | var selected = ['ObjectTypeDefinition', 'ObjectTypeExtension'];
|
339 | if (options.includeInputTypes) {
|
340 | selected = __spread(selected, ['InputObjectTypeDefinition', 'InputObjectTypeExtension']);
|
341 | }
|
342 | var allTypes = documentNode.definitions.filter(function (obj) { return selected.includes(obj.kind); });
|
343 | try {
|
344 | for (var allTypes_1 = __values(allTypes), allTypes_1_1 = allTypes_1.next(); !allTypes_1_1.done; allTypes_1_1 = allTypes_1.next()) {
|
345 | var type = allTypes_1_1.value;
|
346 | var typeName = type.name.value;
|
347 | try {
|
348 | for (var _c = (e_2 = void 0, __values(type.fields)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
349 | var field = _d.value;
|
350 | if (field.directives && field.directives.length > 0) {
|
351 | var fieldName = field.name.value;
|
352 | var key = typeName + "." + fieldName;
|
353 | var directives = field.directives.map(function (d) { return ({
|
354 | name: d.name.value,
|
355 | args: (d.arguments || []).reduce(function (prev, arg) {
|
356 | var _a;
|
357 | return (__assign(__assign({}, prev), (_a = {}, _a[arg.name.value] = parseDirectiveValue(arg.value), _a)));
|
358 | }, {}),
|
359 | }); });
|
360 | result[key] = directives;
|
361 | }
|
362 | }
|
363 | }
|
364 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
365 | finally {
|
366 | try {
|
367 | if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
368 | }
|
369 | finally { if (e_2) throw e_2.error; }
|
370 | }
|
371 | }
|
372 | }
|
373 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
374 | finally {
|
375 | try {
|
376 | if (allTypes_1_1 && !allTypes_1_1.done && (_a = allTypes_1.return)) _a.call(allTypes_1);
|
377 | }
|
378 | finally { if (e_1) throw e_1.error; }
|
379 | }
|
380 | return result;
|
381 | }
|
382 |
|
383 | function getImplementingTypes(interfaceName, schema) {
|
384 | var allTypesMap = schema.getTypeMap();
|
385 | var result = [];
|
386 | for (var graphqlTypeName in allTypesMap) {
|
387 | var graphqlType = allTypesMap[graphqlTypeName];
|
388 | if (isObjectType(graphqlType)) {
|
389 | var allInterfaces = graphqlType.getInterfaces();
|
390 | if (allInterfaces.find(function (int) { return int.name === interfaceName; })) {
|
391 | result.push(graphqlType.name);
|
392 | }
|
393 | }
|
394 | }
|
395 | return result;
|
396 | }
|
397 |
|
398 | function createSchemaDefinition(def, config) {
|
399 | var schemaRoot = {};
|
400 | if (def.query) {
|
401 | schemaRoot.query = def.query.toString();
|
402 | }
|
403 | if (def.mutation) {
|
404 | schemaRoot.mutation = def.mutation.toString();
|
405 | }
|
406 | if (def.subscription) {
|
407 | schemaRoot.subscription = def.subscription.toString();
|
408 | }
|
409 | var fields = Object.keys(schemaRoot)
|
410 | .map(function (rootType) { return (schemaRoot[rootType] ? rootType + ": " + schemaRoot[rootType] : null); })
|
411 | .filter(function (a) { return a; });
|
412 | if (fields.length) {
|
413 | return "schema { " + fields.join('\n') + " }";
|
414 | }
|
415 | if (config && config.force) {
|
416 | return " schema { query: Query } ";
|
417 | }
|
418 | return undefined;
|
419 | }
|
420 |
|
421 | function printSchemaWithDirectives(schema, _options) {
|
422 | var e_1, _a;
|
423 | var _b;
|
424 | var typesMap = schema.getTypeMap();
|
425 | var result = [getSchemaDefinition(schema)];
|
426 | for (var typeName in typesMap) {
|
427 | var type = typesMap[typeName];
|
428 | var isPredefinedScalar = isScalarType(type) && isSpecifiedScalarType(type);
|
429 | var isIntrospection = isIntrospectionType(type);
|
430 | if (isPredefinedScalar || isIntrospection) {
|
431 | continue;
|
432 | }
|
433 |
|
434 | result.push(print((_b = correctType(typeName, typesMap)) === null || _b === void 0 ? void 0 : _b.astNode));
|
435 | }
|
436 | var directives = schema.getDirectives();
|
437 | try {
|
438 | for (var directives_1 = __values(directives), directives_1_1 = directives_1.next(); !directives_1_1.done; directives_1_1 = directives_1.next()) {
|
439 | var directive = directives_1_1.value;
|
440 | if (directive.astNode) {
|
441 | result.push(print(directive.astNode));
|
442 | }
|
443 | }
|
444 | }
|
445 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
446 | finally {
|
447 | try {
|
448 | if (directives_1_1 && !directives_1_1.done && (_a = directives_1.return)) _a.call(directives_1);
|
449 | }
|
450 | finally { if (e_1) throw e_1.error; }
|
451 | }
|
452 | return result.join('\n');
|
453 | }
|
454 | function extendDefinition(type) {
|
455 | switch (type.astNode.kind) {
|
456 | case Kind.OBJECT_TYPE_DEFINITION:
|
457 | return __assign(__assign({}, type.astNode), { fields: type.astNode.fields.concat(type.extensionASTNodes.reduce(function (fields, node) { return fields.concat(node.fields); }, [])) });
|
458 | case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
459 | return __assign(__assign({}, type.astNode), { fields: type.astNode.fields.concat(type.extensionASTNodes.reduce(function (fields, node) { return fields.concat(node.fields); }, [])) });
|
460 | default:
|
461 | return type.astNode;
|
462 | }
|
463 | }
|
464 | function correctType(typeName, typesMap) {
|
465 | var e_2, _a, e_3, _b;
|
466 | var type = typesMap[typeName];
|
467 | type.name = typeName.toString();
|
468 | if (type.astNode && type.extensionASTNodes) {
|
469 | type.astNode = type.extensionASTNodes ? extendDefinition(type) : type.astNode;
|
470 | }
|
471 | var doc = parse(printType(type));
|
472 | var fixedAstNode = doc.definitions[0];
|
473 | var originalAstNode = type === null || type === void 0 ? void 0 : type.astNode;
|
474 | if (originalAstNode) {
|
475 | fixedAstNode.directives = originalAstNode === null || originalAstNode === void 0 ? void 0 : originalAstNode.directives;
|
476 | if (fixedAstNode && 'fields' in fixedAstNode && originalAstNode && 'fields' in originalAstNode) {
|
477 | var _loop_1 = function (fieldDefinitionNode) {
|
478 | var e_4, _a;
|
479 | var originalFieldDefinitionNode = originalAstNode.fields.find(function (field) { return field.name.value === fieldDefinitionNode.name.value; });
|
480 | fieldDefinitionNode.directives = originalFieldDefinitionNode === null || originalFieldDefinitionNode === void 0 ? void 0 : originalFieldDefinitionNode.directives;
|
481 | if (fieldDefinitionNode &&
|
482 | 'arguments' in fieldDefinitionNode &&
|
483 | originalFieldDefinitionNode &&
|
484 | 'arguments' in originalFieldDefinitionNode) {
|
485 | var _loop_3 = function (argument) {
|
486 | var originalArgumentNode = (_c = originalFieldDefinitionNode.arguments) === null || _c === void 0 ? void 0 : _c.find(function (arg) { return arg.name.value === argument.name.value; });
|
487 | argument.directives = originalArgumentNode.directives;
|
488 | };
|
489 | try {
|
490 | for (var _b = (e_4 = void 0, __values(fieldDefinitionNode.arguments)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
491 | var argument = _c.value;
|
492 | _loop_3(argument);
|
493 | }
|
494 | }
|
495 | catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
496 | finally {
|
497 | try {
|
498 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
499 | }
|
500 | finally { if (e_4) throw e_4.error; }
|
501 | }
|
502 | }
|
503 | };
|
504 | try {
|
505 | for (var _d = __values(fixedAstNode.fields), _e = _d.next(); !_e.done; _e = _d.next()) {
|
506 | var fieldDefinitionNode = _e.value;
|
507 | _loop_1(fieldDefinitionNode);
|
508 | }
|
509 | }
|
510 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
511 | finally {
|
512 | try {
|
513 | if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
514 | }
|
515 | finally { if (e_2) throw e_2.error; }
|
516 | }
|
517 | }
|
518 | else if (fixedAstNode && 'values' in fixedAstNode && originalAstNode && 'values' in originalAstNode) {
|
519 | var _loop_2 = function (valueDefinitionNode) {
|
520 | var originalValueDefinitionNode = originalAstNode.values.find(function (valueNode) { return valueNode.name.value === valueDefinitionNode.name.value; });
|
521 | valueDefinitionNode.directives = originalValueDefinitionNode === null || originalValueDefinitionNode === void 0 ? void 0 : originalValueDefinitionNode.directives;
|
522 | };
|
523 | try {
|
524 | for (var _f = __values(fixedAstNode.values), _g = _f.next(); !_g.done; _g = _f.next()) {
|
525 | var valueDefinitionNode = _g.value;
|
526 | _loop_2(valueDefinitionNode);
|
527 | }
|
528 | }
|
529 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
530 | finally {
|
531 | try {
|
532 | if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
533 | }
|
534 | finally { if (e_3) throw e_3.error; }
|
535 | }
|
536 | }
|
537 | }
|
538 | type.astNode = fixedAstNode;
|
539 | return type;
|
540 | }
|
541 | function getSchemaDefinition(schema) {
|
542 | if (!Object.getOwnPropertyDescriptor(schema, 'astNode').get && schema.astNode) {
|
543 | return print(schema.astNode);
|
544 | }
|
545 | else {
|
546 | return createSchemaDefinition({
|
547 | query: schema.getQueryType(),
|
548 | mutation: schema.getMutationType(),
|
549 | subscription: schema.getSubscriptionType(),
|
550 | });
|
551 | }
|
552 | }
|
553 |
|
554 | function validateGraphQlDocuments(schema, documentFiles, effectiveRules) {
|
555 | return __awaiter(this, void 0, void 0, function () {
|
556 | var allFragments, allErrors;
|
557 | var _this = this;
|
558 | return __generator(this, function (_a) {
|
559 | switch (_a.label) {
|
560 | case 0:
|
561 | effectiveRules = effectiveRules || createDefaultRules();
|
562 | allFragments = [];
|
563 | documentFiles.forEach(function (documentFile) {
|
564 | var e_1, _a;
|
565 | if (documentFile.document) {
|
566 | try {
|
567 | for (var _b = __values(documentFile.document.definitions), _c = _b.next(); !_c.done; _c = _b.next()) {
|
568 | var definitionNode = _c.value;
|
569 | if (definitionNode.kind === Kind.FRAGMENT_DEFINITION) {
|
570 | allFragments.push(definitionNode);
|
571 | }
|
572 | }
|
573 | }
|
574 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
575 | finally {
|
576 | try {
|
577 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
578 | }
|
579 | finally { if (e_1) throw e_1.error; }
|
580 | }
|
581 | }
|
582 | });
|
583 | allErrors = [];
|
584 | return [4 , Promise.all(documentFiles.map(function (documentFile) { return __awaiter(_this, void 0, void 0, function () {
|
585 | var documentToValidate, errors;
|
586 | return __generator(this, function (_a) {
|
587 | documentToValidate = {
|
588 | kind: Kind.DOCUMENT,
|
589 | definitions: __spread(allFragments, documentFile.document.definitions).filter(function (definition, index, list) {
|
590 | if (definition.kind === Kind.FRAGMENT_DEFINITION) {
|
591 | var firstIndex = list.findIndex(function (def) { return def.kind === Kind.FRAGMENT_DEFINITION && def.name.value === definition.name.value; });
|
592 | var isDuplicated = firstIndex !== index;
|
593 | if (isDuplicated) {
|
594 | return false;
|
595 | }
|
596 | }
|
597 | return true;
|
598 | }),
|
599 | };
|
600 | errors = validate(schema, documentToValidate, effectiveRules);
|
601 | if (errors.length > 0) {
|
602 | allErrors.push({
|
603 | filePath: documentFile.location,
|
604 | errors: errors,
|
605 | });
|
606 | }
|
607 | return [2 ];
|
608 | });
|
609 | }); }))];
|
610 | case 1:
|
611 | _a.sent();
|
612 | return [2 , allErrors];
|
613 | }
|
614 | });
|
615 | });
|
616 | }
|
617 | function checkValidationErrors(loadDocumentErrors) {
|
618 | var e_2, _a;
|
619 | if (loadDocumentErrors.length > 0) {
|
620 | var errors = [];
|
621 | var _loop_1 = function (loadDocumentError) {
|
622 | var e_3, _a;
|
623 | var _loop_2 = function (graphQLError) {
|
624 | var error = new Error();
|
625 | error.name = 'GraphQLDocumentError';
|
626 | error.message = error.name + ": " + graphQLError.message;
|
627 | error.stack = error.message;
|
628 | graphQLError.locations.forEach(function (location) { return (error.stack += "\n at " + loadDocumentError.filePath + ":" + location.line + ":" + location.column); });
|
629 | errors.push(error);
|
630 | };
|
631 | try {
|
632 | for (var _b = (e_3 = void 0, __values(loadDocumentError.errors)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
633 | var graphQLError = _c.value;
|
634 | _loop_2(graphQLError);
|
635 | }
|
636 | }
|
637 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
638 | finally {
|
639 | try {
|
640 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
641 | }
|
642 | finally { if (e_3) throw e_3.error; }
|
643 | }
|
644 | };
|
645 | try {
|
646 | for (var loadDocumentErrors_1 = __values(loadDocumentErrors), loadDocumentErrors_1_1 = loadDocumentErrors_1.next(); !loadDocumentErrors_1_1.done; loadDocumentErrors_1_1 = loadDocumentErrors_1.next()) {
|
647 | var loadDocumentError = loadDocumentErrors_1_1.value;
|
648 | _loop_1(loadDocumentError);
|
649 | }
|
650 | }
|
651 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
652 | finally {
|
653 | try {
|
654 | if (loadDocumentErrors_1_1 && !loadDocumentErrors_1_1.done && (_a = loadDocumentErrors_1.return)) _a.call(loadDocumentErrors_1);
|
655 | }
|
656 | finally { if (e_2) throw e_2.error; }
|
657 | }
|
658 | throw new AggregateError(errors);
|
659 | }
|
660 | }
|
661 | function createDefaultRules() {
|
662 | var ignored = ['NoUnusedFragmentsRule', 'NoUnusedVariablesRule', 'KnownDirectivesRule'];
|
663 |
|
664 |
|
665 | ignored.forEach(function (rule) {
|
666 | ignored.push(rule.replace(/Rule$/, ''));
|
667 | });
|
668 | return specifiedRules.filter(function (f) { return !ignored.includes(f.name); });
|
669 | }
|
670 |
|
671 | function buildFixedSchema(schema, options) {
|
672 | return buildSchema(printSchemaWithDirectives(schema), __assign({ noLocation: true }, (options || {})));
|
673 | }
|
674 | function fixSchemaAst(schema, options) {
|
675 | var schemaWithValidAst;
|
676 | if (!schema.astNode) {
|
677 | Object.defineProperty(schema, 'astNode', {
|
678 | get: function () {
|
679 | if (!schemaWithValidAst) {
|
680 | schemaWithValidAst = buildFixedSchema(schema, options);
|
681 | }
|
682 | return schemaWithValidAst.astNode;
|
683 | },
|
684 | });
|
685 | }
|
686 | if (!schema.extensionASTNodes) {
|
687 | Object.defineProperty(schema, 'extensionASTNodes', {
|
688 | get: function () {
|
689 | if (!schemaWithValidAst) {
|
690 | schemaWithValidAst = buildFixedSchema(schema, options);
|
691 | }
|
692 | return schemaWithValidAst.extensionASTNodes;
|
693 | },
|
694 | });
|
695 | }
|
696 | return schema;
|
697 | }
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 | function dedentBlockStringValue(rawString) {
|
708 |
|
709 | var lines = rawString.split(/\r\n|[\n\r]/g);
|
710 |
|
711 | var commonIndent = getBlockStringIndentation(lines);
|
712 |
|
713 | if (commonIndent !== 0) {
|
714 | for (var i = 1; i < lines.length; i++) {
|
715 | lines[i] = lines[i].slice(commonIndent);
|
716 | }
|
717 | }
|
718 |
|
719 |
|
720 | while (lines.length > 0 && isBlank(lines[0])) {
|
721 | lines.shift();
|
722 | }
|
723 |
|
724 | while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
|
725 | lines.pop();
|
726 | }
|
727 |
|
728 |
|
729 | return lines.join('\n');
|
730 | }
|
731 |
|
732 |
|
733 |
|
734 |
|
735 | function getBlockStringIndentation(lines) {
|
736 | var commonIndent = null;
|
737 |
|
738 | for (var i = 1; i < lines.length; i++) {
|
739 | var line = lines[i];
|
740 | var indent = leadingWhitespace(line);
|
741 |
|
742 | if (indent === line.length) {
|
743 | continue;
|
744 | }
|
745 |
|
746 | if (commonIndent === null || indent < commonIndent) {
|
747 | commonIndent = indent;
|
748 |
|
749 | if (commonIndent === 0) {
|
750 | break;
|
751 | }
|
752 | }
|
753 | }
|
754 |
|
755 | return commonIndent === null ? 0 : commonIndent;
|
756 | }
|
757 |
|
758 | function leadingWhitespace(str) {
|
759 | var i = 0;
|
760 |
|
761 | while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
|
762 | i++;
|
763 | }
|
764 |
|
765 | return i;
|
766 | }
|
767 |
|
768 | function isBlank(str) {
|
769 | return leadingWhitespace(str) === str.length;
|
770 | }
|
771 |
|
772 | function parseGraphQLSDL(location, rawSDL, options) {
|
773 | if (options === void 0) { options = {}; }
|
774 | var document;
|
775 | var sdl = rawSDL;
|
776 | var sdlModified = false;
|
777 | try {
|
778 | if (options.commentDescriptions && sdl.includes('#')) {
|
779 | sdlModified = true;
|
780 | document = transformCommentsToDescriptions(rawSDL, options);
|
781 |
|
782 |
|
783 |
|
784 | if (options.noLocation) {
|
785 | document = parse(print(document), options);
|
786 | }
|
787 | }
|
788 | else {
|
789 | document = parse(new Source(sdl, location), options);
|
790 | }
|
791 | }
|
792 | catch (e) {
|
793 | if (e.message.includes('EOF')) {
|
794 | document = {
|
795 | kind: Kind.DOCUMENT,
|
796 | definitions: [],
|
797 | };
|
798 | }
|
799 | else {
|
800 | throw e;
|
801 | }
|
802 | }
|
803 | return {
|
804 | location: location,
|
805 | document: document,
|
806 | rawSDL: sdlModified ? print(document) : sdl,
|
807 | };
|
808 | }
|
809 | function getLeadingCommentBlock(node) {
|
810 | var loc = node.loc;
|
811 | if (!loc) {
|
812 | return;
|
813 | }
|
814 | var comments = [];
|
815 | var token = loc.startToken.prev;
|
816 | while (token != null &&
|
817 | token.kind === TokenKind.COMMENT &&
|
818 | token.next &&
|
819 | token.prev &&
|
820 | token.line + 1 === token.next.line &&
|
821 | token.line !== token.prev.line) {
|
822 | var value = String(token.value);
|
823 | comments.push(value);
|
824 | token = token.prev;
|
825 | }
|
826 | return comments.length > 0 ? comments.reverse().join('\n') : undefined;
|
827 | }
|
828 | function transformCommentsToDescriptions(sourceSdl, options) {
|
829 | if (options === void 0) { options = {}; }
|
830 | var parsedDoc = parse(sourceSdl, __assign(__assign({}, options), { noLocation: false }));
|
831 | var modifiedDoc = visit(parsedDoc, {
|
832 | leave: function (node) {
|
833 | if (isDescribable(node)) {
|
834 | var rawValue = getLeadingCommentBlock(node);
|
835 | if (rawValue !== undefined) {
|
836 | var commentsBlock = dedentBlockStringValue('\n' + rawValue);
|
837 | var isBlock = commentsBlock.includes('\n');
|
838 | if (!node.description) {
|
839 | return __assign(__assign({}, node), { description: {
|
840 | kind: Kind.STRING,
|
841 | value: commentsBlock,
|
842 | block: isBlock,
|
843 | } });
|
844 | }
|
845 | else {
|
846 | return __assign(__assign({}, node), { description: __assign(__assign({}, node.description), { value: node.description.value + '\n' + commentsBlock, block: true }) });
|
847 | }
|
848 | }
|
849 | }
|
850 | },
|
851 | });
|
852 | return modifiedDoc;
|
853 | }
|
854 | function isDescribable(node) {
|
855 | return (isTypeSystemDefinitionNode(node) ||
|
856 | node.kind === Kind.FIELD_DEFINITION ||
|
857 | node.kind === Kind.INPUT_VALUE_DEFINITION ||
|
858 | node.kind === Kind.ENUM_VALUE_DEFINITION);
|
859 | }
|
860 |
|
861 | function stripBOM(content) {
|
862 | content = content.toString();
|
863 |
|
864 |
|
865 |
|
866 | if (content.charCodeAt(0) === 0xfeff) {
|
867 | content = content.slice(1);
|
868 | }
|
869 | return content;
|
870 | }
|
871 | function parseBOM(content) {
|
872 | return JSON.parse(stripBOM(content));
|
873 | }
|
874 | function parseGraphQLJSON(location, jsonContent, options) {
|
875 | var parsedJson = parseBOM(jsonContent);
|
876 | if (parsedJson.data) {
|
877 | parsedJson = parsedJson.data;
|
878 | }
|
879 | if (parsedJson.kind === 'Document') {
|
880 | var document_1 = parsedJson;
|
881 | return {
|
882 | location: location,
|
883 | document: document_1,
|
884 | };
|
885 | }
|
886 | else if (parsedJson.__schema) {
|
887 | var schema = buildClientSchema(parsedJson, options);
|
888 | var rawSDL = printSchemaWithDirectives(schema);
|
889 | return {
|
890 | location: location,
|
891 | document: parseGraphQLSDL(location, rawSDL, options).document,
|
892 | rawSDL: rawSDL,
|
893 | schema: schema,
|
894 | };
|
895 | }
|
896 | throw new Error("Not valid JSON content");
|
897 | }
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 | function getUserTypesFromSchema(schema) {
|
908 | var allTypesMap = schema.getTypeMap();
|
909 |
|
910 | var modelTypes = Object.values(allTypesMap).filter(function (graphqlType) {
|
911 | if (isObjectType(graphqlType)) {
|
912 |
|
913 | if (graphqlType.name.startsWith('__')) {
|
914 | return false;
|
915 | }
|
916 | if (schema.getMutationType() && graphqlType.name === schema.getMutationType().name) {
|
917 | return false;
|
918 | }
|
919 | if (schema.getQueryType() && graphqlType.name === schema.getQueryType().name) {
|
920 | return false;
|
921 | }
|
922 | if (schema.getSubscriptionType() && graphqlType.name === schema.getSubscriptionType().name) {
|
923 | return false;
|
924 | }
|
925 | return true;
|
926 | }
|
927 | return false;
|
928 | });
|
929 | return modelTypes;
|
930 | }
|
931 |
|
932 | var operationVariables = [];
|
933 | var fieldTypeMap = new Map();
|
934 | function addOperationVariable(variable) {
|
935 | operationVariables.push(variable);
|
936 | }
|
937 | function resetOperationVariables() {
|
938 | operationVariables = [];
|
939 | }
|
940 | function resetFieldMap() {
|
941 | fieldTypeMap = new Map();
|
942 | }
|
943 | function buildOperationName(name) {
|
944 | return camelCase(name);
|
945 | }
|
946 | function buildOperationNodeForField(_a) {
|
947 | var schema = _a.schema, kind = _a.kind, field = _a.field, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, _b = _a.selectedFields, selectedFields = _b === void 0 ? true : _b;
|
948 | resetOperationVariables();
|
949 | resetFieldMap();
|
950 | var operationNode = buildOperationAndCollectVariables({
|
951 | schema: schema,
|
952 | fieldName: field,
|
953 | kind: kind,
|
954 | models: models || [],
|
955 | ignore: ignore || [],
|
956 | depthLimit: depthLimit || Infinity,
|
957 | circularReferenceDepth: circularReferenceDepth || 1,
|
958 | argNames: argNames,
|
959 | selectedFields: selectedFields,
|
960 | });
|
961 |
|
962 | operationNode.variableDefinitions = __spread(operationVariables);
|
963 | resetOperationVariables();
|
964 | resetFieldMap();
|
965 | return operationNode;
|
966 | }
|
967 | function buildOperationAndCollectVariables(_a) {
|
968 | var schema = _a.schema, fieldName = _a.fieldName, kind = _a.kind, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, selectedFields = _a.selectedFields;
|
969 | var typeMap = {
|
970 | query: schema.getQueryType(),
|
971 | mutation: schema.getMutationType(),
|
972 | subscription: schema.getSubscriptionType(),
|
973 | };
|
974 | var type = typeMap[kind];
|
975 | var field = type.getFields()[fieldName];
|
976 | var operationName = buildOperationName(fieldName + "_" + kind);
|
977 | if (field.args) {
|
978 | field.args.forEach(function (arg) {
|
979 | var argName = arg.name;
|
980 | if (!argNames || argNames.includes(argName)) {
|
981 | addOperationVariable(resolveVariable(arg, argName));
|
982 | }
|
983 | });
|
984 | }
|
985 | return {
|
986 | kind: Kind.OPERATION_DEFINITION,
|
987 | operation: kind,
|
988 | name: {
|
989 | kind: 'Name',
|
990 | value: operationName,
|
991 | },
|
992 | variableDefinitions: [],
|
993 | selectionSet: {
|
994 | kind: Kind.SELECTION_SET,
|
995 | selections: [
|
996 | resolveField({
|
997 | type: type,
|
998 | field: field,
|
999 | models: models,
|
1000 | firstCall: true,
|
1001 | path: [],
|
1002 | ancestors: [],
|
1003 | ignore: ignore,
|
1004 | depthLimit: depthLimit,
|
1005 | circularReferenceDepth: circularReferenceDepth,
|
1006 | schema: schema,
|
1007 | depth: 0,
|
1008 | argNames: argNames,
|
1009 | selectedFields: selectedFields,
|
1010 | }),
|
1011 | ],
|
1012 | },
|
1013 | };
|
1014 | }
|
1015 | function resolveSelectionSet(_a) {
|
1016 | var parent = _a.parent, type = _a.type, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields;
|
1017 | if (typeof selectedFields === 'boolean' && depth > depthLimit) {
|
1018 | return;
|
1019 | }
|
1020 | if (isUnionType(type)) {
|
1021 | var types = type.getTypes();
|
1022 | return {
|
1023 | kind: Kind.SELECTION_SET,
|
1024 | selections: types
|
1025 | .filter(function (t) {
|
1026 | return !hasCircularRef(__spread(ancestors, [t]), {
|
1027 | depth: circularReferenceDepth,
|
1028 | });
|
1029 | })
|
1030 | .map(function (t) {
|
1031 | return {
|
1032 | kind: Kind.INLINE_FRAGMENT,
|
1033 | typeCondition: {
|
1034 | kind: Kind.NAMED_TYPE,
|
1035 | name: {
|
1036 | kind: Kind.NAME,
|
1037 | value: t.name,
|
1038 | },
|
1039 | },
|
1040 | selectionSet: resolveSelectionSet({
|
1041 | parent: type,
|
1042 | type: t,
|
1043 | models: models,
|
1044 | path: path,
|
1045 | ancestors: ancestors,
|
1046 | ignore: ignore,
|
1047 | depthLimit: depthLimit,
|
1048 | circularReferenceDepth: circularReferenceDepth,
|
1049 | schema: schema,
|
1050 | depth: depth,
|
1051 | argNames: argNames,
|
1052 | selectedFields: selectedFields,
|
1053 | }),
|
1054 | };
|
1055 | })
|
1056 | .filter(function (fragmentNode) { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
|
1057 | };
|
1058 | }
|
1059 | if (isInterfaceType(type)) {
|
1060 | var types = Object.values(schema.getTypeMap()).filter(function (t) { return isObjectType(t) && t.getInterfaces().includes(type); });
|
1061 | return {
|
1062 | kind: Kind.SELECTION_SET,
|
1063 | selections: types
|
1064 | .filter(function (t) {
|
1065 | return !hasCircularRef(__spread(ancestors, [t]), {
|
1066 | depth: circularReferenceDepth,
|
1067 | });
|
1068 | })
|
1069 | .map(function (t) {
|
1070 | return {
|
1071 | kind: Kind.INLINE_FRAGMENT,
|
1072 | typeCondition: {
|
1073 | kind: Kind.NAMED_TYPE,
|
1074 | name: {
|
1075 | kind: Kind.NAME,
|
1076 | value: t.name,
|
1077 | },
|
1078 | },
|
1079 | selectionSet: resolveSelectionSet({
|
1080 | parent: type,
|
1081 | type: t,
|
1082 | models: models,
|
1083 | path: path,
|
1084 | ancestors: ancestors,
|
1085 | ignore: ignore,
|
1086 | depthLimit: depthLimit,
|
1087 | circularReferenceDepth: circularReferenceDepth,
|
1088 | schema: schema,
|
1089 | depth: depth,
|
1090 | argNames: argNames,
|
1091 | selectedFields: selectedFields,
|
1092 | }),
|
1093 | };
|
1094 | })
|
1095 | .filter(function (fragmentNode) { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
|
1096 | };
|
1097 | }
|
1098 | if (isObjectType(type)) {
|
1099 | var isIgnored = ignore.includes(type.name) || ignore.includes(parent.name + "." + path[path.length - 1]);
|
1100 | var isModel = models.includes(type.name);
|
1101 | if (!firstCall && isModel && !isIgnored) {
|
1102 | return {
|
1103 | kind: Kind.SELECTION_SET,
|
1104 | selections: [
|
1105 | {
|
1106 | kind: Kind.FIELD,
|
1107 | name: {
|
1108 | kind: Kind.NAME,
|
1109 | value: 'id',
|
1110 | },
|
1111 | },
|
1112 | ],
|
1113 | };
|
1114 | }
|
1115 | var fields_1 = type.getFields();
|
1116 | return {
|
1117 | kind: Kind.SELECTION_SET,
|
1118 | selections: Object.keys(fields_1)
|
1119 | .filter(function (fieldName) {
|
1120 | return !hasCircularRef(__spread(ancestors, [getNamedType(fields_1[fieldName].type)]), {
|
1121 | depth: circularReferenceDepth,
|
1122 | });
|
1123 | })
|
1124 | .map(function (fieldName) {
|
1125 | var selectedSubFields = typeof selectedFields === 'object' ? selectedFields[fieldName] : true;
|
1126 | if (selectedSubFields) {
|
1127 | return resolveField({
|
1128 | type: type,
|
1129 | field: fields_1[fieldName],
|
1130 | models: models,
|
1131 | path: __spread(path, [fieldName]),
|
1132 | ancestors: ancestors,
|
1133 | ignore: ignore,
|
1134 | depthLimit: depthLimit,
|
1135 | circularReferenceDepth: circularReferenceDepth,
|
1136 | schema: schema,
|
1137 | depth: depth,
|
1138 | argNames: argNames,
|
1139 | selectedFields: selectedSubFields,
|
1140 | });
|
1141 | }
|
1142 | })
|
1143 | .filter(function (f) {
|
1144 | var _a, _b;
|
1145 | if (f) {
|
1146 | if ('selectionSet' in f) {
|
1147 | return (_b = (_a = f.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length;
|
1148 | }
|
1149 | else {
|
1150 | return true;
|
1151 | }
|
1152 | }
|
1153 | return false;
|
1154 | }),
|
1155 | };
|
1156 | }
|
1157 | }
|
1158 | function resolveVariable(arg, name) {
|
1159 | function resolveVariableType(type) {
|
1160 | if (isListType(type)) {
|
1161 | return {
|
1162 | kind: Kind.LIST_TYPE,
|
1163 | type: resolveVariableType(type.ofType),
|
1164 | };
|
1165 | }
|
1166 | if (isNonNullType(type)) {
|
1167 | return {
|
1168 | kind: Kind.NON_NULL_TYPE,
|
1169 | type: resolveVariableType(type.ofType),
|
1170 | };
|
1171 | }
|
1172 | return {
|
1173 | kind: Kind.NAMED_TYPE,
|
1174 | name: {
|
1175 | kind: Kind.NAME,
|
1176 | value: type.name,
|
1177 | },
|
1178 | };
|
1179 | }
|
1180 | return {
|
1181 | kind: Kind.VARIABLE_DEFINITION,
|
1182 | variable: {
|
1183 | kind: Kind.VARIABLE,
|
1184 | name: {
|
1185 | kind: Kind.NAME,
|
1186 | value: name || arg.name,
|
1187 | },
|
1188 | },
|
1189 | type: resolveVariableType(arg.type),
|
1190 | };
|
1191 | }
|
1192 | function getArgumentName(name, path) {
|
1193 | return camelCase(__spread(path, [name]).join('_'));
|
1194 | }
|
1195 | function resolveField(_a) {
|
1196 | var type = _a.type, field = _a.field, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields;
|
1197 | var namedType = getNamedType(field.type);
|
1198 | var args = [];
|
1199 | var removeField = false;
|
1200 | if (field.args && field.args.length) {
|
1201 | args = field.args
|
1202 | .map(function (arg) {
|
1203 | var argumentName = getArgumentName(arg.name, path);
|
1204 | if (argNames && !argNames.includes(argumentName)) {
|
1205 | if (isNonNullType(arg.type)) {
|
1206 | removeField = true;
|
1207 | }
|
1208 | return null;
|
1209 | }
|
1210 | if (!firstCall) {
|
1211 | addOperationVariable(resolveVariable(arg, argumentName));
|
1212 | }
|
1213 | return {
|
1214 | kind: Kind.ARGUMENT,
|
1215 | name: {
|
1216 | kind: Kind.NAME,
|
1217 | value: arg.name,
|
1218 | },
|
1219 | value: {
|
1220 | kind: Kind.VARIABLE,
|
1221 | name: {
|
1222 | kind: Kind.NAME,
|
1223 | value: getArgumentName(arg.name, path),
|
1224 | },
|
1225 | },
|
1226 | };
|
1227 | })
|
1228 | .filter(Boolean);
|
1229 | }
|
1230 | if (removeField) {
|
1231 | return null;
|
1232 | }
|
1233 | var fieldPath = __spread(path, [field.name]);
|
1234 | var fieldPathStr = fieldPath.join('.');
|
1235 | var fieldName = field.name;
|
1236 | if (fieldTypeMap.has(fieldPathStr) && fieldTypeMap.get(fieldPathStr) !== field.type.toString()) {
|
1237 | fieldName += field.type.toString().replace('!', 'NonNull');
|
1238 | }
|
1239 | fieldTypeMap.set(fieldPathStr, field.type.toString());
|
1240 | if (!isScalarType(namedType) && !isEnumType(namedType)) {
|
1241 | return __assign(__assign({ kind: Kind.FIELD, name: {
|
1242 | kind: Kind.NAME,
|
1243 | value: field.name,
|
1244 | } }, (fieldName !== field.name && { alias: { kind: Kind.NAME, value: fieldName } })), { selectionSet: resolveSelectionSet({
|
1245 | parent: type,
|
1246 | type: namedType,
|
1247 | models: models,
|
1248 | firstCall: firstCall,
|
1249 | path: fieldPath,
|
1250 | ancestors: __spread(ancestors, [type]),
|
1251 | ignore: ignore,
|
1252 | depthLimit: depthLimit,
|
1253 | circularReferenceDepth: circularReferenceDepth,
|
1254 | schema: schema,
|
1255 | depth: depth + 1,
|
1256 | argNames: argNames,
|
1257 | selectedFields: selectedFields,
|
1258 | }) || undefined, arguments: args });
|
1259 | }
|
1260 | return __assign(__assign({ kind: Kind.FIELD, name: {
|
1261 | kind: Kind.NAME,
|
1262 | value: field.name,
|
1263 | } }, (fieldName !== field.name && { alias: { kind: Kind.NAME, value: fieldName } })), { arguments: args });
|
1264 | }
|
1265 | function hasCircularRef(types, config) {
|
1266 | if (config === void 0) { config = {
|
1267 | depth: 1,
|
1268 | }; }
|
1269 | var type = types[types.length - 1];
|
1270 | if (isScalarType(type)) {
|
1271 | return false;
|
1272 | }
|
1273 | var size = types.filter(function (t) { return t.name === type.name; }).length;
|
1274 | return size > config.depth;
|
1275 | }
|
1276 |
|
1277 | var VisitSchemaKind;
|
1278 | (function (VisitSchemaKind) {
|
1279 | VisitSchemaKind["TYPE"] = "VisitSchemaKind.TYPE";
|
1280 | VisitSchemaKind["SCALAR_TYPE"] = "VisitSchemaKind.SCALAR_TYPE";
|
1281 | VisitSchemaKind["ENUM_TYPE"] = "VisitSchemaKind.ENUM_TYPE";
|
1282 | VisitSchemaKind["COMPOSITE_TYPE"] = "VisitSchemaKind.COMPOSITE_TYPE";
|
1283 | VisitSchemaKind["OBJECT_TYPE"] = "VisitSchemaKind.OBJECT_TYPE";
|
1284 | VisitSchemaKind["INPUT_OBJECT_TYPE"] = "VisitSchemaKind.INPUT_OBJECT_TYPE";
|
1285 | VisitSchemaKind["ABSTRACT_TYPE"] = "VisitSchemaKind.ABSTRACT_TYPE";
|
1286 | VisitSchemaKind["UNION_TYPE"] = "VisitSchemaKind.UNION_TYPE";
|
1287 | VisitSchemaKind["INTERFACE_TYPE"] = "VisitSchemaKind.INTERFACE_TYPE";
|
1288 | VisitSchemaKind["ROOT_OBJECT"] = "VisitSchemaKind.ROOT_OBJECT";
|
1289 | VisitSchemaKind["QUERY"] = "VisitSchemaKind.QUERY";
|
1290 | VisitSchemaKind["MUTATION"] = "VisitSchemaKind.MUTATION";
|
1291 | VisitSchemaKind["SUBSCRIPTION"] = "VisitSchemaKind.SUBSCRIPTION";
|
1292 | })(VisitSchemaKind || (VisitSchemaKind = {}));
|
1293 | var MapperKind;
|
1294 | (function (MapperKind) {
|
1295 | MapperKind["TYPE"] = "MapperKind.TYPE";
|
1296 | MapperKind["SCALAR_TYPE"] = "MapperKind.SCALAR_TYPE";
|
1297 | MapperKind["ENUM_TYPE"] = "MapperKind.ENUM_TYPE";
|
1298 | MapperKind["COMPOSITE_TYPE"] = "MapperKind.COMPOSITE_TYPE";
|
1299 | MapperKind["OBJECT_TYPE"] = "MapperKind.OBJECT_TYPE";
|
1300 | MapperKind["INPUT_OBJECT_TYPE"] = "MapperKind.INPUT_OBJECT_TYPE";
|
1301 | MapperKind["ABSTRACT_TYPE"] = "MapperKind.ABSTRACT_TYPE";
|
1302 | MapperKind["UNION_TYPE"] = "MapperKind.UNION_TYPE";
|
1303 | MapperKind["INTERFACE_TYPE"] = "MapperKind.INTERFACE_TYPE";
|
1304 | MapperKind["ROOT_OBJECT"] = "MapperKind.ROOT_OBJECT";
|
1305 | MapperKind["QUERY"] = "MapperKind.QUERY";
|
1306 | MapperKind["MUTATION"] = "MapperKind.MUTATION";
|
1307 | MapperKind["SUBSCRIPTION"] = "MapperKind.SUBSCRIPTION";
|
1308 | MapperKind["DIRECTIVE"] = "MapperKind.DIRECTIVE";
|
1309 | MapperKind["FIELD"] = "MapperKind.FIELD";
|
1310 | MapperKind["COMPOSITE_FIELD"] = "MapperKind.COMPOSITE_FIELD";
|
1311 | MapperKind["OBJECT_FIELD"] = "MapperKind.OBJECT_FIELD";
|
1312 | MapperKind["ROOT_FIELD"] = "MapperKind.ROOT_FIELD";
|
1313 | MapperKind["QUERY_ROOT_FIELD"] = "MapperKind.QUERY_ROOT_FIELD";
|
1314 | MapperKind["MUTATION_ROOT_FIELD"] = "MapperKind.MUTATION_ROOT_FIELD";
|
1315 | MapperKind["SUBSCRIPTION_ROOT_FIELD"] = "MapperKind.SUBSCRIPTION_ROOT_FIELD";
|
1316 | MapperKind["INTERFACE_FIELD"] = "MapperKind.INTERFACE_FIELD";
|
1317 | MapperKind["INPUT_OBJECT_FIELD"] = "MapperKind.INPUT_OBJECT_FIELD";
|
1318 | MapperKind["ARGUMENT"] = "MapperKind.ARGUMENT";
|
1319 | MapperKind["ENUM_VALUE"] = "MapperKind.ENUM_VALUE";
|
1320 | })(MapperKind || (MapperKind = {}));
|
1321 |
|
1322 | function createNamedStub(name, type) {
|
1323 | var constructor;
|
1324 | if (type === 'object') {
|
1325 | constructor = GraphQLObjectType;
|
1326 | }
|
1327 | else if (type === 'interface') {
|
1328 | constructor = GraphQLInterfaceType;
|
1329 | }
|
1330 | else {
|
1331 | constructor = GraphQLInputObjectType;
|
1332 | }
|
1333 | return new constructor({
|
1334 | name: name,
|
1335 | fields: {
|
1336 | __fake: {
|
1337 | type: GraphQLString,
|
1338 | },
|
1339 | },
|
1340 | });
|
1341 | }
|
1342 | function createStub(node, type) {
|
1343 | switch (node.kind) {
|
1344 | case Kind.LIST_TYPE:
|
1345 | return new GraphQLList(createStub(node.type, type));
|
1346 | case Kind.NON_NULL_TYPE:
|
1347 | return new GraphQLNonNull(createStub(node.type, type));
|
1348 | default:
|
1349 | if (type === 'output') {
|
1350 | return createNamedStub(node.name.value, 'object');
|
1351 | }
|
1352 | return createNamedStub(node.name.value, 'input');
|
1353 | }
|
1354 | }
|
1355 | function isNamedStub(type) {
|
1356 | if (isObjectType(type) || isInterfaceType(type) || isInputObjectType(type)) {
|
1357 | var fields = type.getFields();
|
1358 | var fieldNames = Object.keys(fields);
|
1359 | return fieldNames.length === 1 && fields[fieldNames[0]].name === '__fake';
|
1360 | }
|
1361 | return false;
|
1362 | }
|
1363 | function getBuiltInForStub(type) {
|
1364 | switch (type.name) {
|
1365 | case GraphQLInt.name:
|
1366 | return GraphQLInt;
|
1367 | case GraphQLFloat.name:
|
1368 | return GraphQLFloat;
|
1369 | case GraphQLString.name:
|
1370 | return GraphQLString;
|
1371 | case GraphQLBoolean.name:
|
1372 | return GraphQLBoolean;
|
1373 | case GraphQLID.name:
|
1374 | return GraphQLID;
|
1375 | default:
|
1376 | return type;
|
1377 | }
|
1378 | }
|
1379 |
|
1380 | function rewireTypes(originalTypeMap, directives) {
|
1381 | var referenceTypeMap = Object.create(null);
|
1382 | Object.keys(originalTypeMap).forEach(function (typeName) {
|
1383 | referenceTypeMap[typeName] = originalTypeMap[typeName];
|
1384 | });
|
1385 | var newTypeMap = Object.create(null);
|
1386 | Object.keys(referenceTypeMap).forEach(function (typeName) {
|
1387 | var namedType = referenceTypeMap[typeName];
|
1388 | if (namedType == null || typeName.startsWith('__')) {
|
1389 | return;
|
1390 | }
|
1391 | var newName = namedType.name;
|
1392 | if (newName.startsWith('__')) {
|
1393 | return;
|
1394 | }
|
1395 | if (newTypeMap[newName] != null) {
|
1396 | throw new Error("Duplicate schema type name " + newName);
|
1397 | }
|
1398 | newTypeMap[newName] = namedType;
|
1399 | });
|
1400 | Object.keys(newTypeMap).forEach(function (typeName) {
|
1401 | newTypeMap[typeName] = rewireNamedType(newTypeMap[typeName]);
|
1402 | });
|
1403 | var newDirectives = directives.map(function (directive) { return rewireDirective(directive); });
|
1404 | return {
|
1405 | typeMap: newTypeMap,
|
1406 | directives: newDirectives,
|
1407 | };
|
1408 | function rewireDirective(directive) {
|
1409 | if (isSpecifiedDirective(directive)) {
|
1410 | return directive;
|
1411 | }
|
1412 | var directiveConfig = directive.toConfig();
|
1413 | directiveConfig.args = rewireArgs(directiveConfig.args);
|
1414 | return new GraphQLDirective(directiveConfig);
|
1415 | }
|
1416 | function rewireArgs(args) {
|
1417 | var rewiredArgs = {};
|
1418 | Object.keys(args).forEach(function (argName) {
|
1419 | var arg = args[argName];
|
1420 | var rewiredArgType = rewireType(arg.type);
|
1421 | if (rewiredArgType != null) {
|
1422 | arg.type = rewiredArgType;
|
1423 | rewiredArgs[argName] = arg;
|
1424 | }
|
1425 | });
|
1426 | return rewiredArgs;
|
1427 | }
|
1428 | function rewireNamedType(type) {
|
1429 | if (isObjectType(type)) {
|
1430 | var config_1 = type.toConfig();
|
1431 | var newConfig = __assign(__assign({}, config_1), { fields: function () { return rewireFields(config_1.fields); }, interfaces: function () { return rewireNamedTypes(config_1.interfaces); } });
|
1432 | return new GraphQLObjectType(newConfig);
|
1433 | }
|
1434 | else if (isInterfaceType(type)) {
|
1435 | var config_2 = type.toConfig();
|
1436 | var newConfig = __assign(__assign({}, config_2), { fields: function () { return rewireFields(config_2.fields); } });
|
1437 | if ('interfaces' in newConfig) {
|
1438 | newConfig.interfaces = function () {
|
1439 | return rewireNamedTypes(config_2.interfaces);
|
1440 | };
|
1441 | }
|
1442 | return new GraphQLInterfaceType(newConfig);
|
1443 | }
|
1444 | else if (isUnionType(type)) {
|
1445 | var config_3 = type.toConfig();
|
1446 | var newConfig = __assign(__assign({}, config_3), { types: function () { return rewireNamedTypes(config_3.types); } });
|
1447 | return new GraphQLUnionType(newConfig);
|
1448 | }
|
1449 | else if (isInputObjectType(type)) {
|
1450 | var config_4 = type.toConfig();
|
1451 | var newConfig = __assign(__assign({}, config_4), { fields: function () { return rewireInputFields(config_4.fields); } });
|
1452 | return new GraphQLInputObjectType(newConfig);
|
1453 | }
|
1454 | else if (isEnumType(type)) {
|
1455 | var enumConfig = type.toConfig();
|
1456 | return new GraphQLEnumType(enumConfig);
|
1457 | }
|
1458 | else if (isScalarType(type)) {
|
1459 | if (isSpecifiedScalarType(type)) {
|
1460 | return type;
|
1461 | }
|
1462 | var scalarConfig = type.toConfig();
|
1463 | return new GraphQLScalarType(scalarConfig);
|
1464 | }
|
1465 | throw new Error("Unexpected schema type: " + type);
|
1466 | }
|
1467 | function rewireFields(fields) {
|
1468 | var rewiredFields = {};
|
1469 | Object.keys(fields).forEach(function (fieldName) {
|
1470 | var field = fields[fieldName];
|
1471 | var rewiredFieldType = rewireType(field.type);
|
1472 | if (rewiredFieldType != null) {
|
1473 | field.type = rewiredFieldType;
|
1474 | field.args = rewireArgs(field.args);
|
1475 | rewiredFields[fieldName] = field;
|
1476 | }
|
1477 | });
|
1478 | return rewiredFields;
|
1479 | }
|
1480 | function rewireInputFields(fields) {
|
1481 | var rewiredFields = {};
|
1482 | Object.keys(fields).forEach(function (fieldName) {
|
1483 | var field = fields[fieldName];
|
1484 | var rewiredFieldType = rewireType(field.type);
|
1485 | if (rewiredFieldType != null) {
|
1486 | field.type = rewiredFieldType;
|
1487 | rewiredFields[fieldName] = field;
|
1488 | }
|
1489 | });
|
1490 | return rewiredFields;
|
1491 | }
|
1492 | function rewireNamedTypes(namedTypes) {
|
1493 | var rewiredTypes = [];
|
1494 | namedTypes.forEach(function (namedType) {
|
1495 | var rewiredType = rewireType(namedType);
|
1496 | if (rewiredType != null) {
|
1497 | rewiredTypes.push(rewiredType);
|
1498 | }
|
1499 | });
|
1500 | return rewiredTypes;
|
1501 | }
|
1502 | function rewireType(type) {
|
1503 | if (isListType(type)) {
|
1504 | var rewiredType = rewireType(type.ofType);
|
1505 | return rewiredType != null ? new GraphQLList(rewiredType) : null;
|
1506 | }
|
1507 | else if (isNonNullType(type)) {
|
1508 | var rewiredType = rewireType(type.ofType);
|
1509 | return rewiredType != null ? new GraphQLNonNull(rewiredType) : null;
|
1510 | }
|
1511 | else if (isNamedType(type)) {
|
1512 | var rewiredType = referenceTypeMap[type.name];
|
1513 | if (rewiredType === undefined) {
|
1514 | rewiredType = isNamedStub(type) ? getBuiltInForStub(type) : rewireNamedType(type);
|
1515 | newTypeMap[rewiredType.name] = referenceTypeMap[type.name] = rewiredType;
|
1516 | }
|
1517 | return rewiredType != null ? newTypeMap[rewiredType.name] : null;
|
1518 | }
|
1519 | return null;
|
1520 | }
|
1521 | }
|
1522 |
|
1523 | function transformInputValue(type, value, transformer) {
|
1524 | if (value == null) {
|
1525 | return value;
|
1526 | }
|
1527 | var nullableType = getNullableType(type);
|
1528 | if (isLeafType(nullableType)) {
|
1529 | return transformer(nullableType, value);
|
1530 | }
|
1531 | else if (isListType(nullableType)) {
|
1532 | return value.map(function (listMember) { return transformInputValue(nullableType.ofType, listMember, transformer); });
|
1533 | }
|
1534 | else if (isInputObjectType(nullableType)) {
|
1535 | var fields_1 = nullableType.getFields();
|
1536 | var newValue_1 = {};
|
1537 | Object.keys(value).forEach(function (key) {
|
1538 | newValue_1[key] = transformInputValue(fields_1[key].type, value[key], transformer);
|
1539 | });
|
1540 | return newValue_1;
|
1541 | }
|
1542 |
|
1543 | }
|
1544 | function serializeInputValue(type, value) {
|
1545 | return transformInputValue(type, value, function (t, v) { return t.serialize(v); });
|
1546 | }
|
1547 | function parseInputValue(type, value) {
|
1548 | return transformInputValue(type, value, function (t, v) { return t.parseValue(v); });
|
1549 | }
|
1550 | function parseInputValueLiteral(type, value) {
|
1551 | return transformInputValue(type, value, function (t, v) { return t.parseLiteral(v, {}); });
|
1552 | }
|
1553 |
|
1554 | function mapSchema(schema, schemaMapper) {
|
1555 | if (schemaMapper === void 0) { schemaMapper = {}; }
|
1556 | var originalTypeMap = schema.getTypeMap();
|
1557 | var newTypeMap = mapDefaultValues(originalTypeMap, schema, serializeInputValue);
|
1558 | newTypeMap = mapTypes(newTypeMap, schema, schemaMapper, function (type) { return isLeafType(type); });
|
1559 | newTypeMap = mapEnumValues(newTypeMap, schema, schemaMapper);
|
1560 | newTypeMap = mapDefaultValues(newTypeMap, schema, parseInputValue);
|
1561 | newTypeMap = mapTypes(newTypeMap, schema, schemaMapper, function (type) { return !isLeafType(type); });
|
1562 | newTypeMap = mapFields(newTypeMap, schema, schemaMapper);
|
1563 | newTypeMap = mapArguments(newTypeMap, schema, schemaMapper);
|
1564 | var originalDirectives = schema.getDirectives();
|
1565 | var newDirectives = mapDirectives(originalDirectives, schema, schemaMapper);
|
1566 | var queryType = schema.getQueryType();
|
1567 | var mutationType = schema.getMutationType();
|
1568 | var subscriptionType = schema.getSubscriptionType();
|
1569 | var newQueryTypeName = queryType != null ? (newTypeMap[queryType.name] != null ? newTypeMap[queryType.name].name : undefined) : undefined;
|
1570 | var newMutationTypeName = mutationType != null
|
1571 | ? newTypeMap[mutationType.name] != null
|
1572 | ? newTypeMap[mutationType.name].name
|
1573 | : undefined
|
1574 | : undefined;
|
1575 | var newSubscriptionTypeName = subscriptionType != null
|
1576 | ? newTypeMap[subscriptionType.name] != null
|
1577 | ? newTypeMap[subscriptionType.name].name
|
1578 | : undefined
|
1579 | : undefined;
|
1580 | var _a = rewireTypes(newTypeMap, newDirectives), typeMap = _a.typeMap, directives = _a.directives;
|
1581 | return new GraphQLSchema(__assign(__assign({}, schema.toConfig()), { query: newQueryTypeName ? typeMap[newQueryTypeName] : undefined, mutation: newMutationTypeName ? typeMap[newMutationTypeName] : undefined, subscription: newSubscriptionTypeName != null ? typeMap[newSubscriptionTypeName] : undefined, types: Object.keys(typeMap).map(function (typeName) { return typeMap[typeName]; }), directives: directives }));
|
1582 | }
|
1583 | function mapTypes(originalTypeMap, schema, schemaMapper, testFn) {
|
1584 | if (testFn === void 0) { testFn = function () { return true; }; }
|
1585 | var newTypeMap = {};
|
1586 | Object.keys(originalTypeMap).forEach(function (typeName) {
|
1587 | if (!typeName.startsWith('__')) {
|
1588 | var originalType = originalTypeMap[typeName];
|
1589 | if (originalType == null || !testFn(originalType)) {
|
1590 | newTypeMap[typeName] = originalType;
|
1591 | return;
|
1592 | }
|
1593 | var typeMapper = getTypeMapper(schema, schemaMapper, typeName);
|
1594 | if (typeMapper == null) {
|
1595 | newTypeMap[typeName] = originalType;
|
1596 | return;
|
1597 | }
|
1598 | var maybeNewType = typeMapper(originalType, schema);
|
1599 | if (maybeNewType === undefined) {
|
1600 | newTypeMap[typeName] = originalType;
|
1601 | return;
|
1602 | }
|
1603 | newTypeMap[typeName] = maybeNewType;
|
1604 | }
|
1605 | });
|
1606 | return newTypeMap;
|
1607 | }
|
1608 | function mapEnumValues(originalTypeMap, schema, schemaMapper) {
|
1609 | var _a;
|
1610 | var enumValueMapper = getEnumValueMapper(schemaMapper);
|
1611 | if (!enumValueMapper) {
|
1612 | return originalTypeMap;
|
1613 | }
|
1614 | return mapTypes(originalTypeMap, schema, (_a = {},
|
1615 | _a[MapperKind.ENUM_TYPE] = function (type) {
|
1616 | var config = type.toConfig();
|
1617 | var originalEnumValueConfigMap = config.values;
|
1618 | var newEnumValueConfigMap = {};
|
1619 | Object.keys(originalEnumValueConfigMap).forEach(function (externalValue) {
|
1620 | var originalEnumValueConfig = originalEnumValueConfigMap[externalValue];
|
1621 | var mappedEnumValue = enumValueMapper(originalEnumValueConfig, type.name, schema, externalValue);
|
1622 | if (mappedEnumValue === undefined) {
|
1623 | newEnumValueConfigMap[externalValue] = originalEnumValueConfig;
|
1624 | }
|
1625 | else if (Array.isArray(mappedEnumValue)) {
|
1626 | var _a = __read(mappedEnumValue, 2), newExternalValue = _a[0], newEnumValueConfig = _a[1];
|
1627 | newEnumValueConfigMap[newExternalValue] =
|
1628 | newEnumValueConfig === undefined ? originalEnumValueConfig : newEnumValueConfig;
|
1629 | }
|
1630 | else if (mappedEnumValue !== null) {
|
1631 | newEnumValueConfigMap[externalValue] = mappedEnumValue;
|
1632 | }
|
1633 | });
|
1634 | return correctASTNodes(new GraphQLEnumType(__assign(__assign({}, config), { values: newEnumValueConfigMap })));
|
1635 | },
|
1636 | _a), function (type) { return isEnumType(type); });
|
1637 | }
|
1638 | function mapDefaultValues(originalTypeMap, schema, fn) {
|
1639 | var _a, _b;
|
1640 | var newTypeMap = mapArguments(originalTypeMap, schema, (_a = {},
|
1641 | _a[MapperKind.ARGUMENT] = function (argumentConfig) {
|
1642 | if (argumentConfig.defaultValue === undefined) {
|
1643 | return argumentConfig;
|
1644 | }
|
1645 | var maybeNewType = getNewType(originalTypeMap, argumentConfig.type);
|
1646 | if (maybeNewType != null) {
|
1647 | return __assign(__assign({}, argumentConfig), { defaultValue: fn(maybeNewType, argumentConfig.defaultValue) });
|
1648 | }
|
1649 | },
|
1650 | _a));
|
1651 | return mapFields(newTypeMap, schema, (_b = {},
|
1652 | _b[MapperKind.INPUT_OBJECT_FIELD] = function (inputFieldConfig) {
|
1653 | if (inputFieldConfig.defaultValue === undefined) {
|
1654 | return inputFieldConfig;
|
1655 | }
|
1656 | var maybeNewType = getNewType(newTypeMap, inputFieldConfig.type);
|
1657 | if (maybeNewType != null) {
|
1658 | return __assign(__assign({}, inputFieldConfig), { defaultValue: fn(maybeNewType, inputFieldConfig.defaultValue) });
|
1659 | }
|
1660 | },
|
1661 | _b));
|
1662 | }
|
1663 | function getNewType(newTypeMap, type) {
|
1664 | if (isListType(type)) {
|
1665 | var newType = getNewType(newTypeMap, type.ofType);
|
1666 | return newType != null ? new GraphQLList(newType) : null;
|
1667 | }
|
1668 | else if (isNonNullType(type)) {
|
1669 | var newType = getNewType(newTypeMap, type.ofType);
|
1670 | return newType != null ? new GraphQLNonNull(newType) : null;
|
1671 | }
|
1672 | else if (isNamedType(type)) {
|
1673 | var newType = newTypeMap[type.name];
|
1674 | return newType != null ? newType : null;
|
1675 | }
|
1676 | return null;
|
1677 | }
|
1678 | function mapFields(originalTypeMap, schema, schemaMapper) {
|
1679 | var newTypeMap = {};
|
1680 | Object.keys(originalTypeMap).forEach(function (typeName) {
|
1681 | if (!typeName.startsWith('__')) {
|
1682 | var originalType = originalTypeMap[typeName];
|
1683 | if (!isObjectType(originalType) && !isInterfaceType(originalType) && !isInputObjectType(originalType)) {
|
1684 | newTypeMap[typeName] = originalType;
|
1685 | return;
|
1686 | }
|
1687 | var fieldMapper_1 = getFieldMapper(schema, schemaMapper, typeName);
|
1688 | if (fieldMapper_1 == null) {
|
1689 | newTypeMap[typeName] = originalType;
|
1690 | return;
|
1691 | }
|
1692 | var config = originalType.toConfig();
|
1693 | var originalFieldConfigMap_1 = config.fields;
|
1694 | var newFieldConfigMap_1 = {};
|
1695 | Object.keys(originalFieldConfigMap_1).forEach(function (fieldName) {
|
1696 | var originalFieldConfig = originalFieldConfigMap_1[fieldName];
|
1697 | var mappedField = fieldMapper_1(originalFieldConfig, fieldName, typeName, schema);
|
1698 | if (mappedField === undefined) {
|
1699 | newFieldConfigMap_1[fieldName] = originalFieldConfig;
|
1700 | }
|
1701 | else if (Array.isArray(mappedField)) {
|
1702 | var _a = __read(mappedField, 2), newFieldName = _a[0], newFieldConfig = _a[1];
|
1703 | if (newFieldConfig.astNode != null) {
|
1704 | newFieldConfig.astNode = __assign(__assign({}, newFieldConfig.astNode), { name: __assign(__assign({}, newFieldConfig.astNode.name), { value: newFieldName }) });
|
1705 | }
|
1706 | newFieldConfigMap_1[newFieldName] = newFieldConfig === undefined ? originalFieldConfig : newFieldConfig;
|
1707 | }
|
1708 | else if (mappedField !== null) {
|
1709 | newFieldConfigMap_1[fieldName] = mappedField;
|
1710 | }
|
1711 | });
|
1712 | if (isObjectType(originalType)) {
|
1713 | newTypeMap[typeName] = correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_1 })));
|
1714 | }
|
1715 | else if (isInterfaceType(originalType)) {
|
1716 | newTypeMap[typeName] = correctASTNodes(new GraphQLInterfaceType(__assign(__assign({}, config), { fields: newFieldConfigMap_1 })));
|
1717 | }
|
1718 | else {
|
1719 | newTypeMap[typeName] = correctASTNodes(new GraphQLInputObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_1 })));
|
1720 | }
|
1721 | }
|
1722 | });
|
1723 | return newTypeMap;
|
1724 | }
|
1725 | function mapArguments(originalTypeMap, schema, schemaMapper) {
|
1726 | var newTypeMap = {};
|
1727 | Object.keys(originalTypeMap).forEach(function (typeName) {
|
1728 | if (!typeName.startsWith('__')) {
|
1729 | var originalType = originalTypeMap[typeName];
|
1730 | if (!isObjectType(originalType) && !isInterfaceType(originalType)) {
|
1731 | newTypeMap[typeName] = originalType;
|
1732 | return;
|
1733 | }
|
1734 | var argumentMapper_1 = getArgumentMapper(schemaMapper);
|
1735 | if (argumentMapper_1 == null) {
|
1736 | newTypeMap[typeName] = originalType;
|
1737 | return;
|
1738 | }
|
1739 | var config = originalType.toConfig();
|
1740 | var originalFieldConfigMap_2 = config.fields;
|
1741 | var newFieldConfigMap_2 = {};
|
1742 | Object.keys(originalFieldConfigMap_2).forEach(function (fieldName) {
|
1743 | var originalFieldConfig = originalFieldConfigMap_2[fieldName];
|
1744 | var originalArgumentConfigMap = originalFieldConfig.args;
|
1745 | if (originalArgumentConfigMap == null) {
|
1746 | newFieldConfigMap_2[fieldName] = originalFieldConfig;
|
1747 | return;
|
1748 | }
|
1749 | var argumentNames = Object.keys(originalArgumentConfigMap);
|
1750 | if (!argumentNames.length) {
|
1751 | newFieldConfigMap_2[fieldName] = originalFieldConfig;
|
1752 | return;
|
1753 | }
|
1754 | var newArgumentConfigMap = {};
|
1755 | argumentNames.forEach(function (argumentName) {
|
1756 | var originalArgumentConfig = originalArgumentConfigMap[argumentName];
|
1757 | var mappedArgument = argumentMapper_1(originalArgumentConfig, fieldName, typeName, schema);
|
1758 | if (mappedArgument === undefined) {
|
1759 | newArgumentConfigMap[argumentName] = originalArgumentConfig;
|
1760 | }
|
1761 | else if (Array.isArray(mappedArgument)) {
|
1762 | var _a = __read(mappedArgument, 2), newArgumentName = _a[0], newArgumentConfig = _a[1];
|
1763 | newArgumentConfigMap[newArgumentName] = newArgumentConfig;
|
1764 | }
|
1765 | else if (mappedArgument !== null) {
|
1766 | newArgumentConfigMap[argumentName] = mappedArgument;
|
1767 | }
|
1768 | });
|
1769 | newFieldConfigMap_2[fieldName] = __assign(__assign({}, originalFieldConfig), { args: newArgumentConfigMap });
|
1770 | });
|
1771 | if (isObjectType(originalType)) {
|
1772 | newTypeMap[typeName] = new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_2 }));
|
1773 | }
|
1774 | else if (isInterfaceType(originalType)) {
|
1775 | newTypeMap[typeName] = new GraphQLInterfaceType(__assign(__assign({}, config), { fields: newFieldConfigMap_2 }));
|
1776 | }
|
1777 | else {
|
1778 | newTypeMap[typeName] = new GraphQLInputObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_2 }));
|
1779 | }
|
1780 | }
|
1781 | });
|
1782 | return newTypeMap;
|
1783 | }
|
1784 | function mapDirectives(originalDirectives, schema, schemaMapper) {
|
1785 | var directiveMapper = getDirectiveMapper(schemaMapper);
|
1786 | if (directiveMapper == null) {
|
1787 | return originalDirectives.slice();
|
1788 | }
|
1789 | var newDirectives = [];
|
1790 | originalDirectives.forEach(function (directive) {
|
1791 | var mappedDirective = directiveMapper(directive, schema);
|
1792 | if (mappedDirective === undefined) {
|
1793 | newDirectives.push(directive);
|
1794 | }
|
1795 | else if (mappedDirective !== null) {
|
1796 | newDirectives.push(mappedDirective);
|
1797 | }
|
1798 | });
|
1799 | return newDirectives;
|
1800 | }
|
1801 | function getTypeSpecifiers(schema, typeName) {
|
1802 | var type = schema.getType(typeName);
|
1803 | var specifiers = [MapperKind.TYPE];
|
1804 | if (isObjectType(type)) {
|
1805 | specifiers.push(MapperKind.COMPOSITE_TYPE, MapperKind.OBJECT_TYPE);
|
1806 | var query = schema.getQueryType();
|
1807 | var mutation = schema.getMutationType();
|
1808 | var subscription = schema.getSubscriptionType();
|
1809 | if (query != null && typeName === query.name) {
|
1810 | specifiers.push(MapperKind.ROOT_OBJECT, MapperKind.QUERY);
|
1811 | }
|
1812 | else if (mutation != null && typeName === mutation.name) {
|
1813 | specifiers.push(MapperKind.ROOT_OBJECT, MapperKind.MUTATION);
|
1814 | }
|
1815 | else if (subscription != null && typeName === subscription.name) {
|
1816 | specifiers.push(MapperKind.ROOT_OBJECT, MapperKind.SUBSCRIPTION);
|
1817 | }
|
1818 | }
|
1819 | else if (isInputObjectType(type)) {
|
1820 | specifiers.push(MapperKind.INPUT_OBJECT_TYPE);
|
1821 | }
|
1822 | else if (isInterfaceType(type)) {
|
1823 | specifiers.push(MapperKind.COMPOSITE_TYPE, MapperKind.ABSTRACT_TYPE, MapperKind.INTERFACE_TYPE);
|
1824 | }
|
1825 | else if (isUnionType(type)) {
|
1826 | specifiers.push(MapperKind.COMPOSITE_TYPE, MapperKind.ABSTRACT_TYPE, MapperKind.UNION_TYPE);
|
1827 | }
|
1828 | else if (isEnumType(type)) {
|
1829 | specifiers.push(MapperKind.ENUM_TYPE);
|
1830 | }
|
1831 | else if (isScalarType(type)) {
|
1832 | specifiers.push(MapperKind.SCALAR_TYPE);
|
1833 | }
|
1834 | return specifiers;
|
1835 | }
|
1836 | function getTypeMapper(schema, schemaMapper, typeName) {
|
1837 | var specifiers = getTypeSpecifiers(schema, typeName);
|
1838 | var typeMapper;
|
1839 | var stack = __spread(specifiers);
|
1840 | while (!typeMapper && stack.length > 0) {
|
1841 | var next = stack.pop();
|
1842 | typeMapper = schemaMapper[next];
|
1843 | }
|
1844 | return typeMapper != null ? typeMapper : null;
|
1845 | }
|
1846 | function getFieldSpecifiers(schema, typeName) {
|
1847 | var type = schema.getType(typeName);
|
1848 | var specifiers = [MapperKind.FIELD];
|
1849 | if (isObjectType(type)) {
|
1850 | specifiers.push(MapperKind.COMPOSITE_FIELD, MapperKind.OBJECT_FIELD);
|
1851 | var query = schema.getQueryType();
|
1852 | var mutation = schema.getMutationType();
|
1853 | var subscription = schema.getSubscriptionType();
|
1854 | if (query != null && typeName === query.name) {
|
1855 | specifiers.push(MapperKind.ROOT_FIELD, MapperKind.QUERY_ROOT_FIELD);
|
1856 | }
|
1857 | else if (mutation != null && typeName === mutation.name) {
|
1858 | specifiers.push(MapperKind.ROOT_FIELD, MapperKind.MUTATION_ROOT_FIELD);
|
1859 | }
|
1860 | else if (subscription != null && typeName === subscription.name) {
|
1861 | specifiers.push(MapperKind.ROOT_FIELD, MapperKind.SUBSCRIPTION_ROOT_FIELD);
|
1862 | }
|
1863 | }
|
1864 | else if (isInterfaceType(type)) {
|
1865 | specifiers.push(MapperKind.COMPOSITE_FIELD, MapperKind.INTERFACE_FIELD);
|
1866 | }
|
1867 | else if (isInputObjectType(type)) {
|
1868 | specifiers.push(MapperKind.INPUT_OBJECT_FIELD);
|
1869 | }
|
1870 | return specifiers;
|
1871 | }
|
1872 | function getFieldMapper(schema, schemaMapper, typeName) {
|
1873 | var specifiers = getFieldSpecifiers(schema, typeName);
|
1874 | var fieldMapper;
|
1875 | var stack = __spread(specifiers);
|
1876 | while (!fieldMapper && stack.length > 0) {
|
1877 | var next = stack.pop();
|
1878 | fieldMapper = schemaMapper[next];
|
1879 | }
|
1880 | return fieldMapper != null ? fieldMapper : null;
|
1881 | }
|
1882 | function getArgumentMapper(schemaMapper) {
|
1883 | var argumentMapper = schemaMapper[MapperKind.ARGUMENT];
|
1884 | return argumentMapper != null ? argumentMapper : null;
|
1885 | }
|
1886 | function getDirectiveMapper(schemaMapper) {
|
1887 | var directiveMapper = schemaMapper[MapperKind.DIRECTIVE];
|
1888 | return directiveMapper != null ? directiveMapper : null;
|
1889 | }
|
1890 | function getEnumValueMapper(schemaMapper) {
|
1891 | var enumValueMapper = schemaMapper[MapperKind.ENUM_VALUE];
|
1892 | return enumValueMapper != null ? enumValueMapper : null;
|
1893 | }
|
1894 | function correctASTNodes(type) {
|
1895 | if (isObjectType(type)) {
|
1896 | var config = type.toConfig();
|
1897 | if (config.astNode != null) {
|
1898 | var fields_1 = [];
|
1899 | Object.values(config.fields).forEach(function (fieldConfig) {
|
1900 | if (fieldConfig.astNode != null) {
|
1901 | fields_1.push(fieldConfig.astNode);
|
1902 | }
|
1903 | });
|
1904 | config.astNode = __assign(__assign({}, config.astNode), { kind: Kind.OBJECT_TYPE_DEFINITION, fields: fields_1 });
|
1905 | }
|
1906 | if (config.extensionASTNodes != null) {
|
1907 | config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { kind: Kind.OBJECT_TYPE_EXTENSION, fields: undefined })); });
|
1908 | }
|
1909 | return new GraphQLObjectType(config);
|
1910 | }
|
1911 | else if (isInterfaceType(type)) {
|
1912 | var config = type.toConfig();
|
1913 | if (config.astNode != null) {
|
1914 | var fields_2 = [];
|
1915 | Object.values(config.fields).forEach(function (fieldConfig) {
|
1916 | if (fieldConfig.astNode != null) {
|
1917 | fields_2.push(fieldConfig.astNode);
|
1918 | }
|
1919 | });
|
1920 | config.astNode = __assign(__assign({}, config.astNode), { kind: Kind.INTERFACE_TYPE_DEFINITION, fields: fields_2 });
|
1921 | }
|
1922 | if (config.extensionASTNodes != null) {
|
1923 | config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { kind: Kind.INTERFACE_TYPE_EXTENSION, fields: undefined })); });
|
1924 | }
|
1925 | return new GraphQLInterfaceType(config);
|
1926 | }
|
1927 | else if (isInputObjectType(type)) {
|
1928 | var config = type.toConfig();
|
1929 | if (config.astNode != null) {
|
1930 | var fields_3 = [];
|
1931 | Object.values(config.fields).forEach(function (fieldConfig) {
|
1932 | if (fieldConfig.astNode != null) {
|
1933 | fields_3.push(fieldConfig.astNode);
|
1934 | }
|
1935 | });
|
1936 | config.astNode = __assign(__assign({}, config.astNode), { kind: Kind.INPUT_OBJECT_TYPE_DEFINITION, fields: fields_3 });
|
1937 | }
|
1938 | if (config.extensionASTNodes != null) {
|
1939 | config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { kind: Kind.INPUT_OBJECT_TYPE_EXTENSION, fields: undefined })); });
|
1940 | }
|
1941 | return new GraphQLInputObjectType(config);
|
1942 | }
|
1943 | else if (isEnumType(type)) {
|
1944 | var config = type.toConfig();
|
1945 | if (config.astNode != null) {
|
1946 | var values_1 = [];
|
1947 | Object.values(config.values).forEach(function (enumValueConfig) {
|
1948 | if (enumValueConfig.astNode != null) {
|
1949 | values_1.push(enumValueConfig.astNode);
|
1950 | }
|
1951 | });
|
1952 | config.astNode = __assign(__assign({}, config.astNode), { values: values_1 });
|
1953 | }
|
1954 | if (config.extensionASTNodes != null) {
|
1955 | config.extensionASTNodes = config.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { values: undefined })); });
|
1956 | }
|
1957 | return new GraphQLEnumType(config);
|
1958 | }
|
1959 | else {
|
1960 | return type;
|
1961 | }
|
1962 | }
|
1963 |
|
1964 | function filterSchema(_a) {
|
1965 | var _b;
|
1966 | var schema = _a.schema, _c = _a.typeFilter, typeFilter = _c === void 0 ? function () { return true; } : _c, _d = _a.fieldFilter, fieldFilter = _d === void 0 ? undefined : _d, _e = _a.rootFieldFilter, rootFieldFilter = _e === void 0 ? undefined : _e, _f = _a.objectFieldFilter, objectFieldFilter = _f === void 0 ? undefined : _f, _g = _a.interfaceFieldFilter, interfaceFieldFilter = _g === void 0 ? undefined : _g, _h = _a.inputObjectFieldFilter, inputObjectFieldFilter = _h === void 0 ? undefined : _h, _j = _a.argumentFilter, argumentFilter = _j === void 0 ? undefined : _j;
|
1967 | var filteredSchema = mapSchema(schema, (_b = {},
|
1968 | _b[MapperKind.QUERY] = function (type) { return filterRootFields(type, 'Query', rootFieldFilter); },
|
1969 | _b[MapperKind.MUTATION] = function (type) { return filterRootFields(type, 'Mutation', rootFieldFilter); },
|
1970 | _b[MapperKind.SUBSCRIPTION] = function (type) { return filterRootFields(type, 'Subscription', rootFieldFilter); },
|
1971 | _b[MapperKind.OBJECT_TYPE] = function (type) {
|
1972 | return typeFilter(type.name, type)
|
1973 | ? filterElementFields(GraphQLObjectType, type, objectFieldFilter || fieldFilter, argumentFilter)
|
1974 | : null;
|
1975 | },
|
1976 | _b[MapperKind.INTERFACE_TYPE] = function (type) {
|
1977 | return typeFilter(type.name, type)
|
1978 | ? filterElementFields(GraphQLInterfaceType, type, interfaceFieldFilter || fieldFilter, argumentFilter)
|
1979 | : null;
|
1980 | },
|
1981 | _b[MapperKind.INPUT_OBJECT_TYPE] = function (type) {
|
1982 | return typeFilter(type.name, type)
|
1983 | ? filterElementFields(GraphQLInputObjectType, type, inputObjectFieldFilter || fieldFilter)
|
1984 | : null;
|
1985 | },
|
1986 | _b[MapperKind.UNION_TYPE] = function (type) { return (typeFilter(type.name, type) ? undefined : null); },
|
1987 | _b[MapperKind.ENUM_TYPE] = function (type) { return (typeFilter(type.name, type) ? undefined : null); },
|
1988 | _b[MapperKind.SCALAR_TYPE] = function (type) { return (typeFilter(type.name, type) ? undefined : null); },
|
1989 | _b));
|
1990 | return filteredSchema;
|
1991 | }
|
1992 | function filterRootFields(type, operation, rootFieldFilter) {
|
1993 | if (rootFieldFilter) {
|
1994 | var config_1 = type.toConfig();
|
1995 | Object.keys(config_1.fields).forEach(function (fieldName) {
|
1996 | if (!rootFieldFilter(operation, fieldName, config_1.fields[fieldName])) {
|
1997 | delete config_1.fields[fieldName];
|
1998 | }
|
1999 | });
|
2000 | return new GraphQLObjectType(config_1);
|
2001 | }
|
2002 | return type;
|
2003 | }
|
2004 | function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilter) {
|
2005 | var e_1, _a, e_2, _b;
|
2006 | if (fieldFilter || argumentFilter) {
|
2007 | if (!fieldFilter)
|
2008 | fieldFilter = function () { return true; };
|
2009 | var config = type.toConfig();
|
2010 | try {
|
2011 | for (var _c = __values(Object.entries(config.fields)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
2012 | var _e = __read(_d.value, 2), fieldName = _e[0], field = _e[1];
|
2013 | if (!fieldFilter(type.name, fieldName, config.fields[fieldName])) {
|
2014 | delete config.fields[fieldName];
|
2015 | }
|
2016 | else if (argumentFilter && 'args' in field) {
|
2017 | try {
|
2018 | for (var _f = (e_2 = void 0, __values(Object.keys(field.args))), _g = _f.next(); !_g.done; _g = _f.next()) {
|
2019 | var argName = _g.value;
|
2020 | if (!argumentFilter(type.name, fieldName, argName, field.args[argName])) {
|
2021 | delete field.args[argName];
|
2022 | }
|
2023 | }
|
2024 | }
|
2025 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
2026 | finally {
|
2027 | try {
|
2028 | if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
2029 | }
|
2030 | finally { if (e_2) throw e_2.error; }
|
2031 | }
|
2032 | }
|
2033 | }
|
2034 | }
|
2035 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
2036 | finally {
|
2037 | try {
|
2038 | if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
2039 | }
|
2040 | finally { if (e_1) throw e_1.error; }
|
2041 | }
|
2042 | return new ElementConstructor(config);
|
2043 | }
|
2044 | }
|
2045 |
|
2046 | function cloneDirective(directive) {
|
2047 | return isSpecifiedDirective(directive) ? directive : new GraphQLDirective(directive.toConfig());
|
2048 | }
|
2049 | function cloneType(type) {
|
2050 | if (isObjectType(type)) {
|
2051 | var config = type.toConfig();
|
2052 | return new GraphQLObjectType(__assign(__assign({}, config), { interfaces: typeof config.interfaces === 'function' ? config.interfaces : config.interfaces.slice() }));
|
2053 | }
|
2054 | else if (isInterfaceType(type)) {
|
2055 | var config = type.toConfig();
|
2056 | var newConfig = __assign(__assign({}, config), { interfaces: __spread(((typeof config.interfaces === 'function' ? config.interfaces() : config.interfaces) || [])) });
|
2057 | return new GraphQLInterfaceType(newConfig);
|
2058 | }
|
2059 | else if (isUnionType(type)) {
|
2060 | var config = type.toConfig();
|
2061 | return new GraphQLUnionType(__assign(__assign({}, config), { types: config.types.slice() }));
|
2062 | }
|
2063 | else if (isInputObjectType(type)) {
|
2064 | return new GraphQLInputObjectType(type.toConfig());
|
2065 | }
|
2066 | else if (isEnumType(type)) {
|
2067 | return new GraphQLEnumType(type.toConfig());
|
2068 | }
|
2069 | else if (isScalarType(type)) {
|
2070 | return isSpecifiedScalarType(type) ? type : new GraphQLScalarType(type.toConfig());
|
2071 | }
|
2072 | throw new Error("Invalid type " + type);
|
2073 | }
|
2074 | function cloneSchema(schema) {
|
2075 | return mapSchema(schema);
|
2076 | }
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 | function healSchema(schema) {
|
2107 | healTypes(schema.getTypeMap(), schema.getDirectives());
|
2108 | return schema;
|
2109 | }
|
2110 | function healTypes(originalTypeMap, directives) {
|
2111 | var e_1, _a;
|
2112 | var actualNamedTypeMap = Object.create(null);
|
2113 |
|
2114 |
|
2115 |
|
2116 | Object.entries(originalTypeMap).forEach(function (_a) {
|
2117 | var _b = __read(_a, 2), typeName = _b[0], namedType = _b[1];
|
2118 | if (namedType == null || typeName.startsWith('__')) {
|
2119 | return;
|
2120 | }
|
2121 | var actualName = namedType.name;
|
2122 | if (actualName.startsWith('__')) {
|
2123 | return;
|
2124 | }
|
2125 | if (actualName in actualNamedTypeMap) {
|
2126 | throw new Error("Duplicate schema type name " + actualName);
|
2127 | }
|
2128 | actualNamedTypeMap[actualName] = namedType;
|
2129 |
|
2130 |
|
2131 |
|
2132 | });
|
2133 |
|
2134 | Object.entries(actualNamedTypeMap).forEach(function (_a) {
|
2135 | var _b = __read(_a, 2), typeName = _b[0], namedType = _b[1];
|
2136 | originalTypeMap[typeName] = namedType;
|
2137 | });
|
2138 |
|
2139 | directives.forEach(function (decl) {
|
2140 | decl.args = decl.args.filter(function (arg) {
|
2141 | arg.type = healType(arg.type);
|
2142 | return arg.type !== null;
|
2143 | });
|
2144 | });
|
2145 | Object.entries(originalTypeMap).forEach(function (_a) {
|
2146 | var _b = __read(_a, 2), typeName = _b[0], namedType = _b[1];
|
2147 |
|
2148 | if (!typeName.startsWith('__') && typeName in actualNamedTypeMap) {
|
2149 | if (namedType != null) {
|
2150 | healNamedType(namedType);
|
2151 | }
|
2152 | }
|
2153 | });
|
2154 | try {
|
2155 | for (var _b = __values(Object.keys(originalTypeMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
2156 | var typeName = _c.value;
|
2157 | if (!typeName.startsWith('__') && !(typeName in actualNamedTypeMap)) {
|
2158 | delete originalTypeMap[typeName];
|
2159 | }
|
2160 | }
|
2161 | }
|
2162 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
2163 | finally {
|
2164 | try {
|
2165 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
2166 | }
|
2167 | finally { if (e_1) throw e_1.error; }
|
2168 | }
|
2169 | function healNamedType(type) {
|
2170 | if (isObjectType(type)) {
|
2171 | healFields(type);
|
2172 | healInterfaces(type);
|
2173 | return;
|
2174 | }
|
2175 | else if (isInterfaceType(type)) {
|
2176 | healFields(type);
|
2177 | if ('getInterfaces' in type) {
|
2178 | healInterfaces(type);
|
2179 | }
|
2180 | return;
|
2181 | }
|
2182 | else if (isUnionType(type)) {
|
2183 | healUnderlyingTypes(type);
|
2184 | return;
|
2185 | }
|
2186 | else if (isInputObjectType(type)) {
|
2187 | healInputFields(type);
|
2188 | return;
|
2189 | }
|
2190 | else if (isLeafType(type)) {
|
2191 | return;
|
2192 | }
|
2193 | throw new Error("Unexpected schema type: " + type);
|
2194 | }
|
2195 | function healFields(type) {
|
2196 | var e_2, _a;
|
2197 | var fieldMap = type.getFields();
|
2198 | try {
|
2199 | for (var _b = __values(Object.entries(fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
2200 | var _d = __read(_c.value, 2), key = _d[0], field = _d[1];
|
2201 | field.args
|
2202 | .map(function (arg) {
|
2203 | arg.type = healType(arg.type);
|
2204 | return arg.type === null ? null : arg;
|
2205 | })
|
2206 | .filter(Boolean);
|
2207 | field.type = healType(field.type);
|
2208 | if (field.type === null) {
|
2209 | delete fieldMap[key];
|
2210 | }
|
2211 | }
|
2212 | }
|
2213 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
2214 | finally {
|
2215 | try {
|
2216 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
2217 | }
|
2218 | finally { if (e_2) throw e_2.error; }
|
2219 | }
|
2220 | }
|
2221 | function healInterfaces(type) {
|
2222 | if ('getInterfaces' in type) {
|
2223 | var interfaces = type.getInterfaces();
|
2224 | interfaces.push.apply(interfaces, __spread(interfaces
|
2225 | .splice(0)
|
2226 | .map(function (iface) { return healType(iface); })
|
2227 | .filter(Boolean)));
|
2228 | }
|
2229 | }
|
2230 | function healInputFields(type) {
|
2231 | var e_3, _a;
|
2232 | var fieldMap = type.getFields();
|
2233 | try {
|
2234 | for (var _b = __values(Object.entries(fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
2235 | var _d = __read(_c.value, 2), key = _d[0], field = _d[1];
|
2236 | field.type = healType(field.type);
|
2237 | if (field.type === null) {
|
2238 | delete fieldMap[key];
|
2239 | }
|
2240 | }
|
2241 | }
|
2242 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
2243 | finally {
|
2244 | try {
|
2245 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
2246 | }
|
2247 | finally { if (e_3) throw e_3.error; }
|
2248 | }
|
2249 | }
|
2250 | function healUnderlyingTypes(type) {
|
2251 | var types = type.getTypes();
|
2252 | types.push.apply(types, __spread(types
|
2253 | .splice(0)
|
2254 | .map(function (t) { return healType(t); })
|
2255 | .filter(Boolean)));
|
2256 | }
|
2257 | function healType(type) {
|
2258 |
|
2259 | if (isListType(type)) {
|
2260 | var healedType = healType(type.ofType);
|
2261 | return healedType != null ? new GraphQLList(healedType) : null;
|
2262 | }
|
2263 | else if (isNonNullType(type)) {
|
2264 | var healedType = healType(type.ofType);
|
2265 | return healedType != null ? new GraphQLNonNull(healedType) : null;
|
2266 | }
|
2267 | else if (isNamedType(type)) {
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 | var officialType = originalTypeMap[type.name];
|
2275 | if (officialType && type !== officialType) {
|
2276 | return officialType;
|
2277 | }
|
2278 | }
|
2279 | return type;
|
2280 | }
|
2281 | }
|
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 | var SchemaVisitor = (function () {
|
2288 | function SchemaVisitor() {
|
2289 | }
|
2290 |
|
2291 |
|
2292 | SchemaVisitor.implementsVisitorMethod = function (methodName) {
|
2293 | if (!methodName.startsWith('visit')) {
|
2294 | return false;
|
2295 | }
|
2296 | var method = this.prototype[methodName];
|
2297 | if (typeof method !== 'function') {
|
2298 | return false;
|
2299 | }
|
2300 | if (this.name === 'SchemaVisitor') {
|
2301 |
|
2302 | return true;
|
2303 | }
|
2304 | var stub = SchemaVisitor.prototype[methodName];
|
2305 | if (method === stub) {
|
2306 |
|
2307 |
|
2308 | return false;
|
2309 | }
|
2310 | return true;
|
2311 | };
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 | SchemaVisitor.prototype.visitSchema = function (_schema) { };
|
2319 | SchemaVisitor.prototype.visitScalar = function (_scalar
|
2320 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2321 | ) { };
|
2322 | SchemaVisitor.prototype.visitObject = function (_object
|
2323 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2324 | ) { };
|
2325 | SchemaVisitor.prototype.visitFieldDefinition = function (_field, _details
|
2326 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2327 | ) { };
|
2328 | SchemaVisitor.prototype.visitArgumentDefinition = function (_argument, _details
|
2329 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2330 | ) { };
|
2331 | SchemaVisitor.prototype.visitInterface = function (_iface
|
2332 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2333 | ) { };
|
2334 |
|
2335 | SchemaVisitor.prototype.visitUnion = function (_union) { };
|
2336 |
|
2337 | SchemaVisitor.prototype.visitEnum = function (_type) { };
|
2338 | SchemaVisitor.prototype.visitEnumValue = function (_value, _details
|
2339 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2340 | ) { };
|
2341 | SchemaVisitor.prototype.visitInputObject = function (_object
|
2342 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2343 | ) { };
|
2344 | SchemaVisitor.prototype.visitInputFieldDefinition = function (_field, _details
|
2345 | // eslint-disable-next-line @typescript-eslint/no-empty-function
|
2346 | ) { };
|
2347 | return SchemaVisitor;
|
2348 | }());
|
2349 |
|
2350 | function isSchemaVisitor(obj) {
|
2351 | if ('schema' in obj && isSchema(obj.schema)) {
|
2352 | if ('visitSchema' in obj && typeof obj.visitSchema === 'function') {
|
2353 | return true;
|
2354 | }
|
2355 | }
|
2356 | return false;
|
2357 | }
|
2358 |
|
2359 | function visitSchema(schema,
|
2360 | // To accommodate as many different visitor patterns as possible, the
|
2361 | // visitSchema function does not simply accept a single instance of the
|
2362 | // SchemaVisitor class, but instead accepts a function that takes the
|
2363 | // current VisitableSchemaType object and the name of a visitor method and
|
2364 | // returns an array of SchemaVisitor instances that implement the visitor
|
2365 | // method and have an interest in handling the given VisitableSchemaType
|
2366 | // object. In the simplest case, this function can always return an array
|
2367 | // containing a single visitor object, without even looking at the type or
|
2368 | // methodName parameters. In other cases, this function might sometimes
|
2369 | // return an empty array to indicate there are no visitors that should be
|
2370 | // applied to the given VisitableSchemaType object. For an example of a
|
2371 | // visitor pattern that benefits from this abstraction, see the
|
2372 | // SchemaDirectiveVisitor class below.
|
2373 | visitorOrVisitorSelector) {
|
2374 | var visitorSelector = typeof visitorOrVisitorSelector === 'function' ? visitorOrVisitorSelector : function () { return visitorOrVisitorSelector; };
|
2375 |
|
2376 |
|
2377 | function callMethod(methodName, type) {
|
2378 | var args = [];
|
2379 | for (var _i = 2; _i < arguments.length; _i++) {
|
2380 | args[_i - 2] = arguments[_i];
|
2381 | }
|
2382 | var visitors = visitorSelector(type, methodName);
|
2383 | visitors = Array.isArray(visitors) ? visitors : [visitors];
|
2384 | var finalType = type;
|
2385 | visitors.every(function (visitorOrVisitorDef) {
|
2386 | var newType;
|
2387 | if (isSchemaVisitor(visitorOrVisitorDef)) {
|
2388 | newType = visitorOrVisitorDef[methodName].apply(visitorOrVisitorDef, __spread([finalType], args));
|
2389 | }
|
2390 | else if (isNamedType(finalType) &&
|
2391 | (methodName === 'visitScalar' ||
|
2392 | methodName === 'visitEnum' ||
|
2393 | methodName === 'visitObject' ||
|
2394 | methodName === 'visitInputObject' ||
|
2395 | methodName === 'visitUnion' ||
|
2396 | methodName === 'visitInterface')) {
|
2397 | var specifiers = getTypeSpecifiers$1(finalType, schema);
|
2398 | var typeVisitor = getVisitor(visitorOrVisitorDef, specifiers);
|
2399 | newType = typeVisitor != null ? typeVisitor(finalType, schema) : undefined;
|
2400 | }
|
2401 | if (typeof newType === 'undefined') {
|
2402 |
|
2403 | return true;
|
2404 | }
|
2405 | if (methodName === 'visitSchema' || isSchema(finalType)) {
|
2406 | throw new Error("Method " + methodName + " cannot replace schema with " + newType);
|
2407 | }
|
2408 | if (newType === null) {
|
2409 |
|
2410 |
|
2411 | finalType = null;
|
2412 | return false;
|
2413 | }
|
2414 |
|
2415 |
|
2416 |
|
2417 | finalType = newType;
|
2418 | return true;
|
2419 | });
|
2420 |
|
2421 |
|
2422 | return finalType;
|
2423 | }
|
2424 |
|
2425 |
|
2426 | function visit(type) {
|
2427 | var e_1, _a;
|
2428 | if (isSchema(type)) {
|
2429 |
|
2430 |
|
2431 |
|
2432 | callMethod('visitSchema', type);
|
2433 | var typeMap_1 = type.getTypeMap();
|
2434 | Object.entries(typeMap_1).forEach(function (_a) {
|
2435 | var _b = __read(_a, 2), typeName = _b[0], namedType = _b[1];
|
2436 | if (!typeName.startsWith('__') && namedType != null) {
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 | typeMap_1[typeName] = visit(namedType);
|
2443 | }
|
2444 | });
|
2445 | return type;
|
2446 | }
|
2447 | if (isObjectType(type)) {
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 | var newObject = callMethod('visitObject', type);
|
2453 | if (newObject != null) {
|
2454 | visitFields(newObject);
|
2455 | }
|
2456 | return newObject;
|
2457 | }
|
2458 | if (isInterfaceType(type)) {
|
2459 | var newInterface = callMethod('visitInterface', type);
|
2460 | if (newInterface != null) {
|
2461 | visitFields(newInterface);
|
2462 | }
|
2463 | return newInterface;
|
2464 | }
|
2465 | if (isInputObjectType(type)) {
|
2466 | var newInputObject = callMethod('visitInputObject', type);
|
2467 | if (newInputObject != null) {
|
2468 | var fieldMap = newInputObject.getFields();
|
2469 | try {
|
2470 | for (var _b = __values(Object.keys(fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
2471 | var key = _c.value;
|
2472 | fieldMap[key] = callMethod('visitInputFieldDefinition', fieldMap[key], {
|
2473 |
|
2474 |
|
2475 | objectType: newInputObject,
|
2476 | });
|
2477 | if (!fieldMap[key]) {
|
2478 | delete fieldMap[key];
|
2479 | }
|
2480 | }
|
2481 | }
|
2482 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
2483 | finally {
|
2484 | try {
|
2485 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
2486 | }
|
2487 | finally { if (e_1) throw e_1.error; }
|
2488 | }
|
2489 | }
|
2490 | return newInputObject;
|
2491 | }
|
2492 | if (isScalarType(type)) {
|
2493 | return callMethod('visitScalar', type);
|
2494 | }
|
2495 | if (isUnionType(type)) {
|
2496 | return callMethod('visitUnion', type);
|
2497 | }
|
2498 | if (isEnumType(type)) {
|
2499 | var newEnum_1 = callMethod('visitEnum', type);
|
2500 | if (newEnum_1 != null) {
|
2501 | var newValues = newEnum_1
|
2502 | .getValues()
|
2503 | .map(function (value) {
|
2504 | return callMethod('visitEnumValue', value, {
|
2505 | enumType: newEnum_1,
|
2506 | });
|
2507 | })
|
2508 | .filter(Boolean);
|
2509 |
|
2510 | var valuesUpdated = newValues.some(function (value, index) { return value !== newEnum_1.getValues()[index]; });
|
2511 | if (valuesUpdated) {
|
2512 | newEnum_1 = new GraphQLEnumType(__assign(__assign({}, newEnum_1.toConfig()), { values: newValues.reduce(function (prev, value) {
|
2513 | var _a;
|
2514 | return (__assign(__assign({}, prev), (_a = {}, _a[value.name] = {
|
2515 | value: value.value,
|
2516 | deprecationReason: value.deprecationReason,
|
2517 | description: value.description,
|
2518 | astNode: value.astNode,
|
2519 | }, _a)));
|
2520 | }, {}) }));
|
2521 | }
|
2522 | }
|
2523 | return newEnum_1;
|
2524 | }
|
2525 | throw new Error("Unexpected schema type: " + type);
|
2526 | }
|
2527 | function visitFields(type) {
|
2528 | var e_2, _a;
|
2529 | var fieldMap = type.getFields();
|
2530 | var _loop_1 = function (key, field) {
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 | var newField = callMethod('visitFieldDefinition', field, {
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 | objectType: type,
|
2544 | });
|
2545 | if (newField.args != null) {
|
2546 | newField.args = newField.args
|
2547 | .map(function (arg) {
|
2548 | return callMethod('visitArgumentDefinition', arg, {
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 | field: newField,
|
2554 | objectType: type,
|
2555 | });
|
2556 | })
|
2557 | .filter(Boolean);
|
2558 | }
|
2559 |
|
2560 | if (newField) {
|
2561 | fieldMap[key] = newField;
|
2562 | }
|
2563 | else {
|
2564 | delete fieldMap[key];
|
2565 | }
|
2566 | };
|
2567 | try {
|
2568 | for (var _b = __values(Object.entries(fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
2569 | var _d = __read(_c.value, 2), key = _d[0], field = _d[1];
|
2570 | _loop_1(key, field);
|
2571 | }
|
2572 | }
|
2573 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
2574 | finally {
|
2575 | try {
|
2576 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
2577 | }
|
2578 | finally { if (e_2) throw e_2.error; }
|
2579 | }
|
2580 | }
|
2581 | visit(schema);
|
2582 |
|
2583 |
|
2584 | healSchema(schema);
|
2585 |
|
2586 | return schema;
|
2587 | }
|
2588 | function getTypeSpecifiers$1(type, schema) {
|
2589 | var specifiers = [VisitSchemaKind.TYPE];
|
2590 | if (isObjectType(type)) {
|
2591 | specifiers.push(VisitSchemaKind.COMPOSITE_TYPE, VisitSchemaKind.OBJECT_TYPE);
|
2592 | var query = schema.getQueryType();
|
2593 | var mutation = schema.getMutationType();
|
2594 | var subscription = schema.getSubscriptionType();
|
2595 | if (type === query) {
|
2596 | specifiers.push(VisitSchemaKind.ROOT_OBJECT, VisitSchemaKind.QUERY);
|
2597 | }
|
2598 | else if (type === mutation) {
|
2599 | specifiers.push(VisitSchemaKind.ROOT_OBJECT, VisitSchemaKind.MUTATION);
|
2600 | }
|
2601 | else if (type === subscription) {
|
2602 | specifiers.push(VisitSchemaKind.ROOT_OBJECT, VisitSchemaKind.SUBSCRIPTION);
|
2603 | }
|
2604 | }
|
2605 | else if (isInputType(type)) {
|
2606 | specifiers.push(VisitSchemaKind.INPUT_OBJECT_TYPE);
|
2607 | }
|
2608 | else if (isInterfaceType(type)) {
|
2609 | specifiers.push(VisitSchemaKind.COMPOSITE_TYPE, VisitSchemaKind.ABSTRACT_TYPE, VisitSchemaKind.INTERFACE_TYPE);
|
2610 | }
|
2611 | else if (isUnionType(type)) {
|
2612 | specifiers.push(VisitSchemaKind.COMPOSITE_TYPE, VisitSchemaKind.ABSTRACT_TYPE, VisitSchemaKind.UNION_TYPE);
|
2613 | }
|
2614 | else if (isEnumType(type)) {
|
2615 | specifiers.push(VisitSchemaKind.ENUM_TYPE);
|
2616 | }
|
2617 | else if (isScalarType(type)) {
|
2618 | specifiers.push(VisitSchemaKind.SCALAR_TYPE);
|
2619 | }
|
2620 | return specifiers;
|
2621 | }
|
2622 | function getVisitor(visitorDef, specifiers) {
|
2623 | var typeVisitor;
|
2624 | var stack = __spread(specifiers);
|
2625 | while (!typeVisitor && stack.length > 0) {
|
2626 | var next = stack.pop();
|
2627 | typeVisitor = visitorDef[next];
|
2628 | }
|
2629 | return typeVisitor != null ? typeVisitor : null;
|
2630 | }
|
2631 |
|
2632 |
|
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 | var SchemaDirectiveVisitor = (function (_super) {
|
2675 | __extends(SchemaDirectiveVisitor, _super);
|
2676 |
|
2677 |
|
2678 | function SchemaDirectiveVisitor(config) {
|
2679 | var _this = _super.call(this) || this;
|
2680 | _this.name = config.name;
|
2681 | _this.args = config.args;
|
2682 | _this.visitedType = config.visitedType;
|
2683 | _this.schema = config.schema;
|
2684 | _this.context = config.context;
|
2685 | return _this;
|
2686 | }
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 | SchemaDirectiveVisitor.getDirectiveDeclaration = function (directiveName, schema) {
|
2692 | return schema.getDirective(directiveName);
|
2693 | };
|
2694 |
|
2695 |
|
2696 |
|
2697 | SchemaDirectiveVisitor.visitSchemaDirectives = function (schema,
|
2698 | // The keys of this object correspond to directive names as they appear
|
2699 | // in the schema, and the values should be subclasses (not instances!)
|
2700 | // of the SchemaDirectiveVisitor class. This distinction is important
|
2701 | // because a new SchemaDirectiveVisitor instance will be created each
|
2702 | // time a matching directive is found in the schema AST, with arguments
|
2703 | // and other metadata specific to that occurrence. To help prevent the
|
2704 | // mistake of passing instances, the SchemaDirectiveVisitor constructor
|
2705 | // method is marked as protected.
|
2706 | directiveVisitors,
|
2707 | // Optional context object that will be available to all visitor instances
|
2708 | // via this.context. Defaults to an empty null-prototype object.
|
2709 | context
|
2710 | // The visitSchemaDirectives method returns a map from directive names to
|
2711 | // lists of SchemaDirectiveVisitors created while visiting the schema.
|
2712 | ) {
|
2713 | if (context === void 0) { context = Object.create(null); }
|
2714 |
|
2715 |
|
2716 |
|
2717 | var declaredDirectives = this.getDeclaredDirectives(schema, directiveVisitors);
|
2718 |
|
2719 |
|
2720 | var createdVisitors = Object.keys(directiveVisitors).reduce(function (prev, item) {
|
2721 | var _a;
|
2722 | return (__assign(__assign({}, prev), (_a = {}, _a[item] = [], _a)));
|
2723 | }, {});
|
2724 | var directiveVisitorMap = Object.entries(directiveVisitors).reduce(function (prev, _a) {
|
2725 | var _b;
|
2726 | var _c = __read(_a, 2), key = _c[0], value = _c[1];
|
2727 | return (__assign(__assign({}, prev), (_b = {}, _b[key] = value, _b)));
|
2728 | }, {});
|
2729 | function visitorSelector(type, methodName) {
|
2730 | var _a, _b;
|
2731 | var directiveNodes = (_b = (_a = type === null || type === void 0 ? void 0 : type.astNode) === null || _a === void 0 ? void 0 : _a.directives) !== null && _b !== void 0 ? _b : [];
|
2732 | var extensionASTNodes = type.extensionASTNodes;
|
2733 | if (extensionASTNodes != null) {
|
2734 | extensionASTNodes.forEach(function (extensionASTNode) {
|
2735 | if (extensionASTNode.directives != null) {
|
2736 | directiveNodes = directiveNodes.concat(extensionASTNode.directives);
|
2737 | }
|
2738 | });
|
2739 | }
|
2740 | var visitors = [];
|
2741 | directiveNodes.forEach(function (directiveNode) {
|
2742 | var directiveName = directiveNode.name.value;
|
2743 | if (!(directiveName in directiveVisitorMap)) {
|
2744 | return;
|
2745 | }
|
2746 | var VisitorClass = directiveVisitorMap[directiveName];
|
2747 |
|
2748 |
|
2749 | if (!VisitorClass.implementsVisitorMethod(methodName)) {
|
2750 | return;
|
2751 | }
|
2752 | var decl = declaredDirectives[directiveName];
|
2753 | var args;
|
2754 | if (decl != null) {
|
2755 |
|
2756 |
|
2757 |
|
2758 | args = getArgumentValues(decl, directiveNode);
|
2759 | }
|
2760 | else {
|
2761 |
|
2762 |
|
2763 | args = Object.create(null);
|
2764 | if (directiveNode.arguments != null) {
|
2765 | directiveNode.arguments.forEach(function (arg) {
|
2766 | args[arg.name.value] = valueFromASTUntyped(arg.value);
|
2767 | });
|
2768 | }
|
2769 | }
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 | visitors.push(new VisitorClass({
|
2776 | name: directiveName,
|
2777 | args: args,
|
2778 | visitedType: type,
|
2779 | schema: schema,
|
2780 | context: context,
|
2781 | }));
|
2782 | });
|
2783 | if (visitors.length > 0) {
|
2784 | visitors.forEach(function (visitor) {
|
2785 | createdVisitors[visitor.name].push(visitor);
|
2786 | });
|
2787 | }
|
2788 | return visitors;
|
2789 | }
|
2790 | visitSchema(schema, visitorSelector);
|
2791 | return createdVisitors;
|
2792 | };
|
2793 | SchemaDirectiveVisitor.getDeclaredDirectives = function (schema, directiveVisitors) {
|
2794 | var declaredDirectives = schema.getDirectives().reduce(function (prev, curr) {
|
2795 | var _a;
|
2796 | return (__assign(__assign({}, prev), (_a = {}, _a[curr.name] = curr, _a)));
|
2797 | }, {});
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 | Object.entries(directiveVisitors).forEach(function (_a) {
|
2804 | var _b = __read(_a, 2), directiveName = _b[0], visitorClass = _b[1];
|
2805 | var decl = visitorClass.getDirectiveDeclaration(directiveName, schema);
|
2806 | if (decl != null) {
|
2807 | declaredDirectives[directiveName] = decl;
|
2808 | }
|
2809 | });
|
2810 | Object.entries(declaredDirectives).forEach(function (_a) {
|
2811 | var _b = __read(_a, 2), name = _b[0], decl = _b[1];
|
2812 | if (!(name in directiveVisitors)) {
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 | return;
|
2818 | }
|
2819 | var visitorClass = directiveVisitors[name];
|
2820 | decl.locations.forEach(function (loc) {
|
2821 | var visitorMethodName = directiveLocationToVisitorMethodName(loc);
|
2822 | if (SchemaVisitor.implementsVisitorMethod(visitorMethodName) &&
|
2823 | !visitorClass.implementsVisitorMethod(visitorMethodName)) {
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 | throw new Error("SchemaDirectiveVisitor for @" + name + " must implement " + visitorMethodName + " method");
|
2829 | }
|
2830 | });
|
2831 | });
|
2832 | return declaredDirectives;
|
2833 | };
|
2834 | return SchemaDirectiveVisitor;
|
2835 | }(SchemaVisitor));
|
2836 |
|
2837 | function directiveLocationToVisitorMethodName(loc) {
|
2838 | return ('visit' +
|
2839 | loc.replace(/([^_]*)_?/g, function (_wholeMatch, part) { return part.charAt(0).toUpperCase() + part.slice(1).toLowerCase(); }));
|
2840 | }
|
2841 |
|
2842 | function getResolversFromSchema(schema) {
|
2843 | var resolvers = Object.create({});
|
2844 | var typeMap = schema.getTypeMap();
|
2845 | Object.keys(typeMap).forEach(function (typeName) {
|
2846 | var type = typeMap[typeName];
|
2847 | if (isScalarType(type)) {
|
2848 | if (!isSpecifiedScalarType(type)) {
|
2849 | var config = type.toConfig();
|
2850 | delete config.astNode;
|
2851 | resolvers[typeName] = new GraphQLScalarType(config);
|
2852 | }
|
2853 | }
|
2854 | else if (isEnumType(type)) {
|
2855 | resolvers[typeName] = {};
|
2856 | var values = type.getValues();
|
2857 | values.forEach(function (value) {
|
2858 | resolvers[typeName][value.name] = value.value;
|
2859 | });
|
2860 | }
|
2861 | else if (isInterfaceType(type)) {
|
2862 | if (type.resolveType != null) {
|
2863 | resolvers[typeName] = {
|
2864 | __resolveType: type.resolveType,
|
2865 | };
|
2866 | }
|
2867 | }
|
2868 | else if (isUnionType(type)) {
|
2869 | if (type.resolveType != null) {
|
2870 | resolvers[typeName] = {
|
2871 | __resolveType: type.resolveType,
|
2872 | };
|
2873 | }
|
2874 | }
|
2875 | else if (isObjectType(type)) {
|
2876 | resolvers[typeName] = {};
|
2877 | if (type.isTypeOf != null) {
|
2878 | resolvers[typeName].__isTypeOf = type.isTypeOf;
|
2879 | }
|
2880 | var fields_1 = type.getFields();
|
2881 | Object.keys(fields_1).forEach(function (fieldName) {
|
2882 | var field = fields_1[fieldName];
|
2883 | resolvers[typeName][fieldName] = {
|
2884 | resolve: field.resolve,
|
2885 | subscribe: field.subscribe,
|
2886 | };
|
2887 | });
|
2888 | }
|
2889 | });
|
2890 | return resolvers;
|
2891 | }
|
2892 |
|
2893 | function forEachField(schema, fn) {
|
2894 | var typeMap = schema.getTypeMap();
|
2895 | Object.keys(typeMap).forEach(function (typeName) {
|
2896 | var type = typeMap[typeName];
|
2897 |
|
2898 | if (!getNamedType(type).name.startsWith('__') && isObjectType(type)) {
|
2899 | var fields_1 = type.getFields();
|
2900 | Object.keys(fields_1).forEach(function (fieldName) {
|
2901 | var field = fields_1[fieldName];
|
2902 | fn(field, typeName, fieldName);
|
2903 | });
|
2904 | }
|
2905 | });
|
2906 | }
|
2907 |
|
2908 | function forEachDefaultValue(schema, fn) {
|
2909 | var typeMap = schema.getTypeMap();
|
2910 | Object.keys(typeMap).forEach(function (typeName) {
|
2911 | var type = typeMap[typeName];
|
2912 | if (!getNamedType(type).name.startsWith('__')) {
|
2913 | if (isObjectType(type)) {
|
2914 | var fields_1 = type.getFields();
|
2915 | Object.keys(fields_1).forEach(function (fieldName) {
|
2916 | var field = fields_1[fieldName];
|
2917 | field.args.forEach(function (arg) {
|
2918 | arg.defaultValue = fn(arg.type, arg.defaultValue);
|
2919 | });
|
2920 | });
|
2921 | }
|
2922 | else if (isInputObjectType(type)) {
|
2923 | var fields_2 = type.getFields();
|
2924 | Object.keys(fields_2).forEach(function (fieldName) {
|
2925 | var field = fields_2[fieldName];
|
2926 | field.defaultValue = fn(field.type, field.defaultValue);
|
2927 | });
|
2928 | }
|
2929 | }
|
2930 | });
|
2931 | }
|
2932 |
|
2933 |
|
2934 | function addTypes(schema, newTypesOrDirectives) {
|
2935 | var queryType = schema.getQueryType();
|
2936 | var mutationType = schema.getMutationType();
|
2937 | var subscriptionType = schema.getSubscriptionType();
|
2938 | var queryTypeName = queryType != null ? queryType.name : undefined;
|
2939 | var mutationTypeName = mutationType != null ? mutationType.name : undefined;
|
2940 | var subscriptionTypeName = subscriptionType != null ? subscriptionType.name : undefined;
|
2941 | var config = schema.toConfig();
|
2942 | var originalTypeMap = {};
|
2943 | config.types.forEach(function (type) {
|
2944 | originalTypeMap[type.name] = type;
|
2945 | });
|
2946 | var originalDirectiveMap = {};
|
2947 | config.directives.forEach(function (directive) {
|
2948 | originalDirectiveMap[directive.name] = directive;
|
2949 | });
|
2950 | newTypesOrDirectives.forEach(function (newTypeOrDirective) {
|
2951 | if (isNamedType(newTypeOrDirective)) {
|
2952 | originalTypeMap[newTypeOrDirective.name] = newTypeOrDirective;
|
2953 | }
|
2954 | else if (isDirective(newTypeOrDirective)) {
|
2955 | originalDirectiveMap[newTypeOrDirective.name] = newTypeOrDirective;
|
2956 | }
|
2957 | });
|
2958 | var _a = rewireTypes(originalTypeMap, Object.keys(originalDirectiveMap).map(function (directiveName) { return originalDirectiveMap[directiveName]; })), typeMap = _a.typeMap, directives = _a.directives;
|
2959 | return new GraphQLSchema(__assign(__assign({}, config), { query: queryTypeName ? typeMap[queryTypeName] : undefined, mutation: mutationTypeName ? typeMap[mutationTypeName] : undefined, subscription: subscriptionTypeName != null ? typeMap[subscriptionTypeName] : undefined, types: Object.keys(typeMap).map(function (typeName) { return typeMap[typeName]; }), directives: directives }));
|
2960 | }
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 | function pruneSchema(schema, options) {
|
2968 | var _a;
|
2969 | if (options === void 0) { options = {}; }
|
2970 | var pruningContext = {
|
2971 | schema: schema,
|
2972 | unusedTypes: Object.create(null),
|
2973 | implementations: Object.create(null),
|
2974 | };
|
2975 | Object.keys(schema.getTypeMap()).forEach(function (typeName) {
|
2976 | var type = schema.getType(typeName);
|
2977 | if ('getInterfaces' in type) {
|
2978 | type.getInterfaces().forEach(function (iface) {
|
2979 | if (pruningContext.implementations[iface.name] == null) {
|
2980 | pruningContext.implementations[iface.name] = Object.create(null);
|
2981 | }
|
2982 | pruningContext.implementations[iface.name][type.name] = true;
|
2983 | });
|
2984 | }
|
2985 | });
|
2986 | visitTypes(pruningContext, schema);
|
2987 | return mapSchema(schema, (_a = {},
|
2988 | _a[MapperKind.TYPE] = function (type) {
|
2989 | if (isObjectType(type) || isInputObjectType(type)) {
|
2990 | if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
|
2991 | (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
|
2992 | return null;
|
2993 | }
|
2994 | }
|
2995 | else if (isUnionType(type)) {
|
2996 | if ((!type.getTypes().length && !options.skipEmptyUnionPruning) ||
|
2997 | (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
|
2998 | return null;
|
2999 | }
|
3000 | }
|
3001 | else if (isInterfaceType(type)) {
|
3002 | if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
|
3003 | (!Object.keys(pruningContext.implementations[type.name]).length &&
|
3004 | !options.skipUnimplementedInterfacesPruning) ||
|
3005 | (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
|
3006 | return null;
|
3007 | }
|
3008 | }
|
3009 | else {
|
3010 | if (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning) {
|
3011 | return null;
|
3012 | }
|
3013 | }
|
3014 | },
|
3015 | _a));
|
3016 | }
|
3017 | function visitOutputType(visitedTypes, pruningContext, type) {
|
3018 | if (visitedTypes[type.name]) {
|
3019 | return;
|
3020 | }
|
3021 | visitedTypes[type.name] = true;
|
3022 | pruningContext.unusedTypes[type.name] = false;
|
3023 | if (isObjectType(type) || isInterfaceType(type)) {
|
3024 | var fields_1 = type.getFields();
|
3025 | Object.keys(fields_1).forEach(function (fieldName) {
|
3026 | var field = fields_1[fieldName];
|
3027 | var namedType = getNamedType(field.type);
|
3028 | visitOutputType(visitedTypes, pruningContext, namedType);
|
3029 | var args = field.args;
|
3030 | args.forEach(function (arg) {
|
3031 | var type = getNamedType(arg.type);
|
3032 | visitInputType(visitedTypes, pruningContext, type);
|
3033 | });
|
3034 | });
|
3035 | if (isInterfaceType(type)) {
|
3036 | Object.keys(pruningContext.implementations[type.name]).forEach(function (typeName) {
|
3037 | visitOutputType(visitedTypes, pruningContext, pruningContext.schema.getType(typeName));
|
3038 | });
|
3039 | }
|
3040 | if ('getInterfaces' in type) {
|
3041 | type.getInterfaces().forEach(function (type) {
|
3042 | visitOutputType(visitedTypes, pruningContext, type);
|
3043 | });
|
3044 | }
|
3045 | }
|
3046 | else if (isUnionType(type)) {
|
3047 | var types = type.getTypes();
|
3048 | types.forEach(function (type) { return visitOutputType(visitedTypes, pruningContext, type); });
|
3049 | }
|
3050 | }
|
3051 | function visitInputType(visitedTypes, pruningContext, type) {
|
3052 | if (visitedTypes[type.name]) {
|
3053 | return;
|
3054 | }
|
3055 | pruningContext.unusedTypes[type.name] = false;
|
3056 | visitedTypes[type.name] = true;
|
3057 | if (isInputObjectType(type)) {
|
3058 | var fields_2 = type.getFields();
|
3059 | Object.keys(fields_2).forEach(function (fieldName) {
|
3060 | var field = fields_2[fieldName];
|
3061 | var namedType = getNamedType(field.type);
|
3062 | visitInputType(visitedTypes, pruningContext, namedType);
|
3063 | });
|
3064 | }
|
3065 | }
|
3066 | function visitTypes(pruningContext, schema) {
|
3067 | Object.keys(schema.getTypeMap()).forEach(function (typeName) {
|
3068 | if (!typeName.startsWith('__')) {
|
3069 | pruningContext.unusedTypes[typeName] = true;
|
3070 | }
|
3071 | });
|
3072 | var visitedTypes = Object.create(null);
|
3073 | var rootTypes = [schema.getQueryType(), schema.getMutationType(), schema.getSubscriptionType()].filter(function (type) { return type != null; });
|
3074 | rootTypes.forEach(function (rootType) { return visitOutputType(visitedTypes, pruningContext, rootType); });
|
3075 | schema.getDirectives().forEach(function (directive) {
|
3076 | directive.args.forEach(function (arg) {
|
3077 | var type = getNamedType(arg.type);
|
3078 | visitInputType(visitedTypes, pruningContext, type);
|
3079 | });
|
3080 | });
|
3081 | }
|
3082 |
|
3083 | function mergeDeep(target) {
|
3084 | var e_1, _a, _b, _c;
|
3085 | var sources = [];
|
3086 | for (var _i = 1; _i < arguments.length; _i++) {
|
3087 | sources[_i - 1] = arguments[_i];
|
3088 | }
|
3089 | if (isScalarType(target)) {
|
3090 | return target;
|
3091 | }
|
3092 | var output = __assign({}, target);
|
3093 | try {
|
3094 | for (var sources_1 = __values(sources), sources_1_1 = sources_1.next(); !sources_1_1.done; sources_1_1 = sources_1.next()) {
|
3095 | var source = sources_1_1.value;
|
3096 | if (isObject(target) && isObject(source)) {
|
3097 | for (var key in source) {
|
3098 | if (isObject(source[key])) {
|
3099 | if (!(key in target)) {
|
3100 | Object.assign(output, (_b = {}, _b[key] = source[key], _b));
|
3101 | }
|
3102 | else {
|
3103 | output[key] = mergeDeep(target[key], source[key]);
|
3104 | }
|
3105 | }
|
3106 | else {
|
3107 | Object.assign(output, (_c = {}, _c[key] = source[key], _c));
|
3108 | }
|
3109 | }
|
3110 | }
|
3111 | }
|
3112 | }
|
3113 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
3114 | finally {
|
3115 | try {
|
3116 | if (sources_1_1 && !sources_1_1.done && (_a = sources_1.return)) _a.call(sources_1);
|
3117 | }
|
3118 | finally { if (e_1) throw e_1.error; }
|
3119 | }
|
3120 | return output;
|
3121 | }
|
3122 | function isObject(item) {
|
3123 | return item && typeof item === 'object' && !Array.isArray(item);
|
3124 | }
|
3125 |
|
3126 | function parseSelectionSet(selectionSet) {
|
3127 | var query = parse(selectionSet).definitions[0];
|
3128 | return query.selectionSet;
|
3129 | }
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 | function getResponseKeyFromInfo(info) {
|
3137 | return info.fieldNodes[0].alias != null ? info.fieldNodes[0].alias.value : info.fieldName;
|
3138 | }
|
3139 |
|
3140 | function appendObjectFields(schema, typeName, additionalFields) {
|
3141 | var _a;
|
3142 | if (schema.getType(typeName) == null) {
|
3143 | return addTypes(schema, [
|
3144 | new GraphQLObjectType({
|
3145 | name: typeName,
|
3146 | fields: additionalFields,
|
3147 | }),
|
3148 | ]);
|
3149 | }
|
3150 | return mapSchema(schema, (_a = {},
|
3151 | _a[MapperKind.OBJECT_TYPE] = function (type) {
|
3152 | if (type.name === typeName) {
|
3153 | var config = type.toConfig();
|
3154 | var originalFieldConfigMap_1 = config.fields;
|
3155 | var newFieldConfigMap_1 = {};
|
3156 | Object.keys(originalFieldConfigMap_1).forEach(function (fieldName) {
|
3157 | newFieldConfigMap_1[fieldName] = originalFieldConfigMap_1[fieldName];
|
3158 | });
|
3159 | Object.keys(additionalFields).forEach(function (fieldName) {
|
3160 | newFieldConfigMap_1[fieldName] = additionalFields[fieldName];
|
3161 | });
|
3162 | return correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_1 })));
|
3163 | }
|
3164 | },
|
3165 | _a));
|
3166 | }
|
3167 | function removeObjectFields(schema, typeName, testFn) {
|
3168 | var _a;
|
3169 | var removedFields = {};
|
3170 | var newSchema = mapSchema(schema, (_a = {},
|
3171 | _a[MapperKind.OBJECT_TYPE] = function (type) {
|
3172 | if (type.name === typeName) {
|
3173 | var config = type.toConfig();
|
3174 | var originalFieldConfigMap_2 = config.fields;
|
3175 | var newFieldConfigMap_2 = {};
|
3176 | Object.keys(originalFieldConfigMap_2).forEach(function (fieldName) {
|
3177 | var originalFieldConfig = originalFieldConfigMap_2[fieldName];
|
3178 | if (testFn(fieldName, originalFieldConfig)) {
|
3179 | removedFields[fieldName] = originalFieldConfig;
|
3180 | }
|
3181 | else {
|
3182 | newFieldConfigMap_2[fieldName] = originalFieldConfig;
|
3183 | }
|
3184 | });
|
3185 | return correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_2 })));
|
3186 | }
|
3187 | },
|
3188 | _a));
|
3189 | return [newSchema, removedFields];
|
3190 | }
|
3191 | function selectObjectFields(schema, typeName, testFn) {
|
3192 | var _a;
|
3193 | var selectedFields = {};
|
3194 | mapSchema(schema, (_a = {},
|
3195 | _a[MapperKind.OBJECT_TYPE] = function (type) {
|
3196 | if (type.name === typeName) {
|
3197 | var config = type.toConfig();
|
3198 | var originalFieldConfigMap_3 = config.fields;
|
3199 | Object.keys(originalFieldConfigMap_3).forEach(function (fieldName) {
|
3200 | var originalFieldConfig = originalFieldConfigMap_3[fieldName];
|
3201 | if (testFn(fieldName, originalFieldConfig)) {
|
3202 | selectedFields[fieldName] = originalFieldConfig;
|
3203 | }
|
3204 | });
|
3205 | }
|
3206 | return undefined;
|
3207 | },
|
3208 | _a));
|
3209 | return selectedFields;
|
3210 | }
|
3211 | function modifyObjectFields(schema, typeName, testFn, newFields) {
|
3212 | var _a;
|
3213 | var removedFields = {};
|
3214 | var newSchema = mapSchema(schema, (_a = {},
|
3215 | _a[MapperKind.OBJECT_TYPE] = function (type) {
|
3216 | if (type.name === typeName) {
|
3217 | var config = type.toConfig();
|
3218 | var originalFieldConfigMap_4 = config.fields;
|
3219 | var newFieldConfigMap_3 = {};
|
3220 | Object.keys(originalFieldConfigMap_4).forEach(function (fieldName) {
|
3221 | var originalFieldConfig = originalFieldConfigMap_4[fieldName];
|
3222 | if (testFn(fieldName, originalFieldConfig)) {
|
3223 | removedFields[fieldName] = originalFieldConfig;
|
3224 | }
|
3225 | else {
|
3226 | newFieldConfigMap_3[fieldName] = originalFieldConfig;
|
3227 | }
|
3228 | });
|
3229 | Object.keys(newFields).forEach(function (fieldName) {
|
3230 | var fieldConfig = newFields[fieldName];
|
3231 | newFieldConfigMap_3[fieldName] = fieldConfig;
|
3232 | });
|
3233 | return correctASTNodes(new GraphQLObjectType(__assign(__assign({}, config), { fields: newFieldConfigMap_3 })));
|
3234 | }
|
3235 | },
|
3236 | _a));
|
3237 | return [newSchema, removedFields];
|
3238 | }
|
3239 |
|
3240 | function renameType(type, newTypeName) {
|
3241 | if (isObjectType(type)) {
|
3242 | return new GraphQLObjectType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
|
3243 | ? type.astNode
|
3244 | : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
|
3245 | ? type.extensionASTNodes
|
3246 | : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
|
3247 | }
|
3248 | else if (isInterfaceType(type)) {
|
3249 | return new GraphQLInterfaceType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
|
3250 | ? type.astNode
|
3251 | : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
|
3252 | ? type.extensionASTNodes
|
3253 | : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
|
3254 | }
|
3255 | else if (isUnionType(type)) {
|
3256 | return new GraphQLUnionType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
|
3257 | ? type.astNode
|
3258 | : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
|
3259 | ? type.extensionASTNodes
|
3260 | : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
|
3261 | }
|
3262 | else if (isInputObjectType(type)) {
|
3263 | return new GraphQLInputObjectType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
|
3264 | ? type.astNode
|
3265 | : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
|
3266 | ? type.extensionASTNodes
|
3267 | : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
|
3268 | }
|
3269 | else if (isEnumType(type)) {
|
3270 | return new GraphQLEnumType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
|
3271 | ? type.astNode
|
3272 | : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
|
3273 | ? type.extensionASTNodes
|
3274 | : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
|
3275 | }
|
3276 | else if (isScalarType(type)) {
|
3277 | return new GraphQLScalarType(__assign(__assign({}, type.toConfig()), { name: newTypeName, astNode: type.astNode == null
|
3278 | ? type.astNode
|
3279 | : __assign(__assign({}, type.astNode), { name: __assign(__assign({}, type.astNode.name), { value: newTypeName }) }), extensionASTNodes: type.extensionASTNodes == null
|
3280 | ? type.extensionASTNodes
|
3281 | : type.extensionASTNodes.map(function (node) { return (__assign(__assign({}, node), { name: __assign(__assign({}, node.name), { value: newTypeName }) })); }) }));
|
3282 | }
|
3283 | throw new Error("Unknown type " + type + ".");
|
3284 | }
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 | function collectFields(exeContext, runtimeType, selectionSet, fields, visitedFragmentNames) {
|
3297 | var e_1, _a;
|
3298 | try {
|
3299 | for (var _b = __values(selectionSet.selections), _c = _b.next(); !_c.done; _c = _b.next()) {
|
3300 | var selection = _c.value;
|
3301 | switch (selection.kind) {
|
3302 | case Kind.FIELD: {
|
3303 | if (!shouldIncludeNode(exeContext, selection)) {
|
3304 | continue;
|
3305 | }
|
3306 | var name_1 = getFieldEntryKey(selection);
|
3307 | if (!(name_1 in fields)) {
|
3308 | fields[name_1] = [];
|
3309 | }
|
3310 | fields[name_1].push(selection);
|
3311 | break;
|
3312 | }
|
3313 | case Kind.INLINE_FRAGMENT: {
|
3314 | if (!shouldIncludeNode(exeContext, selection) ||
|
3315 | !doesFragmentConditionMatch(exeContext, selection, runtimeType)) {
|
3316 | continue;
|
3317 | }
|
3318 | collectFields(exeContext, runtimeType, selection.selectionSet, fields, visitedFragmentNames);
|
3319 | break;
|
3320 | }
|
3321 | case Kind.FRAGMENT_SPREAD: {
|
3322 | var fragName = selection.name.value;
|
3323 | if (visitedFragmentNames[fragName] || !shouldIncludeNode(exeContext, selection)) {
|
3324 | continue;
|
3325 | }
|
3326 | visitedFragmentNames[fragName] = true;
|
3327 | var fragment = exeContext.fragments[fragName];
|
3328 | if (!fragment || !doesFragmentConditionMatch(exeContext, fragment, runtimeType)) {
|
3329 | continue;
|
3330 | }
|
3331 | collectFields(exeContext, runtimeType, fragment.selectionSet, fields, visitedFragmentNames);
|
3332 | break;
|
3333 | }
|
3334 | }
|
3335 | }
|
3336 | }
|
3337 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
3338 | finally {
|
3339 | try {
|
3340 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
3341 | }
|
3342 | finally { if (e_1) throw e_1.error; }
|
3343 | }
|
3344 | return fields;
|
3345 | }
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 | function shouldIncludeNode(exeContext, node) {
|
3351 | var skip = getDirectiveValues$1(GraphQLSkipDirective, node, exeContext.variableValues);
|
3352 | if ((skip === null || skip === void 0 ? void 0 : skip.if) === true) {
|
3353 | return false;
|
3354 | }
|
3355 | var include = getDirectiveValues$1(GraphQLIncludeDirective, node, exeContext.variableValues);
|
3356 | if ((include === null || include === void 0 ? void 0 : include.if) === false) {
|
3357 | return false;
|
3358 | }
|
3359 | return true;
|
3360 | }
|
3361 |
|
3362 |
|
3363 |
|
3364 | function doesFragmentConditionMatch(exeContext, fragment, type) {
|
3365 | var typeConditionNode = fragment.typeCondition;
|
3366 | if (!typeConditionNode) {
|
3367 | return true;
|
3368 | }
|
3369 | var conditionalType = typeFromAST(exeContext.schema, typeConditionNode);
|
3370 | if (conditionalType === type) {
|
3371 | return true;
|
3372 | }
|
3373 | if (isAbstractType(conditionalType)) {
|
3374 | return exeContext.schema.isPossibleType(conditionalType, type);
|
3375 | }
|
3376 | return false;
|
3377 | }
|
3378 |
|
3379 |
|
3380 |
|
3381 | function getFieldEntryKey(node) {
|
3382 |
|
3383 | return node.alias ? node.alias.value : node.name.value;
|
3384 | }
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 | function mapAsyncIterator(iterator, callback, rejectCallback) {
|
3391 | var _a;
|
3392 | var $return;
|
3393 | var abruptClose;
|
3394 | if (typeof iterator.return === 'function') {
|
3395 | $return = iterator.return;
|
3396 | abruptClose = function (error) {
|
3397 | var rethrow = function () { return Promise.reject(error); };
|
3398 | return $return.call(iterator).then(rethrow, rethrow);
|
3399 | };
|
3400 | }
|
3401 | function mapResult(result) {
|
3402 | return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
|
3403 | }
|
3404 | var mapReject;
|
3405 | if (rejectCallback) {
|
3406 |
|
3407 | var reject_1 = rejectCallback;
|
3408 | mapReject = function (error) { return asyncMapValue(error, reject_1).then(iteratorResult, abruptClose); };
|
3409 | }
|
3410 | return _a = {
|
3411 | next: function () {
|
3412 | return iterator.next().then(mapResult, mapReject);
|
3413 | },
|
3414 | return: function () {
|
3415 | return $return
|
3416 | ? $return.call(iterator).then(mapResult, mapReject)
|
3417 | : Promise.resolve({ value: undefined, done: true });
|
3418 | },
|
3419 | throw: function (error) {
|
3420 | if (typeof iterator.throw === 'function') {
|
3421 | return iterator.throw(error).then(mapResult, mapReject);
|
3422 | }
|
3423 | return Promise.reject(error).catch(abruptClose);
|
3424 | }
|
3425 | },
|
3426 | _a[Symbol.asyncIterator] = function () {
|
3427 | return this;
|
3428 | },
|
3429 | _a;
|
3430 | }
|
3431 | function asyncMapValue(value, callback) {
|
3432 | return new Promise(function (resolve) { return resolve(callback(value)); });
|
3433 | }
|
3434 | function iteratorResult(value) {
|
3435 | return { value: value, done: false };
|
3436 | }
|
3437 |
|
3438 | function astFromType(type) {
|
3439 | if (isNonNullType(type)) {
|
3440 | var innerType = astFromType(type.ofType);
|
3441 | if (innerType.kind === Kind.NON_NULL_TYPE) {
|
3442 | throw new Error("Invalid type node " + JSON.stringify(type) + ". Inner type of non-null type cannot be a non-null type.");
|
3443 | }
|
3444 | return {
|
3445 | kind: Kind.NON_NULL_TYPE,
|
3446 | type: innerType,
|
3447 | };
|
3448 | }
|
3449 | else if (isListType(type)) {
|
3450 | return {
|
3451 | kind: Kind.LIST_TYPE,
|
3452 | type: astFromType(type.ofType),
|
3453 | };
|
3454 | }
|
3455 | return {
|
3456 | kind: Kind.NAMED_TYPE,
|
3457 | name: {
|
3458 | kind: Kind.NAME,
|
3459 | value: type.name,
|
3460 | },
|
3461 | };
|
3462 | }
|
3463 |
|
3464 | function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap, variableValues, newArg) {
|
3465 | var varName;
|
3466 | var numGeneratedVariables = 0;
|
3467 | do {
|
3468 | varName = "_v" + (numGeneratedVariables++).toString() + "_" + argName;
|
3469 | } while (varName in variableDefinitionsMap);
|
3470 | argumentNodes[argName] = {
|
3471 | kind: Kind.ARGUMENT,
|
3472 | name: {
|
3473 | kind: Kind.NAME,
|
3474 | value: argName,
|
3475 | },
|
3476 | value: {
|
3477 | kind: Kind.VARIABLE,
|
3478 | name: {
|
3479 | kind: Kind.NAME,
|
3480 | value: varName,
|
3481 | },
|
3482 | },
|
3483 | };
|
3484 | variableDefinitionsMap[varName] = {
|
3485 | kind: Kind.VARIABLE_DEFINITION,
|
3486 | variable: {
|
3487 | kind: Kind.VARIABLE,
|
3488 | name: {
|
3489 | kind: Kind.NAME,
|
3490 | value: varName,
|
3491 | },
|
3492 | },
|
3493 | type: astFromType(argType),
|
3494 | };
|
3495 | if (newArg === undefined) {
|
3496 | delete variableValues[varName];
|
3497 | }
|
3498 | else {
|
3499 | variableValues[varName] = newArg;
|
3500 | }
|
3501 | }
|
3502 |
|
3503 | function implementsAbstractType(schema, typeA, typeB) {
|
3504 | if (typeA === typeB) {
|
3505 | return true;
|
3506 | }
|
3507 | else if (isCompositeType(typeA) && isCompositeType(typeB)) {
|
3508 | return doTypesOverlap(schema, typeA, typeB);
|
3509 | }
|
3510 | return false;
|
3511 | }
|
3512 |
|
3513 | function relocatedError(originalError, path) {
|
3514 | return new GraphQLError(originalError.message, originalError.nodes, originalError.source, originalError.positions, path === null ? undefined : path === undefined ? originalError.path : path, originalError.originalError, originalError.extensions);
|
3515 | }
|
3516 |
|
3517 | function inputFieldToFieldConfig(field) {
|
3518 | return {
|
3519 | description: field.description,
|
3520 | type: field.type,
|
3521 | defaultValue: field.defaultValue,
|
3522 | extensions: field.extensions,
|
3523 | astNode: field.astNode,
|
3524 | };
|
3525 | }
|
3526 | function fieldToFieldConfig(field) {
|
3527 | return {
|
3528 | description: field.description,
|
3529 | type: field.type,
|
3530 | args: argsToFieldConfigArgumentMap(field.args),
|
3531 | resolve: field.resolve,
|
3532 | subscribe: field.subscribe,
|
3533 | deprecationReason: field.deprecationReason,
|
3534 | extensions: field.extensions,
|
3535 | astNode: field.astNode,
|
3536 | };
|
3537 | }
|
3538 | function argsToFieldConfigArgumentMap(args) {
|
3539 | var newArguments = {};
|
3540 | args.forEach(function (arg) {
|
3541 | newArguments[arg.name] = argumentToArgumentConfig(arg);
|
3542 | });
|
3543 | return newArguments;
|
3544 | }
|
3545 | function argumentToArgumentConfig(arg) {
|
3546 | return {
|
3547 | description: arg.description,
|
3548 | type: arg.type,
|
3549 | defaultValue: arg.defaultValue,
|
3550 | extensions: arg.extensions,
|
3551 | astNode: arg.astNode,
|
3552 | };
|
3553 | }
|
3554 |
|
3555 | function observableToAsyncIterable(observable) {
|
3556 | var _a;
|
3557 | var pullQueue = [];
|
3558 | var pushQueue = [];
|
3559 | var listening = true;
|
3560 | var pushValue = function (value) {
|
3561 | if (pullQueue.length !== 0) {
|
3562 | pullQueue.shift()({ value: value, done: false });
|
3563 | }
|
3564 | else {
|
3565 | pushQueue.push({ value: value });
|
3566 | }
|
3567 | };
|
3568 | var pushError = function (error) {
|
3569 | if (pullQueue.length !== 0) {
|
3570 | pullQueue.shift()({ value: { errors: [error] }, done: false });
|
3571 | }
|
3572 | else {
|
3573 | pushQueue.push({ value: { errors: [error] } });
|
3574 | }
|
3575 | };
|
3576 | var pullValue = function () {
|
3577 | return new Promise(function (resolve) {
|
3578 | if (pushQueue.length !== 0) {
|
3579 | var element = pushQueue.shift();
|
3580 |
|
3581 | resolve(__assign(__assign({}, element), { done: false }));
|
3582 | }
|
3583 | else {
|
3584 | pullQueue.push(resolve);
|
3585 | }
|
3586 | });
|
3587 | };
|
3588 | var subscription = observable.subscribe({
|
3589 | next: function (value) {
|
3590 | pushValue(value);
|
3591 | },
|
3592 | error: function (err) {
|
3593 | pushError(err);
|
3594 | },
|
3595 | });
|
3596 | var emptyQueue = function () {
|
3597 | if (listening) {
|
3598 | listening = false;
|
3599 | subscription.unsubscribe();
|
3600 | pullQueue.forEach(function (resolve) { return resolve({ value: undefined, done: true }); });
|
3601 | pullQueue.length = 0;
|
3602 | pushQueue.length = 0;
|
3603 | }
|
3604 | };
|
3605 | return _a = {
|
3606 | next: function () {
|
3607 | return listening ? pullValue() : this.return();
|
3608 | },
|
3609 | return: function () {
|
3610 | emptyQueue();
|
3611 | return Promise.resolve({ value: undefined, done: true });
|
3612 | },
|
3613 | throw: function (error) {
|
3614 | emptyQueue();
|
3615 | return Promise.reject(error);
|
3616 | }
|
3617 | },
|
3618 | _a[Symbol.asyncIterator] = function () {
|
3619 | return this;
|
3620 | },
|
3621 | _a;
|
3622 | }
|
3623 |
|
3624 | function visitData(data, enter, leave) {
|
3625 | if (Array.isArray(data)) {
|
3626 | return data.map(function (value) { return visitData(value, enter, leave); });
|
3627 | }
|
3628 | else if (typeof data === 'object') {
|
3629 | var newData_1 = enter != null ? enter(data) : data;
|
3630 | if (newData_1 != null) {
|
3631 | Object.keys(newData_1).forEach(function (key) {
|
3632 | var value = newData_1[key];
|
3633 | newData_1[key] = visitData(value, enter, leave);
|
3634 | });
|
3635 | }
|
3636 | return leave != null ? leave(newData_1) : newData_1;
|
3637 | }
|
3638 | return data;
|
3639 | }
|
3640 | function visitErrors(errors, visitor) {
|
3641 | return errors.map(function (error) { return visitor(error); });
|
3642 | }
|
3643 | function visitResult(result, request, schema, resultVisitorMap, errorVisitorMap) {
|
3644 | var partialExecutionContext = {
|
3645 | schema: schema,
|
3646 | fragments: request.document.definitions.reduce(function (acc, def) {
|
3647 | if (def.kind === Kind.FRAGMENT_DEFINITION) {
|
3648 | acc[def.name.value] = def;
|
3649 | }
|
3650 | return acc;
|
3651 | }, {}),
|
3652 | variableValues: request.variables,
|
3653 | };
|
3654 | var errorInfo = {
|
3655 | segmentInfoMap: new Map(),
|
3656 | unpathedErrors: new Set(),
|
3657 | };
|
3658 | var data = result.data;
|
3659 | var errors = result.errors;
|
3660 | var visitingErrors = errors != null && errorVisitorMap != null;
|
3661 | if (data != null) {
|
3662 | result.data = visitRoot(data, getOperationAST(request.document, undefined), partialExecutionContext, resultVisitorMap, visitingErrors ? errors : undefined, errorInfo);
|
3663 | }
|
3664 | if (visitingErrors) {
|
3665 | result.errors = visitErrorsByType(errors, errorVisitorMap, errorInfo);
|
3666 | }
|
3667 | return result;
|
3668 | }
|
3669 | function visitErrorsByType(errors, errorVisitorMap, errorInfo) {
|
3670 | var segmentInfoMap = errorInfo.segmentInfoMap;
|
3671 | var unpathedErrors = errorInfo.unpathedErrors;
|
3672 | var unpathedErrorVisitor = errorVisitorMap['__unpathed'];
|
3673 | return errors.map(function (originalError) {
|
3674 | var pathSegmentsInfo = segmentInfoMap.get(originalError);
|
3675 | var newError = pathSegmentsInfo == null
|
3676 | ? originalError
|
3677 | : pathSegmentsInfo.reduceRight(function (acc, segmentInfo) {
|
3678 | var typeName = segmentInfo.type.name;
|
3679 | var typeVisitorMap = errorVisitorMap[typeName];
|
3680 | if (typeVisitorMap == null) {
|
3681 | return acc;
|
3682 | }
|
3683 | var errorVisitor = typeVisitorMap[segmentInfo.fieldName];
|
3684 | return errorVisitor == null ? acc : errorVisitor(acc, segmentInfo.pathIndex);
|
3685 | }, originalError);
|
3686 | if (unpathedErrorVisitor && unpathedErrors.has(originalError)) {
|
3687 | return unpathedErrorVisitor(newError);
|
3688 | }
|
3689 | return newError;
|
3690 | });
|
3691 | }
|
3692 | function visitRoot(root, operation, exeContext, resultVisitorMap, errors, errorInfo) {
|
3693 | var operationRootType = getOperationRootType(exeContext.schema, operation);
|
3694 | var collectedFields = collectFields(exeContext, operationRootType, operation.selectionSet, Object.create(null), Object.create(null));
|
3695 | return visitObjectValue(root, operationRootType, collectedFields, exeContext, resultVisitorMap, 0, errors, errorInfo);
|
3696 | }
|
3697 | function visitObjectValue(object, type, fieldNodeMap, exeContext, resultVisitorMap, pathIndex, errors, errorInfo) {
|
3698 | var fieldMap = type.getFields();
|
3699 | var typeVisitorMap = resultVisitorMap === null || resultVisitorMap === void 0 ? void 0 : resultVisitorMap[type.name];
|
3700 | var enterObject = typeVisitorMap === null || typeVisitorMap === void 0 ? void 0 : typeVisitorMap.__enter;
|
3701 | var newObject = enterObject != null ? enterObject(object) : object;
|
3702 | var sortedErrors;
|
3703 | var errorMap;
|
3704 | if (errors != null) {
|
3705 | sortedErrors = sortErrorsByPathSegment(errors, pathIndex);
|
3706 | errorMap = sortedErrors.errorMap;
|
3707 | sortedErrors.unpathedErrors.forEach(function (error) { return errorInfo.unpathedErrors.add(error); });
|
3708 | }
|
3709 | Object.keys(fieldNodeMap).forEach(function (responseKey) {
|
3710 | var subFieldNodes = fieldNodeMap[responseKey];
|
3711 | var fieldName = subFieldNodes[0].name.value;
|
3712 | var fieldType = fieldMap[fieldName].type;
|
3713 | var newPathIndex = pathIndex + 1;
|
3714 | var fieldErrors;
|
3715 | if (errors != null) {
|
3716 | fieldErrors = errorMap[responseKey];
|
3717 | if (fieldErrors != null) {
|
3718 | delete errorMap[responseKey];
|
3719 | }
|
3720 | addPathSegmentInfo(type, fieldName, newPathIndex, fieldErrors, errorInfo);
|
3721 | }
|
3722 | var newValue = visitFieldValue(object[responseKey], fieldType, subFieldNodes, exeContext, resultVisitorMap, newPathIndex, fieldErrors, errorInfo);
|
3723 | updateObject(newObject, responseKey, newValue, typeVisitorMap, fieldName);
|
3724 | });
|
3725 | var oldTypename = newObject.__typename;
|
3726 | if (oldTypename != null) {
|
3727 | updateObject(newObject, '__typename', oldTypename, typeVisitorMap, '__typename');
|
3728 | }
|
3729 | if (errors != null) {
|
3730 | Object.keys(errorMap).forEach(function (unknownResponseKey) {
|
3731 | errorMap[unknownResponseKey].forEach(function (error) { return errorInfo.unpathedErrors.add(error); });
|
3732 | });
|
3733 | }
|
3734 | var leaveObject = typeVisitorMap === null || typeVisitorMap === void 0 ? void 0 : typeVisitorMap.__leave;
|
3735 | return leaveObject != null ? leaveObject(newObject) : newObject;
|
3736 | }
|
3737 | function updateObject(object, responseKey, newValue, typeVisitorMap, fieldName) {
|
3738 | if (typeVisitorMap == null) {
|
3739 | object[responseKey] = newValue;
|
3740 | return;
|
3741 | }
|
3742 | var fieldVisitor = typeVisitorMap[fieldName];
|
3743 | if (fieldVisitor == null) {
|
3744 | object[responseKey] = newValue;
|
3745 | return;
|
3746 | }
|
3747 | var visitedValue = fieldVisitor(newValue);
|
3748 | if (visitedValue === undefined) {
|
3749 | delete object[responseKey];
|
3750 | return;
|
3751 | }
|
3752 | object[responseKey] = visitedValue;
|
3753 | }
|
3754 | function visitListValue(list, returnType, fieldNodes, exeContext, resultVisitorMap, pathIndex, errors, errorInfo) {
|
3755 | return list.map(function (listMember) {
|
3756 | return visitFieldValue(listMember, returnType, fieldNodes, exeContext, resultVisitorMap, pathIndex + 1, errors, errorInfo);
|
3757 | });
|
3758 | }
|
3759 | function visitFieldValue(value, returnType, fieldNodes, exeContext, resultVisitorMap, pathIndex, errors, errorInfo) {
|
3760 | if (errors === void 0) { errors = []; }
|
3761 | if (value == null) {
|
3762 | return value;
|
3763 | }
|
3764 | var nullableType = getNullableType(returnType);
|
3765 | if (isListType(nullableType)) {
|
3766 | return visitListValue(value, nullableType.ofType, fieldNodes, exeContext, resultVisitorMap, pathIndex, errors, errorInfo);
|
3767 | }
|
3768 | else if (isAbstractType(nullableType)) {
|
3769 | var finalType = exeContext.schema.getType(value.__typename);
|
3770 | var collectedFields = collectSubFields(exeContext, finalType, fieldNodes);
|
3771 | return visitObjectValue(value, finalType, collectedFields, exeContext, resultVisitorMap, pathIndex, errors, errorInfo);
|
3772 | }
|
3773 | else if (isObjectType(nullableType)) {
|
3774 | var collectedFields = collectSubFields(exeContext, nullableType, fieldNodes);
|
3775 | return visitObjectValue(value, nullableType, collectedFields, exeContext, resultVisitorMap, pathIndex, errors, errorInfo);
|
3776 | }
|
3777 | var typeVisitorMap = resultVisitorMap === null || resultVisitorMap === void 0 ? void 0 : resultVisitorMap[nullableType.name];
|
3778 | if (typeVisitorMap == null) {
|
3779 | return value;
|
3780 | }
|
3781 | var visitedValue = typeVisitorMap(value);
|
3782 | return visitedValue === undefined ? value : visitedValue;
|
3783 | }
|
3784 | function sortErrorsByPathSegment(errors, pathIndex) {
|
3785 | var errorMap = Object.create(null);
|
3786 | var unpathedErrors = new Set();
|
3787 | errors.forEach(function (error) {
|
3788 | var _a;
|
3789 | var pathSegment = (_a = error.path) === null || _a === void 0 ? void 0 : _a[pathIndex];
|
3790 | if (pathSegment == null) {
|
3791 | unpathedErrors.add(error);
|
3792 | return;
|
3793 | }
|
3794 | if (pathSegment in errorMap) {
|
3795 | errorMap[pathSegment].push(error);
|
3796 | }
|
3797 | else {
|
3798 | errorMap[pathSegment] = [error];
|
3799 | }
|
3800 | });
|
3801 | return {
|
3802 | errorMap: errorMap,
|
3803 | unpathedErrors: unpathedErrors,
|
3804 | };
|
3805 | }
|
3806 | function addPathSegmentInfo(type, fieldName, pathIndex, errors, errorInfo) {
|
3807 | if (errors === void 0) { errors = []; }
|
3808 | errors.forEach(function (error) {
|
3809 | var segmentInfo = {
|
3810 | type: type,
|
3811 | fieldName: fieldName,
|
3812 | pathIndex: pathIndex,
|
3813 | };
|
3814 | var pathSegmentsInfo = errorInfo.segmentInfoMap.get(error);
|
3815 | if (pathSegmentsInfo == null) {
|
3816 | errorInfo.segmentInfoMap.set(error, [segmentInfo]);
|
3817 | }
|
3818 | else {
|
3819 | pathSegmentsInfo.push(segmentInfo);
|
3820 | }
|
3821 | });
|
3822 | }
|
3823 | function collectSubFields(exeContext, type, fieldNodes) {
|
3824 | var subFieldNodes = Object.create(null);
|
3825 | var visitedFragmentNames = Object.create(null);
|
3826 | fieldNodes.forEach(function (fieldNode) {
|
3827 | subFieldNodes = collectFields(exeContext, type, fieldNode.selectionSet, subFieldNodes, visitedFragmentNames);
|
3828 | });
|
3829 | return subFieldNodes;
|
3830 | }
|
3831 |
|
3832 | function valueMatchesCriteria(value, criteria) {
|
3833 | if (value == null) {
|
3834 | return value === criteria;
|
3835 | }
|
3836 | else if (Array.isArray(value)) {
|
3837 | return Array.isArray(criteria) && value.every(function (val, index) { return valueMatchesCriteria(val, criteria[index]); });
|
3838 | }
|
3839 | else if (typeof value === 'object') {
|
3840 | return (typeof criteria === 'object' &&
|
3841 | criteria &&
|
3842 | Object.keys(criteria).every(function (propertyName) { return valueMatchesCriteria(value[propertyName], criteria[propertyName]); }));
|
3843 | }
|
3844 | else if (criteria instanceof RegExp) {
|
3845 | return criteria.test(value);
|
3846 | }
|
3847 | return value === criteria;
|
3848 | }
|
3849 |
|
3850 | function isAsyncIterable(value) {
|
3851 | return Symbol.asyncIterator in value;
|
3852 | }
|
3853 |
|
3854 | export { MapperKind, SchemaDirectiveVisitor, SchemaVisitor, VisitSchemaKind, addTypes, appendObjectFields, argsToFieldConfigArgumentMap, argumentToArgumentConfig, asArray, buildOperationNodeForField, checkValidationErrors, cloneDirective, cloneSchema, cloneType, collectFields, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, debugLog, fieldToFieldConfig, filterSchema, fixSchemaAst, fixWindowsPath, flattenArray, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDirectives, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, inputFieldToFieldConfig, isAsyncIterable, isDescribable, isDocumentString, isEqual, isNamedStub, isNotEqual, isValidPath, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, visitSchema };
|
3855 |
|