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