1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const tslib = require('tslib');
|
6 | const graphql = require('graphql');
|
7 | const utils = require('@graphql-tools/utils/es5');
|
8 | const delegate = require('@graphql-tools/delegate/es5');
|
9 | const valueOrPromise = require('value-or-promise');
|
10 |
|
11 | function generateProxyingResolvers(subschemaConfig) {
|
12 | var _a;
|
13 | var targetSchema = subschemaConfig.schema;
|
14 | var createProxyingResolver = (_a = subschemaConfig.createProxyingResolver) !== null && _a !== void 0 ? _a : defaultCreateProxyingResolver;
|
15 | var transformedSchema = delegate.applySchemaTransforms(targetSchema, subschemaConfig);
|
16 | var operationTypes = {
|
17 | query: targetSchema.getQueryType(),
|
18 | mutation: targetSchema.getMutationType(),
|
19 | subscription: targetSchema.getSubscriptionType(),
|
20 | };
|
21 | var resolvers = {};
|
22 | Object.keys(operationTypes).forEach(function (operation) {
|
23 | var rootType = operationTypes[operation];
|
24 | if (rootType != null) {
|
25 | var typeName_1 = rootType.name;
|
26 | var fields = rootType.getFields();
|
27 | resolvers[typeName_1] = {};
|
28 | Object.keys(fields).forEach(function (fieldName) {
|
29 | var proxyingResolver = createProxyingResolver({
|
30 | subschemaConfig: subschemaConfig,
|
31 | transformedSchema: transformedSchema,
|
32 | operation: operation,
|
33 | fieldName: fieldName,
|
34 | });
|
35 | var finalResolver = createPossiblyNestedProxyingResolver(subschemaConfig, proxyingResolver);
|
36 | if (operation === 'subscription') {
|
37 | resolvers[typeName_1][fieldName] = {
|
38 | subscribe: finalResolver,
|
39 | resolve: function (payload, _, __, _a) {
|
40 | var targetFieldName = _a.fieldName;
|
41 | return payload[targetFieldName];
|
42 | },
|
43 | };
|
44 | }
|
45 | else {
|
46 | resolvers[typeName_1][fieldName] = {
|
47 | resolve: finalResolver,
|
48 | };
|
49 | }
|
50 | });
|
51 | }
|
52 | });
|
53 | return resolvers;
|
54 | }
|
55 | function createPossiblyNestedProxyingResolver(subschemaConfig, proxyingResolver) {
|
56 | return function (parent, args, context, info) {
|
57 | if (parent != null) {
|
58 | var responseKey = utils.getResponseKeyFromInfo(info);
|
59 |
|
60 | if (delegate.isExternalObject(parent)) {
|
61 | var unpathedErrors = delegate.getUnpathedErrors(parent);
|
62 | var subschema = delegate.getSubschema(parent, responseKey);
|
63 |
|
64 |
|
65 |
|
66 | if (subschemaConfig === subschema && parent[responseKey] !== undefined) {
|
67 | return delegate.resolveExternalValue(parent[responseKey], unpathedErrors, subschema, context, info);
|
68 | }
|
69 | }
|
70 | }
|
71 | return proxyingResolver(parent, args, context, info);
|
72 | };
|
73 | }
|
74 | function defaultCreateProxyingResolver(_a) {
|
75 | var subschemaConfig = _a.subschemaConfig, operation = _a.operation, transformedSchema = _a.transformedSchema;
|
76 | return function (_parent, _args, context, info) {
|
77 | return delegate.delegateToSchema({
|
78 | schema: subschemaConfig,
|
79 | operation: operation,
|
80 | context: context,
|
81 | info: info,
|
82 | transformedSchema: transformedSchema,
|
83 | });
|
84 | };
|
85 | }
|
86 |
|
87 | function wrapSchema(subschemaConfig) {
|
88 | var targetSchema = subschemaConfig.schema;
|
89 | var proxyingResolvers = generateProxyingResolvers(subschemaConfig);
|
90 | var schema = createWrappingSchema(targetSchema, proxyingResolvers);
|
91 | var transformedSchema = delegate.applySchemaTransforms(schema, subschemaConfig);
|
92 | return delegate.applySchemaTransforms(schema, subschemaConfig, transformedSchema);
|
93 | }
|
94 | function createWrappingSchema(schema, proxyingResolvers) {
|
95 | var _a;
|
96 | return utils.mapSchema(schema, (_a = {},
|
97 | _a[utils.MapperKind.ROOT_OBJECT] = function (type) {
|
98 | var config = type.toConfig();
|
99 | var fieldConfigMap = config.fields;
|
100 | Object.keys(fieldConfigMap).forEach(function (fieldName) {
|
101 | fieldConfigMap[fieldName] = tslib.__assign(tslib.__assign({}, fieldConfigMap[fieldName]), proxyingResolvers[type.name][fieldName]);
|
102 | });
|
103 | return new graphql.GraphQLObjectType(config);
|
104 | },
|
105 | _a[utils.MapperKind.OBJECT_TYPE] = function (type) {
|
106 | var config = type.toConfig();
|
107 | config.isTypeOf = undefined;
|
108 | Object.keys(config.fields).forEach(function (fieldName) {
|
109 | config.fields[fieldName].resolve = delegate.defaultMergedResolver;
|
110 | config.fields[fieldName].subscribe = null;
|
111 | });
|
112 | return new graphql.GraphQLObjectType(config);
|
113 | },
|
114 | _a[utils.MapperKind.INTERFACE_TYPE] = function (type) {
|
115 | var config = type.toConfig();
|
116 | delete config.resolveType;
|
117 | return new graphql.GraphQLInterfaceType(config);
|
118 | },
|
119 | _a[utils.MapperKind.UNION_TYPE] = function (type) {
|
120 | var config = type.toConfig();
|
121 | delete config.resolveType;
|
122 | return new graphql.GraphQLUnionType(config);
|
123 | },
|
124 | _a));
|
125 | }
|
126 |
|
127 | var RenameTypes = (function () {
|
128 | function RenameTypes(renamer, options) {
|
129 | this.renamer = renamer;
|
130 | this.map = Object.create(null);
|
131 | this.reverseMap = Object.create(null);
|
132 | var _a = options != null ? options : {}, _b = _a.renameBuiltins, renameBuiltins = _b === void 0 ? false : _b, _c = _a.renameScalars, renameScalars = _c === void 0 ? true : _c;
|
133 | this.renameBuiltins = renameBuiltins;
|
134 | this.renameScalars = renameScalars;
|
135 | }
|
136 | RenameTypes.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
137 | var _a;
|
138 | var _this = this;
|
139 | return utils.mapSchema(originalWrappingSchema, (_a = {},
|
140 | _a[utils.MapperKind.TYPE] = function (type) {
|
141 | if (graphql.isSpecifiedScalarType(type) && !_this.renameBuiltins) {
|
142 | return undefined;
|
143 | }
|
144 | if (graphql.isScalarType(type) && !_this.renameScalars) {
|
145 | return undefined;
|
146 | }
|
147 | var oldName = type.name;
|
148 | var newName = _this.renamer(oldName);
|
149 | if (newName !== undefined && newName !== oldName) {
|
150 | _this.map[oldName] = newName;
|
151 | _this.reverseMap[newName] = oldName;
|
152 | return utils.renameType(type, newName);
|
153 | }
|
154 | },
|
155 | _a[utils.MapperKind.ROOT_OBJECT] = function () {
|
156 | return undefined;
|
157 | },
|
158 | _a));
|
159 | };
|
160 | RenameTypes.prototype.transformRequest = function (originalRequest, _delegationContext, _transformationContext) {
|
161 | var _a;
|
162 | var _this = this;
|
163 | var document = graphql.visit(originalRequest.document, (_a = {},
|
164 | _a[graphql.Kind.NAMED_TYPE] = function (node) {
|
165 | var name = node.name.value;
|
166 | if (name in _this.reverseMap) {
|
167 | return tslib.__assign(tslib.__assign({}, node), { name: {
|
168 | kind: graphql.Kind.NAME,
|
169 | value: _this.reverseMap[name],
|
170 | } });
|
171 | }
|
172 | },
|
173 | _a));
|
174 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: document });
|
175 | };
|
176 | RenameTypes.prototype.transformResult = function (originalResult, _delegationContext, _transformationContext) {
|
177 | var _this = this;
|
178 | return tslib.__assign(tslib.__assign({}, originalResult), { data: utils.visitData(originalResult.data, function (object) {
|
179 | var typeName = object === null || object === void 0 ? void 0 : object.__typename;
|
180 | if (typeName != null && typeName in _this.map) {
|
181 | object.__typename = _this.map[typeName];
|
182 | }
|
183 | return object;
|
184 | }) });
|
185 | };
|
186 | return RenameTypes;
|
187 | }());
|
188 |
|
189 | var FilterTypes = (function () {
|
190 | function FilterTypes(filter) {
|
191 | this.filter = filter;
|
192 | }
|
193 | FilterTypes.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
194 | var _a;
|
195 | var _this = this;
|
196 | return utils.mapSchema(originalWrappingSchema, (_a = {},
|
197 | _a[utils.MapperKind.TYPE] = function (type) {
|
198 | if (_this.filter(type)) {
|
199 | return undefined;
|
200 | }
|
201 | return null;
|
202 | },
|
203 | _a));
|
204 | };
|
205 | return FilterTypes;
|
206 | }());
|
207 |
|
208 | var RenameRootTypes = (function () {
|
209 | function RenameRootTypes(renamer) {
|
210 | this.renamer = renamer;
|
211 | this.map = Object.create(null);
|
212 | this.reverseMap = Object.create(null);
|
213 | }
|
214 | RenameRootTypes.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
215 | var _a;
|
216 | var _this = this;
|
217 | return utils.mapSchema(originalWrappingSchema, (_a = {},
|
218 | _a[utils.MapperKind.ROOT_OBJECT] = function (type) {
|
219 | var oldName = type.name;
|
220 | var newName = _this.renamer(oldName);
|
221 | if (newName !== undefined && newName !== oldName) {
|
222 | _this.map[oldName] = newName;
|
223 | _this.reverseMap[newName] = oldName;
|
224 | return utils.renameType(type, newName);
|
225 | }
|
226 | },
|
227 | _a));
|
228 | };
|
229 | RenameRootTypes.prototype.transformRequest = function (originalRequest, _delegationContext, _transformationContext) {
|
230 | var _a;
|
231 | var _this = this;
|
232 | var document = graphql.visit(originalRequest.document, (_a = {},
|
233 | _a[graphql.Kind.NAMED_TYPE] = function (node) {
|
234 | var name = node.name.value;
|
235 | if (name in _this.reverseMap) {
|
236 | return tslib.__assign(tslib.__assign({}, node), { name: {
|
237 | kind: graphql.Kind.NAME,
|
238 | value: _this.reverseMap[name],
|
239 | } });
|
240 | }
|
241 | },
|
242 | _a));
|
243 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: document });
|
244 | };
|
245 | RenameRootTypes.prototype.transformResult = function (originalResult, _delegationContext, _transformationContext) {
|
246 | var _this = this;
|
247 | return tslib.__assign(tslib.__assign({}, originalResult), { data: utils.visitData(originalResult.data, function (object) {
|
248 | var typeName = object === null || object === void 0 ? void 0 : object.__typename;
|
249 | if (typeName != null && typeName in _this.map) {
|
250 | object.__typename = _this.map[typeName];
|
251 | }
|
252 | return object;
|
253 | }) });
|
254 | };
|
255 | return RenameRootTypes;
|
256 | }());
|
257 |
|
258 | var TransformCompositeFields = (function () {
|
259 | function TransformCompositeFields(fieldTransformer, fieldNodeTransformer, dataTransformer, errorsTransformer) {
|
260 | this.fieldTransformer = fieldTransformer;
|
261 | this.fieldNodeTransformer = fieldNodeTransformer;
|
262 | this.dataTransformer = dataTransformer;
|
263 | this.errorsTransformer = errorsTransformer;
|
264 | this.mapping = {};
|
265 | }
|
266 | TransformCompositeFields.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
267 | var _a;
|
268 | var _this = this;
|
269 | var _b;
|
270 | this.transformedSchema = utils.mapSchema(originalWrappingSchema, (_a = {},
|
271 | _a[utils.MapperKind.COMPOSITE_FIELD] = function (fieldConfig, fieldName, typeName) {
|
272 | var transformedField = _this.fieldTransformer(typeName, fieldName, fieldConfig);
|
273 | if (Array.isArray(transformedField)) {
|
274 | var newFieldName = transformedField[0];
|
275 | if (newFieldName !== fieldName) {
|
276 | if (!(typeName in _this.mapping)) {
|
277 | _this.mapping[typeName] = {};
|
278 | }
|
279 | _this.mapping[typeName][newFieldName] = fieldName;
|
280 | }
|
281 | }
|
282 | return transformedField;
|
283 | },
|
284 | _a));
|
285 | this.typeInfo = new graphql.TypeInfo(this.transformedSchema);
|
286 | this.subscriptionTypeName = (_b = originalWrappingSchema.getSubscriptionType()) === null || _b === void 0 ? void 0 : _b.name;
|
287 | return this.transformedSchema;
|
288 | };
|
289 | TransformCompositeFields.prototype.transformRequest = function (originalRequest, _delegationContext, transformationContext) {
|
290 | var document = originalRequest.document;
|
291 | var fragments = Object.create(null);
|
292 | document.definitions.forEach(function (def) {
|
293 | if (def.kind === graphql.Kind.FRAGMENT_DEFINITION) {
|
294 | fragments[def.name.value] = def;
|
295 | }
|
296 | });
|
297 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: this.transformDocument(document, fragments, transformationContext) });
|
298 | };
|
299 | TransformCompositeFields.prototype.transformResult = function (result, _delegationContext, transformationContext) {
|
300 | var _this = this;
|
301 | if (this.dataTransformer != null) {
|
302 | result.data = utils.visitData(result.data, function (value) { return _this.dataTransformer(value, transformationContext); });
|
303 | }
|
304 | if (this.errorsTransformer != null) {
|
305 | result.errors = this.errorsTransformer(result.errors, transformationContext);
|
306 | }
|
307 | return result;
|
308 | };
|
309 | TransformCompositeFields.prototype.transformDocument = function (document, fragments, transformationContext) {
|
310 | var _a;
|
311 | var _this = this;
|
312 | return graphql.visit(document, graphql.visitWithTypeInfo(this.typeInfo, {
|
313 | leave: (_a = {},
|
314 | _a[graphql.Kind.SELECTION_SET] = function (node) {
|
315 | return _this.transformSelectionSet(node, _this.typeInfo, fragments, transformationContext);
|
316 | },
|
317 | _a),
|
318 | }));
|
319 | };
|
320 | TransformCompositeFields.prototype.transformSelectionSet = function (node, typeInfo, fragments, transformationContext) {
|
321 | var _this = this;
|
322 | var parentType = typeInfo.getParentType();
|
323 | if (parentType == null) {
|
324 | return undefined;
|
325 | }
|
326 | var parentTypeName = parentType.name;
|
327 | var newSelections = [];
|
328 | node.selections.forEach(function (selection) {
|
329 | var _a, _b;
|
330 | if (selection.kind !== graphql.Kind.FIELD) {
|
331 | newSelections.push(selection);
|
332 | return;
|
333 | }
|
334 | var newName = selection.name.value;
|
335 |
|
336 | if ((_this.dataTransformer != null || _this.errorsTransformer != null) &&
|
337 | (_this.subscriptionTypeName == null || parentTypeName !== _this.subscriptionTypeName)) {
|
338 | newSelections.push({
|
339 | kind: graphql.Kind.FIELD,
|
340 | name: {
|
341 | kind: graphql.Kind.NAME,
|
342 | value: '__typename',
|
343 | },
|
344 | });
|
345 | }
|
346 | var transformedSelection;
|
347 | if (_this.fieldNodeTransformer == null) {
|
348 | transformedSelection = selection;
|
349 | }
|
350 | else {
|
351 | transformedSelection = _this.fieldNodeTransformer(parentTypeName, newName, selection, fragments, transformationContext);
|
352 | transformedSelection = transformedSelection === undefined ? selection : transformedSelection;
|
353 | }
|
354 | if (transformedSelection == null) {
|
355 | return;
|
356 | }
|
357 | else if (Array.isArray(transformedSelection)) {
|
358 | newSelections = newSelections.concat(transformedSelection);
|
359 | return;
|
360 | }
|
361 | else if (transformedSelection.kind !== graphql.Kind.FIELD) {
|
362 | newSelections.push(transformedSelection);
|
363 | return;
|
364 | }
|
365 | var typeMapping = _this.mapping[parentTypeName];
|
366 | if (typeMapping == null) {
|
367 | newSelections.push(transformedSelection);
|
368 | return;
|
369 | }
|
370 | var oldName = _this.mapping[parentTypeName][newName];
|
371 | if (oldName == null) {
|
372 | newSelections.push(transformedSelection);
|
373 | return;
|
374 | }
|
375 | newSelections.push(tslib.__assign(tslib.__assign({}, transformedSelection), { name: {
|
376 | kind: graphql.Kind.NAME,
|
377 | value: oldName,
|
378 | }, alias: {
|
379 | kind: graphql.Kind.NAME,
|
380 | value: (_b = (_a = transformedSelection.alias) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : newName,
|
381 | } }));
|
382 | });
|
383 | return tslib.__assign(tslib.__assign({}, node), { selections: newSelections });
|
384 | };
|
385 | return TransformCompositeFields;
|
386 | }());
|
387 |
|
388 | var TransformObjectFields = (function () {
|
389 | function TransformObjectFields(objectFieldTransformer, fieldNodeTransformer) {
|
390 | this.objectFieldTransformer = objectFieldTransformer;
|
391 | this.fieldNodeTransformer = fieldNodeTransformer;
|
392 | }
|
393 | TransformObjectFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
394 | var _this = this;
|
395 | var compositeToObjectFieldTransformer = function (typeName, fieldName, fieldConfig) {
|
396 | if (graphql.isObjectType(originalWrappingSchema.getType(typeName))) {
|
397 | return _this.objectFieldTransformer(typeName, fieldName, fieldConfig);
|
398 | }
|
399 | return undefined;
|
400 | };
|
401 | this.transformer = new TransformCompositeFields(compositeToObjectFieldTransformer, this.fieldNodeTransformer);
|
402 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
403 | };
|
404 | TransformObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
405 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
406 | };
|
407 | TransformObjectFields.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
408 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
409 | };
|
410 | return TransformObjectFields;
|
411 | }());
|
412 |
|
413 | var TransformRootFields = (function () {
|
414 | function TransformRootFields(rootFieldTransformer, fieldNodeTransformer) {
|
415 | this.rootFieldTransformer = rootFieldTransformer;
|
416 | this.fieldNodeTransformer = fieldNodeTransformer;
|
417 | }
|
418 | TransformRootFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
419 | var _this = this;
|
420 | var _a, _b, _c;
|
421 | var queryTypeName = (_a = originalWrappingSchema.getQueryType()) === null || _a === void 0 ? void 0 : _a.name;
|
422 | var mutationTypeName = (_b = originalWrappingSchema.getMutationType()) === null || _b === void 0 ? void 0 : _b.name;
|
423 | var subscriptionTypeName = (_c = originalWrappingSchema.getSubscriptionType()) === null || _c === void 0 ? void 0 : _c.name;
|
424 | var rootToObjectFieldTransformer = function (typeName, fieldName, fieldConfig) {
|
425 | if (typeName === queryTypeName) {
|
426 | return _this.rootFieldTransformer('Query', fieldName, fieldConfig);
|
427 | }
|
428 | if (typeName === mutationTypeName) {
|
429 | return _this.rootFieldTransformer('Mutation', fieldName, fieldConfig);
|
430 | }
|
431 | if (typeName === subscriptionTypeName) {
|
432 | return _this.rootFieldTransformer('Subscription', fieldName, fieldConfig);
|
433 | }
|
434 | return undefined;
|
435 | };
|
436 | this.transformer = new TransformObjectFields(rootToObjectFieldTransformer, this.fieldNodeTransformer);
|
437 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
438 | };
|
439 | TransformRootFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
440 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
441 | };
|
442 | TransformRootFields.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
443 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
444 | };
|
445 | return TransformRootFields;
|
446 | }());
|
447 |
|
448 | var RenameRootFields = (function () {
|
449 | function RenameRootFields(renamer) {
|
450 | this.transformer = new TransformRootFields(function (operation, fieldName, fieldConfig) { return [renamer(operation, fieldName, fieldConfig), fieldConfig]; });
|
451 | }
|
452 | RenameRootFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
453 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
454 | };
|
455 | RenameRootFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
456 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
457 | };
|
458 | return RenameRootFields;
|
459 | }());
|
460 |
|
461 | var FilterRootFields = (function () {
|
462 | function FilterRootFields(filter) {
|
463 | this.transformer = new TransformRootFields(function (operation, fieldName, fieldConfig) {
|
464 | if (filter(operation, fieldName, fieldConfig)) {
|
465 | return undefined;
|
466 | }
|
467 | return null;
|
468 | });
|
469 | }
|
470 | FilterRootFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
471 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
472 | };
|
473 | return FilterRootFields;
|
474 | }());
|
475 |
|
476 | var RenameObjectFields = (function () {
|
477 | function RenameObjectFields(renamer) {
|
478 | this.transformer = new TransformObjectFields(function (typeName, fieldName, fieldConfig) { return [
|
479 | renamer(typeName, fieldName, fieldConfig),
|
480 | fieldConfig,
|
481 | ]; });
|
482 | }
|
483 | RenameObjectFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
484 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
485 | };
|
486 | RenameObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
487 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
488 | };
|
489 | return RenameObjectFields;
|
490 | }());
|
491 |
|
492 | var FilterObjectFields = (function () {
|
493 | function FilterObjectFields(filter) {
|
494 | this.transformer = new TransformObjectFields(function (typeName, fieldName, fieldConfig) {
|
495 | return filter(typeName, fieldName, fieldConfig) ? undefined : null;
|
496 | });
|
497 | }
|
498 | FilterObjectFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
499 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
500 | };
|
501 | return FilterObjectFields;
|
502 | }());
|
503 |
|
504 | var TransformInterfaceFields = (function () {
|
505 | function TransformInterfaceFields(interfaceFieldTransformer, fieldNodeTransformer) {
|
506 | this.interfaceFieldTransformer = interfaceFieldTransformer;
|
507 | this.fieldNodeTransformer = fieldNodeTransformer;
|
508 | }
|
509 | TransformInterfaceFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
510 | var _this = this;
|
511 | var compositeToObjectFieldTransformer = function (typeName, fieldName, fieldConfig) {
|
512 | if (graphql.isInterfaceType(originalWrappingSchema.getType(typeName))) {
|
513 | return _this.interfaceFieldTransformer(typeName, fieldName, fieldConfig);
|
514 | }
|
515 | return undefined;
|
516 | };
|
517 | this.transformer = new TransformCompositeFields(compositeToObjectFieldTransformer, this.fieldNodeTransformer);
|
518 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
519 | };
|
520 | TransformInterfaceFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
521 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
522 | };
|
523 | TransformInterfaceFields.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
524 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
525 | };
|
526 | return TransformInterfaceFields;
|
527 | }());
|
528 |
|
529 | var RenameInterfaceFields = (function () {
|
530 | function RenameInterfaceFields(renamer) {
|
531 | this.transformer = new TransformInterfaceFields(function (typeName, fieldName, fieldConfig) { return [
|
532 | renamer(typeName, fieldName, fieldConfig),
|
533 | fieldConfig,
|
534 | ]; });
|
535 | }
|
536 | RenameInterfaceFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
537 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
538 | };
|
539 | RenameInterfaceFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
540 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
541 | };
|
542 | return RenameInterfaceFields;
|
543 | }());
|
544 |
|
545 | var FilterInterfaceFields = (function () {
|
546 | function FilterInterfaceFields(filter) {
|
547 | this.transformer = new TransformInterfaceFields(function (typeName, fieldName, fieldConfig) {
|
548 | return filter(typeName, fieldName, fieldConfig) ? undefined : null;
|
549 | });
|
550 | }
|
551 | FilterInterfaceFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
552 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
553 | };
|
554 | return FilterInterfaceFields;
|
555 | }());
|
556 |
|
557 | var TransformInputObjectFields = (function () {
|
558 | function TransformInputObjectFields(inputFieldTransformer, inputFieldNodeTransformer, inputObjectNodeTransformer) {
|
559 | this.inputFieldTransformer = inputFieldTransformer;
|
560 | this.inputFieldNodeTransformer = inputFieldNodeTransformer;
|
561 | this.inputObjectNodeTransformer = inputObjectNodeTransformer;
|
562 | this.mapping = {};
|
563 | }
|
564 | TransformInputObjectFields.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
565 | var _a;
|
566 | var _this = this;
|
567 | this.transformedSchema = utils.mapSchema(originalWrappingSchema, (_a = {},
|
568 | _a[utils.MapperKind.INPUT_OBJECT_FIELD] = function (inputFieldConfig, fieldName, typeName) {
|
569 | var transformedInputField = _this.inputFieldTransformer(typeName, fieldName, inputFieldConfig);
|
570 | if (Array.isArray(transformedInputField)) {
|
571 | var newFieldName = transformedInputField[0];
|
572 | if (newFieldName !== fieldName) {
|
573 | if (!(typeName in _this.mapping)) {
|
574 | _this.mapping[typeName] = {};
|
575 | }
|
576 | _this.mapping[typeName][newFieldName] = fieldName;
|
577 | }
|
578 | }
|
579 | return transformedInputField;
|
580 | },
|
581 | _a));
|
582 | return this.transformedSchema;
|
583 | };
|
584 | TransformInputObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, _transformationContext) {
|
585 | var _this = this;
|
586 | var variableValues = originalRequest.variables;
|
587 | var fragments = Object.create(null);
|
588 | var operations = [];
|
589 | originalRequest.document.definitions.forEach(function (def) {
|
590 | if (def.kind === graphql.Kind.OPERATION_DEFINITION) {
|
591 | operations.push(def);
|
592 | }
|
593 | else {
|
594 | fragments[def.name.value] = def;
|
595 | }
|
596 | });
|
597 | operations.forEach(function (def) {
|
598 | var variableDefs = def.variableDefinitions;
|
599 | if (variableDefs != null) {
|
600 | variableDefs.forEach(function (variableDef) {
|
601 | var varName = variableDef.variable.name.value;
|
602 |
|
603 | var varType = graphql.typeFromAST(delegationContext.transformedSchema, variableDef.type);
|
604 | variableValues[varName] = utils.transformInputValue(varType, variableValues[varName], undefined, function (type, originalValue) {
|
605 | var newValue = Object.create(null);
|
606 | var fields = type.getFields();
|
607 | Object.keys(originalValue).forEach(function (key) {
|
608 | var _a;
|
609 | var field = fields[key];
|
610 | if (field != null) {
|
611 | var newFieldName = (_a = _this.mapping[type.name]) === null || _a === void 0 ? void 0 : _a[field.name];
|
612 | if (newFieldName != null) {
|
613 | newValue[newFieldName] = originalValue[field.name];
|
614 | }
|
615 | else {
|
616 | newValue[field.name] = originalValue[field.name];
|
617 | }
|
618 | }
|
619 | });
|
620 | return newValue;
|
621 | });
|
622 | });
|
623 | }
|
624 | });
|
625 | originalRequest.document.definitions
|
626 | .filter(function (def) { return def.kind === graphql.Kind.FRAGMENT_DEFINITION; })
|
627 | .forEach(function (def) {
|
628 | fragments[def.name.value] = def;
|
629 | });
|
630 | var document = this.transformDocument(originalRequest.document, this.mapping, this.inputFieldNodeTransformer, this.inputObjectNodeTransformer, originalRequest, delegationContext);
|
631 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: document, variables: variableValues });
|
632 | };
|
633 | TransformInputObjectFields.prototype.transformDocument = function (document, mapping, inputFieldNodeTransformer, inputObjectNodeTransformer, request, delegationContext) {
|
634 | var _a;
|
635 | var typeInfo = new graphql.TypeInfo(this.transformedSchema);
|
636 | var newDocument = graphql.visit(document, graphql.visitWithTypeInfo(typeInfo, {
|
637 | leave: (_a = {},
|
638 | _a[graphql.Kind.OBJECT] = function (node) {
|
639 | var parentType = typeInfo.getInputType();
|
640 | if (parentType != null) {
|
641 | var parentTypeName_1 = parentType.name;
|
642 | var newInputFields_1 = [];
|
643 | node.fields.forEach(function (inputField) {
|
644 | var newName = inputField.name.value;
|
645 | var transformedInputField = inputFieldNodeTransformer != null
|
646 | ? inputFieldNodeTransformer(parentTypeName_1, newName, inputField, request, delegationContext)
|
647 | : inputField;
|
648 | if (Array.isArray(transformedInputField)) {
|
649 | transformedInputField.forEach(function (individualTransformedInputField) {
|
650 | var typeMapping = mapping[parentTypeName_1];
|
651 | if (typeMapping == null) {
|
652 | newInputFields_1.push(individualTransformedInputField);
|
653 | return;
|
654 | }
|
655 | var oldName = typeMapping[newName];
|
656 | if (oldName == null) {
|
657 | newInputFields_1.push(individualTransformedInputField);
|
658 | return;
|
659 | }
|
660 | newInputFields_1.push(tslib.__assign(tslib.__assign({}, individualTransformedInputField), { name: tslib.__assign(tslib.__assign({}, individualTransformedInputField.name), { value: oldName }) }));
|
661 | });
|
662 | return;
|
663 | }
|
664 | var typeMapping = mapping[parentTypeName_1];
|
665 | if (typeMapping == null) {
|
666 | newInputFields_1.push(transformedInputField);
|
667 | return;
|
668 | }
|
669 | var oldName = typeMapping[newName];
|
670 | if (oldName == null) {
|
671 | newInputFields_1.push(transformedInputField);
|
672 | return;
|
673 | }
|
674 | newInputFields_1.push(tslib.__assign(tslib.__assign({}, transformedInputField), { name: tslib.__assign(tslib.__assign({}, transformedInputField.name), { value: oldName }) }));
|
675 | });
|
676 | var newNode = tslib.__assign(tslib.__assign({}, node), { fields: newInputFields_1 });
|
677 | return inputObjectNodeTransformer != null
|
678 | ? inputObjectNodeTransformer(parentTypeName_1, newNode, request, delegationContext)
|
679 | : newNode;
|
680 | }
|
681 | },
|
682 | _a),
|
683 | }));
|
684 | return newDocument;
|
685 | };
|
686 | return TransformInputObjectFields;
|
687 | }());
|
688 |
|
689 | var RenameInputObjectFields = (function () {
|
690 | function RenameInputObjectFields(renamer) {
|
691 | var _this = this;
|
692 | this.renamer = renamer;
|
693 | this.transformer = new TransformInputObjectFields(function (typeName, inputFieldName, inputFieldConfig) {
|
694 | var newName = renamer(typeName, inputFieldName, inputFieldConfig);
|
695 | if (newName !== undefined && newName !== inputFieldName) {
|
696 | return [renamer(typeName, inputFieldName, inputFieldConfig), inputFieldConfig];
|
697 | }
|
698 | }, function (typeName, inputFieldName, inputFieldNode) {
|
699 | if (!(typeName in _this.reverseMap)) {
|
700 | return inputFieldNode;
|
701 | }
|
702 | var inputFieldNameMap = _this.reverseMap[typeName];
|
703 | if (!(inputFieldName in inputFieldNameMap)) {
|
704 | return inputFieldNode;
|
705 | }
|
706 | return tslib.__assign(tslib.__assign({}, inputFieldNode), { name: tslib.__assign(tslib.__assign({}, inputFieldNode.name), { value: inputFieldNameMap[inputFieldName] }) });
|
707 | });
|
708 | this.reverseMap = Object.create(null);
|
709 | }
|
710 | RenameInputObjectFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
711 | var _a;
|
712 | var _this = this;
|
713 | utils.mapSchema(originalWrappingSchema, (_a = {},
|
714 | _a[utils.MapperKind.INPUT_OBJECT_FIELD] = function (inputFieldConfig, fieldName, typeName) {
|
715 | var newName = _this.renamer(typeName, fieldName, inputFieldConfig);
|
716 | if (newName !== undefined && newName !== fieldName) {
|
717 | if (_this.reverseMap[typeName] == null) {
|
718 | _this.reverseMap[typeName] = Object.create(null);
|
719 | }
|
720 | _this.reverseMap[typeName][newName] = fieldName;
|
721 | }
|
722 | return undefined;
|
723 | },
|
724 | _a[utils.MapperKind.ROOT_OBJECT] = function () {
|
725 | return undefined;
|
726 | },
|
727 | _a));
|
728 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
729 | };
|
730 | RenameInputObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
731 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
732 | };
|
733 | return RenameInputObjectFields;
|
734 | }());
|
735 |
|
736 | var FilterInputObjectFields = (function () {
|
737 | function FilterInputObjectFields(filter, inputObjectNodeTransformer) {
|
738 | this.transformer = new TransformInputObjectFields(function (typeName, fieldName, inputFieldConfig) {
|
739 | return filter(typeName, fieldName, inputFieldConfig) ? undefined : null;
|
740 | }, undefined, inputObjectNodeTransformer);
|
741 | }
|
742 | FilterInputObjectFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
743 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
744 | };
|
745 | FilterInputObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
746 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
747 | };
|
748 | return FilterInputObjectFields;
|
749 | }());
|
750 |
|
751 | var MapLeafValues = (function () {
|
752 | function MapLeafValues(inputValueTransformer, outputValueTransformer) {
|
753 | this.inputValueTransformer = inputValueTransformer;
|
754 | this.outputValueTransformer = outputValueTransformer;
|
755 | this.resultVisitorMap = Object.create(null);
|
756 | }
|
757 | MapLeafValues.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
758 | var _this = this;
|
759 | this.originalWrappingSchema = originalWrappingSchema;
|
760 | var typeMap = originalWrappingSchema.getTypeMap();
|
761 | Object.keys(typeMap).forEach(function (typeName) {
|
762 | var type = typeMap[typeName];
|
763 | if (!typeName.startsWith('__')) {
|
764 | if (graphql.isLeafType(type)) {
|
765 | _this.resultVisitorMap[typeName] = function (value) { return _this.outputValueTransformer(typeName, value); };
|
766 | }
|
767 | }
|
768 | });
|
769 | this.typeInfo = new graphql.TypeInfo(originalWrappingSchema);
|
770 | return originalWrappingSchema;
|
771 | };
|
772 | MapLeafValues.prototype.transformRequest = function (originalRequest, _delegationContext, transformationContext) {
|
773 | var document = originalRequest.document;
|
774 | var variableValues = originalRequest.variables;
|
775 | var operations = document.definitions.filter(function (def) { return def.kind === graphql.Kind.OPERATION_DEFINITION; });
|
776 | var fragments = document.definitions.filter(function (def) { return def.kind === graphql.Kind.FRAGMENT_DEFINITION; });
|
777 | var newOperations = this.transformOperations(operations, variableValues);
|
778 | var transformedRequest = tslib.__assign(tslib.__assign({}, originalRequest), { document: tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(newOperations)), tslib.__read(fragments)) }), variables: variableValues });
|
779 | transformationContext.transformedRequest = transformedRequest;
|
780 | return transformedRequest;
|
781 | };
|
782 | MapLeafValues.prototype.transformResult = function (originalResult, _delegationContext, transformationContext) {
|
783 | return utils.visitResult(originalResult, transformationContext.transformedRequest, this.originalWrappingSchema, this.resultVisitorMap);
|
784 | };
|
785 | MapLeafValues.prototype.transformOperations = function (operations, variableValues) {
|
786 | var _this = this;
|
787 | return operations.map(function (operation) {
|
788 | var _a;
|
789 | var variableDefinitionMap = operation.variableDefinitions.reduce(function (prev, def) {
|
790 | var _a;
|
791 | return (tslib.__assign(tslib.__assign({}, prev), (_a = {}, _a[def.variable.name.value] = def, _a)));
|
792 | }, {});
|
793 | var newOperation = graphql.visit(operation, graphql.visitWithTypeInfo(_this.typeInfo, (_a = {},
|
794 | _a[graphql.Kind.FIELD] = function (node) { return _this.transformFieldNode(node, variableDefinitionMap, variableValues); },
|
795 | _a)));
|
796 | return tslib.__assign(tslib.__assign({}, newOperation), { variableDefinitions: Object.keys(variableDefinitionMap).map(function (varName) { return variableDefinitionMap[varName]; }) });
|
797 | });
|
798 | };
|
799 | MapLeafValues.prototype.transformFieldNode = function (field, variableDefinitionMap, variableValues) {
|
800 | var _this = this;
|
801 | var targetField = this.typeInfo.getFieldDef();
|
802 | if (!targetField.name.startsWith('__')) {
|
803 | var argumentNodes = field.arguments;
|
804 | if (argumentNodes != null) {
|
805 | var argumentNodeMap_1 = argumentNodes.reduce(function (prev, argument) {
|
806 | var _a;
|
807 | return (tslib.__assign(tslib.__assign({}, prev), (_a = {}, _a[argument.name.value] = argument, _a)));
|
808 | }, Object.create(null));
|
809 | targetField.args.forEach(function (argument) {
|
810 | var argName = argument.name;
|
811 | var argType = argument.type;
|
812 | var argumentNode = argumentNodeMap_1[argName];
|
813 | var argValue = argumentNode === null || argumentNode === void 0 ? void 0 : argumentNode.value;
|
814 | var value;
|
815 | if (argValue != null) {
|
816 | value = graphql.valueFromAST(argValue, argType, variableValues);
|
817 | }
|
818 | utils.updateArgument(argName, argType, argumentNodeMap_1, variableDefinitionMap, variableValues, utils.transformInputValue(argType, value, function (t, v) {
|
819 | var newValue = _this.inputValueTransformer(t.name, v);
|
820 | return newValue === undefined ? v : newValue;
|
821 | }));
|
822 | });
|
823 | return tslib.__assign(tslib.__assign({}, field), { arguments: Object.keys(argumentNodeMap_1).map(function (argName) { return argumentNodeMap_1[argName]; }) });
|
824 | }
|
825 | }
|
826 | };
|
827 | return MapLeafValues;
|
828 | }());
|
829 |
|
830 | var TransformEnumValues = (function () {
|
831 | function TransformEnumValues(enumValueTransformer, inputValueTransformer, outputValueTransformer) {
|
832 | this.enumValueTransformer = enumValueTransformer;
|
833 | this.mapping = Object.create(null);
|
834 | this.reverseMapping = Object.create(null);
|
835 | this.transformer = new MapLeafValues(generateValueTransformer(inputValueTransformer, this.reverseMapping), generateValueTransformer(outputValueTransformer, this.mapping));
|
836 | }
|
837 | TransformEnumValues.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
838 | var _a;
|
839 | var _this = this;
|
840 | var mappingSchema = this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
841 | this.transformedSchema = utils.mapSchema(mappingSchema, (_a = {},
|
842 | _a[utils.MapperKind.ENUM_VALUE] = function (valueConfig, typeName, _schema, externalValue) {
|
843 | return _this.transformEnumValue(typeName, externalValue, valueConfig);
|
844 | },
|
845 | _a));
|
846 | return this.transformedSchema;
|
847 | };
|
848 | TransformEnumValues.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
849 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
850 | };
|
851 | TransformEnumValues.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
852 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
853 | };
|
854 | TransformEnumValues.prototype.transformEnumValue = function (typeName, externalValue, enumValueConfig) {
|
855 | var transformedEnumValue = this.enumValueTransformer(typeName, externalValue, enumValueConfig);
|
856 | if (Array.isArray(transformedEnumValue)) {
|
857 | var newExternalValue = transformedEnumValue[0];
|
858 | if (newExternalValue !== externalValue) {
|
859 | if (!(typeName in this.mapping)) {
|
860 | this.mapping[typeName] = Object.create(null);
|
861 | this.reverseMapping[typeName] = Object.create(null);
|
862 | }
|
863 | this.mapping[typeName][externalValue] = newExternalValue;
|
864 | this.reverseMapping[typeName][newExternalValue] = externalValue;
|
865 | }
|
866 | }
|
867 | return transformedEnumValue;
|
868 | };
|
869 | return TransformEnumValues;
|
870 | }());
|
871 | function mapEnumValues(typeName, value, mapping) {
|
872 | var _a;
|
873 | var newExternalValue = (_a = mapping[typeName]) === null || _a === void 0 ? void 0 : _a[value];
|
874 | return newExternalValue != null ? newExternalValue : value;
|
875 | }
|
876 | function generateValueTransformer(valueTransformer, mapping) {
|
877 | if (valueTransformer == null) {
|
878 | return function (typeName, value) { return mapEnumValues(typeName, value, mapping); };
|
879 | }
|
880 | else {
|
881 | return function (typeName, value) { return mapEnumValues(typeName, valueTransformer(typeName, value), mapping); };
|
882 | }
|
883 | }
|
884 |
|
885 | var TransformQuery = (function () {
|
886 | function TransformQuery(_a) {
|
887 | var path = _a.path, queryTransformer = _a.queryTransformer, _b = _a.resultTransformer, resultTransformer = _b === void 0 ? function (result) { return result; } : _b, _c = _a.errorPathTransformer, errorPathTransformer = _c === void 0 ? function (errorPath) { return [].concat(errorPath); } : _c, _d = _a.fragments, fragments = _d === void 0 ? {} : _d;
|
888 | this.path = path;
|
889 | this.queryTransformer = queryTransformer;
|
890 | this.resultTransformer = resultTransformer;
|
891 | this.errorPathTransformer = errorPathTransformer;
|
892 | this.fragments = fragments;
|
893 | }
|
894 | TransformQuery.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
895 | var _a;
|
896 | var _this = this;
|
897 | var pathLength = this.path.length;
|
898 | var index = 0;
|
899 | var document = graphql.visit(originalRequest.document, (_a = {},
|
900 | _a[graphql.Kind.FIELD] = {
|
901 | enter: function (node) {
|
902 | if (index === pathLength || node.name.value !== _this.path[index]) {
|
903 | return false;
|
904 | }
|
905 | index++;
|
906 | if (index === pathLength) {
|
907 | var selectionSet = _this.queryTransformer(node.selectionSet, _this.fragments, delegationContext, transformationContext);
|
908 | return tslib.__assign(tslib.__assign({}, node), { selectionSet: selectionSet });
|
909 | }
|
910 | },
|
911 | leave: function () {
|
912 | index--;
|
913 | },
|
914 | },
|
915 | _a));
|
916 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: document });
|
917 | };
|
918 | TransformQuery.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
919 | var data = this.transformData(originalResult.data, delegationContext, transformationContext);
|
920 | var errors = originalResult.errors;
|
921 | return {
|
922 | data: data,
|
923 | errors: errors != null ? this.transformErrors(errors) : undefined,
|
924 | };
|
925 | };
|
926 | TransformQuery.prototype.transformData = function (data, delegationContext, transformationContext) {
|
927 | var leafIndex = this.path.length - 1;
|
928 | var index = 0;
|
929 | var newData = data;
|
930 | if (newData) {
|
931 | var next = this.path[index];
|
932 | while (index < leafIndex) {
|
933 | if (data[next]) {
|
934 | newData = newData[next];
|
935 | }
|
936 | else {
|
937 | break;
|
938 | }
|
939 | index++;
|
940 | next = this.path[index];
|
941 | }
|
942 | newData[next] = this.resultTransformer(newData[next], delegationContext, transformationContext);
|
943 | }
|
944 | return newData;
|
945 | };
|
946 | TransformQuery.prototype.transformErrors = function (errors) {
|
947 | var _this = this;
|
948 | return errors.map(function (error) {
|
949 | var path = error.path;
|
950 | var match = true;
|
951 | var index = 0;
|
952 | while (index < _this.path.length) {
|
953 | if (path[index] !== _this.path[index]) {
|
954 | match = false;
|
955 | break;
|
956 | }
|
957 | index++;
|
958 | }
|
959 | var newPath = match ? path.slice(0, index).concat(_this.errorPathTransformer(path.slice(index))) : path;
|
960 | return utils.relocatedError(error, newPath);
|
961 | });
|
962 | };
|
963 | return TransformQuery;
|
964 | }());
|
965 |
|
966 | var FilterObjectFieldDirectives = (function () {
|
967 | function FilterObjectFieldDirectives(filter) {
|
968 | this.filter = filter;
|
969 | }
|
970 | FilterObjectFieldDirectives.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
971 | var _this = this;
|
972 | var transformer = new TransformObjectFields(function (_typeName, _fieldName, fieldConfig) {
|
973 | var keepDirectives = fieldConfig.astNode.directives.filter(function (dir) {
|
974 | var directiveDef = originalWrappingSchema.getDirective(dir.name.value);
|
975 | var directiveValue = directiveDef ? utils.getArgumentValues(directiveDef, dir) : undefined;
|
976 | return _this.filter(dir.name.value, directiveValue);
|
977 | });
|
978 | if (keepDirectives.length !== fieldConfig.astNode.directives.length) {
|
979 | fieldConfig = tslib.__assign(tslib.__assign({}, fieldConfig), { astNode: tslib.__assign(tslib.__assign({}, fieldConfig.astNode), { directives: keepDirectives }) });
|
980 | return fieldConfig;
|
981 | }
|
982 | });
|
983 | return transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
984 | };
|
985 | return FilterObjectFieldDirectives;
|
986 | }());
|
987 |
|
988 | var RemoveObjectFieldDirectives = (function () {
|
989 | function RemoveObjectFieldDirectives(directiveName, args) {
|
990 | if (args === void 0) { args = {}; }
|
991 | this.transformer = new FilterObjectFieldDirectives(function (dirName, dirValue) {
|
992 | return !(utils.valueMatchesCriteria(dirName, directiveName) && utils.valueMatchesCriteria(dirValue, args));
|
993 | });
|
994 | }
|
995 | RemoveObjectFieldDirectives.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
996 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
997 | };
|
998 | return RemoveObjectFieldDirectives;
|
999 | }());
|
1000 |
|
1001 | var RemoveObjectFieldsWithDirective = (function () {
|
1002 | function RemoveObjectFieldsWithDirective(directiveName, args) {
|
1003 | if (args === void 0) { args = {}; }
|
1004 | this.directiveName = directiveName;
|
1005 | this.args = args;
|
1006 | }
|
1007 | RemoveObjectFieldsWithDirective.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1008 | var _this = this;
|
1009 | var transformer = new FilterObjectFields(function (_typeName, _fieldName, fieldConfig) {
|
1010 | var valueMap = utils.getDirectives(originalWrappingSchema, fieldConfig);
|
1011 | return !Object.keys(valueMap).some(function (directiveName) {
|
1012 | return utils.valueMatchesCriteria(directiveName, _this.directiveName) &&
|
1013 | ((Array.isArray(valueMap[directiveName]) &&
|
1014 | valueMap[directiveName].some(function (value) { return utils.valueMatchesCriteria(value, _this.args); })) ||
|
1015 | utils.valueMatchesCriteria(valueMap[directiveName], _this.args));
|
1016 | });
|
1017 | });
|
1018 | return transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
1019 | };
|
1020 | return RemoveObjectFieldsWithDirective;
|
1021 | }());
|
1022 |
|
1023 | var RemoveObjectFieldDeprecations = (function () {
|
1024 | function RemoveObjectFieldDeprecations(reason) {
|
1025 | var args = { reason: reason };
|
1026 | this.removeDirectives = new FilterObjectFieldDirectives(function (dirName, dirValue) {
|
1027 | return !(dirName === 'deprecated' && utils.valueMatchesCriteria(dirValue, args));
|
1028 | });
|
1029 | this.removeDeprecations = new TransformObjectFields(function (_typeName, _fieldName, fieldConfig) {
|
1030 | if (fieldConfig.deprecationReason && utils.valueMatchesCriteria(fieldConfig.deprecationReason, reason)) {
|
1031 | fieldConfig = tslib.__assign({}, fieldConfig);
|
1032 | delete fieldConfig.deprecationReason;
|
1033 | }
|
1034 | return fieldConfig;
|
1035 | });
|
1036 | }
|
1037 | RemoveObjectFieldDeprecations.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1038 | return this.removeDeprecations.transformSchema(this.removeDirectives.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema), subschemaConfig, transformedSchema);
|
1039 | };
|
1040 | return RemoveObjectFieldDeprecations;
|
1041 | }());
|
1042 |
|
1043 | var RemoveObjectFieldsWithDeprecation = (function () {
|
1044 | function RemoveObjectFieldsWithDeprecation(reason) {
|
1045 | this.transformer = new FilterObjectFields(function (_typeName, _fieldName, fieldConfig) {
|
1046 | if (fieldConfig.deprecationReason) {
|
1047 | return !utils.valueMatchesCriteria(fieldConfig.deprecationReason, reason);
|
1048 | }
|
1049 | return true;
|
1050 | });
|
1051 | }
|
1052 | RemoveObjectFieldsWithDeprecation.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1053 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
1054 | };
|
1055 | return RemoveObjectFieldsWithDeprecation;
|
1056 | }());
|
1057 |
|
1058 | var PruneTypes = (function () {
|
1059 | function PruneTypes(options) {
|
1060 | if (options === void 0) { options = {}; }
|
1061 | this.options = options;
|
1062 | }
|
1063 | PruneTypes.prototype.transformSchema = function (originalWrappingSchema, _subschemaConfig, _transformedSchema) {
|
1064 | return utils.pruneSchema(originalWrappingSchema, this.options);
|
1065 | };
|
1066 | return PruneTypes;
|
1067 | }());
|
1068 |
|
1069 | var MapFields = (function () {
|
1070 | function MapFields(fieldNodeTransformerMap, objectValueTransformerMap, errorsTransformer) {
|
1071 | this.fieldNodeTransformerMap = fieldNodeTransformerMap;
|
1072 | this.objectValueTransformerMap = objectValueTransformerMap;
|
1073 | this.errorsTransformer = errorsTransformer;
|
1074 | }
|
1075 | MapFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1076 | var _this = this;
|
1077 | var _a;
|
1078 | var subscriptionTypeName = (_a = originalWrappingSchema.getSubscriptionType()) === null || _a === void 0 ? void 0 : _a.name;
|
1079 | this.transformer = new TransformCompositeFields(function () { return undefined; }, function (typeName, fieldName, fieldNode, fragments, transformationContext) {
|
1080 | var typeTransformers = _this.fieldNodeTransformerMap[typeName];
|
1081 | if (typeTransformers == null) {
|
1082 | return undefined;
|
1083 | }
|
1084 | var fieldNodeTransformer = typeTransformers[fieldName];
|
1085 | if (fieldNodeTransformer == null) {
|
1086 | return undefined;
|
1087 | }
|
1088 | return fieldNodeTransformer(fieldNode, fragments, transformationContext);
|
1089 | }, this.objectValueTransformerMap != null
|
1090 | ? function (data, transformationContext) {
|
1091 | if (data == null) {
|
1092 | return data;
|
1093 | }
|
1094 | var typeName = data.__typename;
|
1095 | if (typeName == null) {
|
1096 |
|
1097 | typeName = subscriptionTypeName;
|
1098 | if (typeName == null) {
|
1099 | return data;
|
1100 | }
|
1101 | }
|
1102 | var transformer = _this.objectValueTransformerMap[typeName];
|
1103 | if (transformer == null) {
|
1104 | return data;
|
1105 | }
|
1106 | return transformer(data, transformationContext);
|
1107 | }
|
1108 | : undefined, this.errorsTransformer != null ? this.errorsTransformer : undefined);
|
1109 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
1110 | };
|
1111 | MapFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
1112 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
1113 | };
|
1114 | MapFields.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
1115 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
1116 | };
|
1117 | return MapFields;
|
1118 | }());
|
1119 |
|
1120 | var WrapFields = (function () {
|
1121 | function WrapFields(outerTypeName, wrappingFieldNames, wrappingTypeNames, fieldNames, prefix) {
|
1122 | var _a, _b, _c;
|
1123 | if (prefix === void 0) { prefix = 'gqtld'; }
|
1124 | this.outerTypeName = outerTypeName;
|
1125 | this.wrappingFieldNames = wrappingFieldNames;
|
1126 | this.wrappingTypeNames = wrappingTypeNames;
|
1127 | this.numWraps = wrappingFieldNames.length;
|
1128 | this.fieldNames = fieldNames;
|
1129 | var remainingWrappingFieldNames = this.wrappingFieldNames.slice();
|
1130 | var outerMostWrappingFieldName = remainingWrappingFieldNames.shift();
|
1131 | this.transformer = new MapFields((_a = {},
|
1132 | _a[outerTypeName] = (_b = {},
|
1133 | _b[outerMostWrappingFieldName] = function (fieldNode, fragments, transformationContext) {
|
1134 | return hoistFieldNodes({
|
1135 | fieldNode: fieldNode,
|
1136 | path: remainingWrappingFieldNames,
|
1137 | fieldNames: fieldNames,
|
1138 | fragments: fragments,
|
1139 | transformationContext: transformationContext,
|
1140 | prefix: prefix,
|
1141 | });
|
1142 | },
|
1143 | _b),
|
1144 | _a), (_c = {},
|
1145 | _c[outerTypeName] = function (value, context) { return dehoistValue(value, context); },
|
1146 | _c), function (errors, context) { return dehoistErrors(errors, context); });
|
1147 | }
|
1148 | WrapFields.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1149 | var _a, _b, _c;
|
1150 | var _this = this;
|
1151 | var _d, _e, _f;
|
1152 | var targetFieldConfigMap = utils.selectObjectFields(originalWrappingSchema, this.outerTypeName, !this.fieldNames ? function () { return true; } : function (fieldName) { return _this.fieldNames.includes(fieldName); });
|
1153 | var newTargetFieldConfigMap = Object.create(null);
|
1154 | Object.keys(targetFieldConfigMap).forEach(function (fieldName) {
|
1155 | var field = targetFieldConfigMap[fieldName];
|
1156 | var newField = tslib.__assign(tslib.__assign({}, field), { resolve: delegate.defaultMergedResolver });
|
1157 | newTargetFieldConfigMap[fieldName] = newField;
|
1158 | });
|
1159 | var wrapIndex = this.numWraps - 1;
|
1160 | var wrappingTypeName = this.wrappingTypeNames[wrapIndex];
|
1161 | var wrappingFieldName = this.wrappingFieldNames[wrapIndex];
|
1162 | var newSchema = utils.appendObjectFields(originalWrappingSchema, wrappingTypeName, newTargetFieldConfigMap);
|
1163 | for (wrapIndex--; wrapIndex > -1; wrapIndex--) {
|
1164 | var nextWrappingTypeName = this.wrappingTypeNames[wrapIndex];
|
1165 | newSchema = utils.appendObjectFields(newSchema, nextWrappingTypeName, (_a = {},
|
1166 | _a[wrappingFieldName] = {
|
1167 | type: newSchema.getType(wrappingTypeName),
|
1168 | resolve: delegate.defaultMergedResolver,
|
1169 | },
|
1170 | _a));
|
1171 | wrappingTypeName = nextWrappingTypeName;
|
1172 | wrappingFieldName = this.wrappingFieldNames[wrapIndex];
|
1173 | }
|
1174 | var wrappingRootField = this.outerTypeName === ((_d = originalWrappingSchema.getQueryType()) === null || _d === void 0 ? void 0 : _d.name) ||
|
1175 | this.outerTypeName === ((_e = originalWrappingSchema.getMutationType()) === null || _e === void 0 ? void 0 : _e.name);
|
1176 | var resolve;
|
1177 | if (transformedSchema) {
|
1178 | if (wrappingRootField) {
|
1179 | var targetSchema = subschemaConfig.schema;
|
1180 | var operation = this.outerTypeName === targetSchema.getQueryType().name ? 'query' : 'mutation';
|
1181 | var createProxyingResolver = (_f = subschemaConfig.createProxyingResolver) !== null && _f !== void 0 ? _f : defaultCreateProxyingResolver;
|
1182 | resolve = createProxyingResolver({
|
1183 | subschemaConfig: subschemaConfig,
|
1184 | transformedSchema: transformedSchema,
|
1185 | operation: operation,
|
1186 | fieldName: wrappingFieldName,
|
1187 | });
|
1188 | }
|
1189 | else {
|
1190 | resolve = delegate.defaultMergedResolver;
|
1191 | }
|
1192 | }
|
1193 | var selectedFieldNames = Object.keys(newTargetFieldConfigMap);
|
1194 | _c = tslib.__read(utils.modifyObjectFields(newSchema, this.outerTypeName, function (fieldName) { return selectedFieldNames.includes(fieldName); }, (_b = {},
|
1195 | _b[wrappingFieldName] = {
|
1196 | type: newSchema.getType(wrappingTypeName),
|
1197 | resolve: resolve,
|
1198 | },
|
1199 | _b)), 1), newSchema = _c[0];
|
1200 | return this.transformer.transformSchema(newSchema, subschemaConfig, transformedSchema);
|
1201 | };
|
1202 | WrapFields.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
1203 | transformationContext.nextIndex = 0;
|
1204 | transformationContext.paths = Object.create(null);
|
1205 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
1206 | };
|
1207 | WrapFields.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
1208 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
1209 | };
|
1210 | return WrapFields;
|
1211 | }());
|
1212 | function collectFields(selectionSet, fragments, fields, visitedFragmentNames) {
|
1213 | if (fields === void 0) { fields = []; }
|
1214 | if (visitedFragmentNames === void 0) { visitedFragmentNames = {}; }
|
1215 | if (selectionSet != null) {
|
1216 | selectionSet.selections.forEach(function (selection) {
|
1217 | switch (selection.kind) {
|
1218 | case graphql.Kind.FIELD:
|
1219 | fields.push(selection);
|
1220 | break;
|
1221 | case graphql.Kind.INLINE_FRAGMENT:
|
1222 | collectFields(selection.selectionSet, fragments, fields, visitedFragmentNames);
|
1223 | break;
|
1224 | case graphql.Kind.FRAGMENT_SPREAD: {
|
1225 | var fragmentName = selection.name.value;
|
1226 | if (!visitedFragmentNames[fragmentName]) {
|
1227 | visitedFragmentNames[fragmentName] = true;
|
1228 | collectFields(fragments[fragmentName].selectionSet, fragments, fields, visitedFragmentNames);
|
1229 | }
|
1230 | break;
|
1231 | }
|
1232 | }
|
1233 | });
|
1234 | }
|
1235 | return fields;
|
1236 | }
|
1237 | function aliasFieldNode(fieldNode, str) {
|
1238 | return tslib.__assign(tslib.__assign({}, fieldNode), { alias: {
|
1239 | kind: graphql.Kind.NAME,
|
1240 | value: str,
|
1241 | } });
|
1242 | }
|
1243 | function hoistFieldNodes(_a) {
|
1244 | var fieldNode = _a.fieldNode, fieldNames = _a.fieldNames, path = _a.path, fragments = _a.fragments, transformationContext = _a.transformationContext, prefix = _a.prefix, _b = _a.index, index = _b === void 0 ? 0 : _b, _c = _a.wrappingPath, wrappingPath = _c === void 0 ? [] : _c;
|
1245 | var alias = fieldNode.alias != null ? fieldNode.alias.value : fieldNode.name.value;
|
1246 | var newFieldNodes = [];
|
1247 | if (index < path.length) {
|
1248 | var pathSegment_1 = path[index];
|
1249 | collectFields(fieldNode.selectionSet, fragments).forEach(function (possibleFieldNode) {
|
1250 | if (possibleFieldNode.name.value === pathSegment_1) {
|
1251 | var newWrappingPath = wrappingPath.concat([alias]);
|
1252 | newFieldNodes = newFieldNodes.concat(hoistFieldNodes({
|
1253 | fieldNode: possibleFieldNode,
|
1254 | fieldNames: fieldNames,
|
1255 | path: path,
|
1256 | fragments: fragments,
|
1257 | transformationContext: transformationContext,
|
1258 | prefix: prefix,
|
1259 | index: index + 1,
|
1260 | wrappingPath: newWrappingPath,
|
1261 | }));
|
1262 | }
|
1263 | });
|
1264 | }
|
1265 | else {
|
1266 | collectFields(fieldNode.selectionSet, fragments).forEach(function (possibleFieldNode) {
|
1267 | if (!fieldNames || fieldNames.includes(possibleFieldNode.name.value)) {
|
1268 | var nextIndex = transformationContext.nextIndex;
|
1269 | transformationContext.nextIndex++;
|
1270 | var indexingAlias = "__" + prefix + nextIndex + "__";
|
1271 | transformationContext.paths[indexingAlias] = {
|
1272 | pathToField: wrappingPath.concat([alias]),
|
1273 | alias: possibleFieldNode.alias != null ? possibleFieldNode.alias.value : possibleFieldNode.name.value,
|
1274 | };
|
1275 | newFieldNodes.push(aliasFieldNode(possibleFieldNode, indexingAlias));
|
1276 | }
|
1277 | });
|
1278 | }
|
1279 | return newFieldNodes;
|
1280 | }
|
1281 | function dehoistValue(originalValue, context) {
|
1282 | if (originalValue == null) {
|
1283 | return originalValue;
|
1284 | }
|
1285 | var newValue = Object.create(null);
|
1286 | Object.keys(originalValue).forEach(function (alias) {
|
1287 | var obj = newValue;
|
1288 | var path = context.paths[alias];
|
1289 | if (path == null) {
|
1290 | newValue[alias] = originalValue[alias];
|
1291 | return;
|
1292 | }
|
1293 | var pathToField = path.pathToField;
|
1294 | var fieldAlias = path.alias;
|
1295 | pathToField.forEach(function (key) {
|
1296 | obj = obj[key] = obj[key] || Object.create(null);
|
1297 | });
|
1298 | obj[fieldAlias] = originalValue[alias];
|
1299 | });
|
1300 | return newValue;
|
1301 | }
|
1302 | function dehoistErrors(errors, context) {
|
1303 | if (errors === undefined) {
|
1304 | return undefined;
|
1305 | }
|
1306 | return errors.map(function (error) {
|
1307 | var originalPath = error.path;
|
1308 | if (originalPath == null) {
|
1309 | return error;
|
1310 | }
|
1311 | var newPath = [];
|
1312 | originalPath.forEach(function (pathSegment) {
|
1313 | if (typeof pathSegment !== 'string') {
|
1314 | newPath.push(pathSegment);
|
1315 | return;
|
1316 | }
|
1317 | var path = context.paths[pathSegment];
|
1318 | if (path == null) {
|
1319 | newPath.push(pathSegment);
|
1320 | return;
|
1321 | }
|
1322 | newPath = newPath.concat(path.pathToField, [path.alias]);
|
1323 | });
|
1324 | return utils.relocatedError(error, newPath);
|
1325 | });
|
1326 | }
|
1327 |
|
1328 | var WrapType = (function () {
|
1329 | function WrapType(outerTypeName, innerTypeName, fieldName) {
|
1330 | this.transformer = new WrapFields(outerTypeName, [fieldName], [innerTypeName]);
|
1331 | }
|
1332 | WrapType.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1333 | return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transformedSchema);
|
1334 | };
|
1335 | WrapType.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
1336 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
1337 | };
|
1338 | WrapType.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
1339 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
1340 | };
|
1341 | return WrapType;
|
1342 | }());
|
1343 |
|
1344 | var HoistField = (function () {
|
1345 | function HoistField(typeName, pathConfig, newFieldName, alias) {
|
1346 | var _a, _b, _c;
|
1347 | if (alias === void 0) { alias = '__gqtlw__'; }
|
1348 | this.typeName = typeName;
|
1349 | this.newFieldName = newFieldName;
|
1350 | var path = pathConfig.map(function (segment) { return (typeof segment === 'string' ? segment : segment.fieldName); });
|
1351 | this.argFilters = pathConfig.map(function (segment, index) {
|
1352 | if (typeof segment === 'string' || segment.argFilter == null) {
|
1353 | return index === pathConfig.length - 1 ? function () { return true; } : function () { return false; };
|
1354 | }
|
1355 | return segment.argFilter;
|
1356 | });
|
1357 | var pathToField = path.slice();
|
1358 | var oldFieldName = pathToField.pop();
|
1359 | this.oldFieldName = oldFieldName;
|
1360 | this.pathToField = pathToField;
|
1361 | var argLevels = Object.create(null);
|
1362 | this.transformer = new MapFields((_a = {},
|
1363 | _a[typeName] = (_b = {},
|
1364 | _b[newFieldName] = function (fieldNode) {
|
1365 | return wrapFieldNode(renameFieldNode(fieldNode, oldFieldName), pathToField, alias, argLevels);
|
1366 | },
|
1367 | _b),
|
1368 | _a), (_c = {},
|
1369 | _c[typeName] = function (value) { return unwrapValue(value, alias); },
|
1370 | _c), function (errors) { return unwrapErrors(errors, alias); });
|
1371 | this.argLevels = argLevels;
|
1372 | }
|
1373 | HoistField.prototype.transformSchema = function (originalWrappingSchema, subschemaConfig, transformedSchema) {
|
1374 | var _a;
|
1375 | var _this = this;
|
1376 | var _b, _c, _d;
|
1377 | var argsMap = Object.create(null);
|
1378 | var innerType = this.pathToField.reduce(function (acc, pathSegment, index) {
|
1379 | var field = acc.getFields()[pathSegment];
|
1380 | field.args.forEach(function (arg) {
|
1381 | if (_this.argFilters[index](arg)) {
|
1382 | argsMap[arg.name] = arg;
|
1383 | _this.argLevels[arg.name] = index;
|
1384 | }
|
1385 | });
|
1386 | return graphql.getNullableType(field.type);
|
1387 | }, originalWrappingSchema.getType(this.typeName));
|
1388 | var _e = tslib.__read(utils.removeObjectFields(originalWrappingSchema, innerType.name, function (fieldName) { return fieldName === _this.oldFieldName; }), 2), newSchema = _e[0], targetFieldConfigMap = _e[1];
|
1389 | var targetField = targetFieldConfigMap[this.oldFieldName];
|
1390 | var resolve;
|
1391 | if (transformedSchema) {
|
1392 | var hoistingToRootField = this.typeName === ((_b = originalWrappingSchema.getQueryType()) === null || _b === void 0 ? void 0 : _b.name) ||
|
1393 | this.typeName === ((_c = originalWrappingSchema.getMutationType()) === null || _c === void 0 ? void 0 : _c.name);
|
1394 | if (hoistingToRootField) {
|
1395 | var targetSchema = subschemaConfig.schema;
|
1396 | var operation = this.typeName === targetSchema.getQueryType().name ? 'query' : 'mutation';
|
1397 | var createProxyingResolver = (_d = subschemaConfig.createProxyingResolver) !== null && _d !== void 0 ? _d : defaultCreateProxyingResolver;
|
1398 | resolve = createProxyingResolver({
|
1399 | subschemaConfig: subschemaConfig,
|
1400 | transformedSchema: transformedSchema,
|
1401 | operation: operation,
|
1402 | fieldName: this.newFieldName,
|
1403 | });
|
1404 | }
|
1405 | else {
|
1406 | resolve = delegate.defaultMergedResolver;
|
1407 | }
|
1408 | }
|
1409 | var newTargetField = tslib.__assign(tslib.__assign({}, targetField), { resolve: resolve });
|
1410 | var level = this.pathToField.length;
|
1411 | Object.keys(targetField.args).forEach(function (argName) {
|
1412 | var argConfig = targetField.args[argName];
|
1413 | var arg = tslib.__assign(tslib.__assign({}, argConfig), { name: argName, description: argConfig.description, defaultValue: argConfig.defaultValue, extensions: argConfig.extensions, astNode: argConfig.astNode });
|
1414 | if (_this.argFilters[level](arg)) {
|
1415 | argsMap[argName] = arg;
|
1416 | _this.argLevels[arg.name] = level;
|
1417 | }
|
1418 | });
|
1419 | newTargetField.args = argsMap;
|
1420 | newSchema = utils.appendObjectFields(newSchema, this.typeName, (_a = {},
|
1421 | _a[this.newFieldName] = newTargetField,
|
1422 | _a));
|
1423 | return this.transformer.transformSchema(newSchema, subschemaConfig, transformedSchema);
|
1424 | };
|
1425 | HoistField.prototype.transformRequest = function (originalRequest, delegationContext, transformationContext) {
|
1426 | return this.transformer.transformRequest(originalRequest, delegationContext, transformationContext);
|
1427 | };
|
1428 | HoistField.prototype.transformResult = function (originalResult, delegationContext, transformationContext) {
|
1429 | return this.transformer.transformResult(originalResult, delegationContext, transformationContext);
|
1430 | };
|
1431 | return HoistField;
|
1432 | }());
|
1433 | function wrapFieldNode(fieldNode, path, alias, argLevels) {
|
1434 | return path.reduceRight(function (acc, fieldName, index) { return ({
|
1435 | kind: graphql.Kind.FIELD,
|
1436 | alias: {
|
1437 | kind: graphql.Kind.NAME,
|
1438 | value: alias,
|
1439 | },
|
1440 | name: {
|
1441 | kind: graphql.Kind.NAME,
|
1442 | value: fieldName,
|
1443 | },
|
1444 | selectionSet: {
|
1445 | kind: graphql.Kind.SELECTION_SET,
|
1446 | selections: [acc],
|
1447 | },
|
1448 | arguments: fieldNode.arguments.filter(function (arg) { return argLevels[arg.name.value] === index; }),
|
1449 | }); }, tslib.__assign(tslib.__assign({}, fieldNode), { arguments: fieldNode.arguments.filter(function (arg) { return argLevels[arg.name.value] === path.length; }) }));
|
1450 | }
|
1451 | function renameFieldNode(fieldNode, name) {
|
1452 | return tslib.__assign(tslib.__assign({}, fieldNode), { alias: {
|
1453 | kind: graphql.Kind.NAME,
|
1454 | value: fieldNode.alias != null ? fieldNode.alias.value : fieldNode.name.value,
|
1455 | }, name: {
|
1456 | kind: graphql.Kind.NAME,
|
1457 | value: name,
|
1458 | } });
|
1459 | }
|
1460 | function unwrapValue(originalValue, alias) {
|
1461 | var newValue = originalValue;
|
1462 | var object = newValue[alias];
|
1463 | while (object != null) {
|
1464 | newValue = object;
|
1465 | object = newValue[alias];
|
1466 | }
|
1467 | delete originalValue[alias];
|
1468 | Object.assign(originalValue, newValue);
|
1469 | return originalValue;
|
1470 | }
|
1471 | function unwrapErrors(errors, alias) {
|
1472 | if (errors === undefined) {
|
1473 | return undefined;
|
1474 | }
|
1475 | return errors.map(function (error) {
|
1476 | var originalPath = error.path;
|
1477 | if (originalPath == null) {
|
1478 | return error;
|
1479 | }
|
1480 | var newPath = originalPath.filter(function (pathSegment) { return pathSegment !== alias; });
|
1481 | return utils.relocatedError(error, newPath);
|
1482 | });
|
1483 | }
|
1484 |
|
1485 | var WrapQuery = (function () {
|
1486 | function WrapQuery(path, wrapper, extractor) {
|
1487 | this.path = path;
|
1488 | this.wrapper = wrapper;
|
1489 | this.extractor = extractor;
|
1490 | }
|
1491 | WrapQuery.prototype.transformRequest = function (originalRequest, _delegationContext, _transformationContext) {
|
1492 | var _a;
|
1493 | var _this = this;
|
1494 | var fieldPath = [];
|
1495 | var ourPath = JSON.stringify(this.path);
|
1496 | var document = graphql.visit(originalRequest.document, (_a = {},
|
1497 | _a[graphql.Kind.FIELD] = {
|
1498 | enter: function (node) {
|
1499 | fieldPath.push(node.name.value);
|
1500 | if (ourPath === JSON.stringify(fieldPath)) {
|
1501 | var wrapResult = _this.wrapper(node.selectionSet);
|
1502 |
|
1503 |
|
1504 | var selectionSet = wrapResult != null && wrapResult.kind === graphql.Kind.SELECTION_SET
|
1505 | ? wrapResult
|
1506 | : {
|
1507 | kind: graphql.Kind.SELECTION_SET,
|
1508 | selections: [wrapResult],
|
1509 | };
|
1510 | return tslib.__assign(tslib.__assign({}, node), { selectionSet: selectionSet });
|
1511 | }
|
1512 | },
|
1513 | leave: function () {
|
1514 | fieldPath.pop();
|
1515 | },
|
1516 | },
|
1517 | _a));
|
1518 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: document });
|
1519 | };
|
1520 | WrapQuery.prototype.transformResult = function (originalResult, _delegationContext, _transformationContext) {
|
1521 | var rootData = originalResult.data;
|
1522 | if (rootData != null) {
|
1523 | var data = rootData;
|
1524 | var path = tslib.__spreadArray([], tslib.__read(this.path));
|
1525 | while (path.length > 1) {
|
1526 | var next = path.shift();
|
1527 | if (data[next]) {
|
1528 | data = data[next];
|
1529 | }
|
1530 | }
|
1531 | data[path[0]] = this.extractor(data[path[0]]);
|
1532 | }
|
1533 | return {
|
1534 | data: rootData,
|
1535 | errors: originalResult.errors,
|
1536 | };
|
1537 | };
|
1538 | return WrapQuery;
|
1539 | }());
|
1540 |
|
1541 | var ExtractField = (function () {
|
1542 | function ExtractField(_a) {
|
1543 | var from = _a.from, to = _a.to;
|
1544 | this.from = from;
|
1545 | this.to = to;
|
1546 | }
|
1547 | ExtractField.prototype.transformRequest = function (originalRequest, _delegationContext, _transformationContext) {
|
1548 | var _a, _b;
|
1549 | var fromSelection;
|
1550 | var ourPathFrom = JSON.stringify(this.from);
|
1551 | var ourPathTo = JSON.stringify(this.to);
|
1552 | var fieldPath = [];
|
1553 | graphql.visit(originalRequest.document, (_a = {},
|
1554 | _a[graphql.Kind.FIELD] = {
|
1555 | enter: function (node) {
|
1556 | fieldPath.push(node.name.value);
|
1557 | if (ourPathFrom === JSON.stringify(fieldPath)) {
|
1558 | fromSelection = node.selectionSet;
|
1559 | return graphql.BREAK;
|
1560 | }
|
1561 | },
|
1562 | leave: function () {
|
1563 | fieldPath.pop();
|
1564 | },
|
1565 | },
|
1566 | _a));
|
1567 | fieldPath = [];
|
1568 | var document = graphql.visit(originalRequest.document, (_b = {},
|
1569 | _b[graphql.Kind.FIELD] = {
|
1570 | enter: function (node) {
|
1571 | fieldPath.push(node.name.value);
|
1572 | if (ourPathTo === JSON.stringify(fieldPath) && fromSelection != null) {
|
1573 | return tslib.__assign(tslib.__assign({}, node), { selectionSet: fromSelection });
|
1574 | }
|
1575 | },
|
1576 | leave: function () {
|
1577 | fieldPath.pop();
|
1578 | },
|
1579 | },
|
1580 | _b));
|
1581 | return tslib.__assign(tslib.__assign({}, originalRequest), { document: document });
|
1582 | };
|
1583 | return ExtractField;
|
1584 | }());
|
1585 |
|
1586 | function makeRemoteExecutableSchema(_a) {
|
1587 | var schemaOrTypeDefs = _a.schema, executor = _a.executor, subscriber = _a.subscriber, _b = _a.createResolver, createResolver = _b === void 0 ? defaultCreateRemoteResolver : _b, buildSchemaOptions = _a.buildSchemaOptions;
|
1588 | var targetSchema = typeof schemaOrTypeDefs === 'string' ? graphql.buildSchema(schemaOrTypeDefs, buildSchemaOptions) : schemaOrTypeDefs;
|
1589 | return wrapSchema({
|
1590 | schema: targetSchema,
|
1591 | createProxyingResolver: function () { return createResolver(executor, subscriber); },
|
1592 | });
|
1593 | }
|
1594 | function defaultCreateRemoteResolver(executor, subscriber) {
|
1595 | return function (_parent, _args, context, info) {
|
1596 | return delegate.delegateToSchema({
|
1597 | schema: { schema: info.schema, executor: executor, subscriber: subscriber },
|
1598 | context: context,
|
1599 | info: info,
|
1600 | });
|
1601 | };
|
1602 | }
|
1603 |
|
1604 | var cleanInternalStack = function (stack) { return stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, ''); };
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 | var escapeStringRegexp = function (string) {
|
1618 | if (typeof string !== 'string') {
|
1619 | throw new TypeError('Expected a string');
|
1620 | }
|
1621 |
|
1622 |
|
1623 | return string
|
1624 | .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|
1625 | .replace(/-/g, '\\x2d');
|
1626 | };
|
1627 |
|
1628 | var extractPathRegex = /\s+at.*[(\s](.*)\)?/;
|
1629 | var pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/;
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 | var cleanStack = function (stack, basePath) {
|
1652 | var basePathRegex = basePath && new RegExp("(at | \\()" + escapeStringRegexp(basePath), 'g');
|
1653 | return stack.replace(/\\/g, '/')
|
1654 | .split('\n')
|
1655 | .filter(function (line) {
|
1656 | var pathMatches = line.match(extractPathRegex);
|
1657 | if (pathMatches === null || !pathMatches[1]) {
|
1658 | return true;
|
1659 | }
|
1660 | var match = pathMatches[1];
|
1661 |
|
1662 | if (match.includes('.app/Contents/Resources/electron.asar') ||
|
1663 | match.includes('.app/Contents/Resources/default_app.asar')) {
|
1664 | return false;
|
1665 | }
|
1666 | return !pathRegex.test(match);
|
1667 | })
|
1668 | .filter(function (line) { return line.trim() !== ''; })
|
1669 | .map(function (line) {
|
1670 | if (basePathRegex) {
|
1671 | line = line.replace(basePathRegex, '$1');
|
1672 | }
|
1673 | return line;
|
1674 | })
|
1675 | .join('\n');
|
1676 | };
|
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 | var indentString = function (string, count, options) {
|
1692 | if (count === void 0) { count = 1; }
|
1693 | options = Object.assign({
|
1694 | indent: ' ',
|
1695 | includeEmptyLines: false,
|
1696 | }, options);
|
1697 | if (typeof string !== 'string') {
|
1698 | throw new TypeError("Expected `input` to be a `string`, got `" + typeof string + "`");
|
1699 | }
|
1700 | if (typeof count !== 'number') {
|
1701 | throw new TypeError("Expected `count` to be a `number`, got `" + typeof count + "`");
|
1702 | }
|
1703 | if (count < 0) {
|
1704 | throw new RangeError("Expected `count` to be at least 0, got `" + count + "`");
|
1705 | }
|
1706 | if (typeof options.indent !== 'string') {
|
1707 | throw new TypeError("Expected `options.indent` to be a `string`, got `" + typeof options.indent + "`");
|
1708 | }
|
1709 | if (count === 0) {
|
1710 | return string;
|
1711 | }
|
1712 | var regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
|
1713 | return string.replace(regex, options.indent.repeat(count));
|
1714 | };
|
1715 |
|
1716 | var AggregateError = (function (_super) {
|
1717 | tslib.__extends(AggregateError, _super);
|
1718 | function AggregateError(errors) {
|
1719 | var _this = this;
|
1720 | if (!Array.isArray(errors)) {
|
1721 | throw new TypeError("Expected input to be an Array, got " + typeof errors);
|
1722 | }
|
1723 | var normalizedErrors = errors.map(function (error) {
|
1724 | if (error instanceof Error) {
|
1725 | return error;
|
1726 | }
|
1727 | if (error !== null && typeof error === 'object') {
|
1728 |
|
1729 | return Object.assign(new Error(error.message), error);
|
1730 | }
|
1731 | return new Error(error);
|
1732 | });
|
1733 | var message = normalizedErrors
|
1734 | .map(function (error) {
|
1735 |
|
1736 | return typeof error.stack === 'string' ? cleanInternalStack(cleanStack(error.stack)) : String(error);
|
1737 | })
|
1738 | .join('\n');
|
1739 | message = '\n' + indentString(message, 4);
|
1740 | _this = _super.call(this, message) || this;
|
1741 | _this.name = 'AggregateError';
|
1742 | Object.defineProperty(_this, Symbol.iterator, {
|
1743 | get: function () { return function () { return normalizedErrors[Symbol.iterator](); }; },
|
1744 | });
|
1745 | return _this;
|
1746 | }
|
1747 | return AggregateError;
|
1748 | }(Error));
|
1749 |
|
1750 | function getSchemaFromIntrospection(introspectionResult) {
|
1751 | var _a, _b;
|
1752 | if ((_a = introspectionResult === null || introspectionResult === void 0 ? void 0 : introspectionResult.data) === null || _a === void 0 ? void 0 : _a.__schema) {
|
1753 | return graphql.buildClientSchema(introspectionResult.data);
|
1754 | }
|
1755 | else if ((_b = introspectionResult === null || introspectionResult === void 0 ? void 0 : introspectionResult.errors) === null || _b === void 0 ? void 0 : _b.length) {
|
1756 | if (introspectionResult.errors.length > 1) {
|
1757 | var combinedError = new AggregateError(introspectionResult.errors);
|
1758 | throw combinedError;
|
1759 | }
|
1760 | var error = introspectionResult.errors[0];
|
1761 | throw error.originalError || error;
|
1762 | }
|
1763 | else {
|
1764 | throw new Error('Could not obtain introspection result, received: ' + JSON.stringify(introspectionResult));
|
1765 | }
|
1766 | }
|
1767 | function introspectSchema(executor, context, options) {
|
1768 | var parsedIntrospectionQuery = graphql.parse(graphql.getIntrospectionQuery(options));
|
1769 | return new valueOrPromise.ValueOrPromise(function () { return executor({
|
1770 | document: parsedIntrospectionQuery,
|
1771 | context: context,
|
1772 | }); }).then(function (introspection) { return getSchemaFromIntrospection(introspection); }).resolve();
|
1773 | }
|
1774 |
|
1775 | function introspectSchemaSync(executor, context, options) {
|
1776 | return introspectSchema(executor, context, options);
|
1777 | }
|
1778 |
|
1779 | exports.ExtractField = ExtractField;
|
1780 | exports.FilterInputObjectFields = FilterInputObjectFields;
|
1781 | exports.FilterInterfaceFields = FilterInterfaceFields;
|
1782 | exports.FilterObjectFieldDirectives = FilterObjectFieldDirectives;
|
1783 | exports.FilterObjectFields = FilterObjectFields;
|
1784 | exports.FilterRootFields = FilterRootFields;
|
1785 | exports.FilterTypes = FilterTypes;
|
1786 | exports.HoistField = HoistField;
|
1787 | exports.MapFields = MapFields;
|
1788 | exports.MapLeafValues = MapLeafValues;
|
1789 | exports.PruneSchema = PruneTypes;
|
1790 | exports.RemoveObjectFieldDeprecations = RemoveObjectFieldDeprecations;
|
1791 | exports.RemoveObjectFieldDirectives = RemoveObjectFieldDirectives;
|
1792 | exports.RemoveObjectFieldsWithDeprecation = RemoveObjectFieldsWithDeprecation;
|
1793 | exports.RemoveObjectFieldsWithDirective = RemoveObjectFieldsWithDirective;
|
1794 | exports.RenameInputObjectFields = RenameInputObjectFields;
|
1795 | exports.RenameInterfaceFields = RenameInterfaceFields;
|
1796 | exports.RenameObjectFields = RenameObjectFields;
|
1797 | exports.RenameRootFields = RenameRootFields;
|
1798 | exports.RenameRootTypes = RenameRootTypes;
|
1799 | exports.RenameTypes = RenameTypes;
|
1800 | exports.TransformCompositeFields = TransformCompositeFields;
|
1801 | exports.TransformEnumValues = TransformEnumValues;
|
1802 | exports.TransformInputObjectFields = TransformInputObjectFields;
|
1803 | exports.TransformInterfaceFields = TransformInterfaceFields;
|
1804 | exports.TransformObjectFields = TransformObjectFields;
|
1805 | exports.TransformQuery = TransformQuery;
|
1806 | exports.TransformRootFields = TransformRootFields;
|
1807 | exports.WrapFields = WrapFields;
|
1808 | exports.WrapQuery = WrapQuery;
|
1809 | exports.WrapType = WrapType;
|
1810 | exports.defaultCreateProxyingResolver = defaultCreateProxyingResolver;
|
1811 | exports.defaultCreateRemoteResolver = defaultCreateRemoteResolver;
|
1812 | exports.generateProxyingResolvers = generateProxyingResolvers;
|
1813 | exports.introspectSchema = introspectSchema;
|
1814 | exports.introspectSchemaSync = introspectSchemaSync;
|
1815 | exports.makeRemoteExecutableSchema = makeRemoteExecutableSchema;
|
1816 | exports.wrapSchema = wrapSchema;
|
1817 |
|